Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to be able to start and stop an nginx server on an Ubuntu EC2 instance with Fabric.

I have this two scripts in my fabfile.py:

def start_nginx():
    sudo('/etc/init.d/nginx start')
    #also tried this: run('sudo /etc/init.d/nginx start')

def stop_nginx():
    sudo('/etc/init.d/nginx stop')

The start_nginx() seemingly runs without errors (* Starting Nginx Server.../ ...done.) but doesn't start the server (or it dies immediately).

If I SSH into the instance this starts nginx perfectly:

sudo /etc/init.d/nginx start 

The stop_nginx() Fabric script stops the server remotely.

I compiled nginx from source, using this http://nginx.org/download/nginx-1.1.9.tar.gz and using this script in /etc/init.d: https://github.com/JasonGiedymin/nginx-init-ubuntu/blob/master/nginx. The only thing I modified is this line:

DAEMON=/usr/local/sbin/nginx   

to

DAEMON=/usr/sbin/nginx

because that's the path I used when I ./configure-d my compile.

Does anyone have any idea why the init script behaves differently being called from Fabric?

share|improve this question

1 Answer 1

I found that if I use a pseudo-terminal on the remote, it works! This is the correct script:

def start_nginx():
    sudo('/etc/init.d/nginx start', pty=False)
share|improve this answer
1  
This issue is referenced in the FAQ, here –  Morgan May 30 '12 at 5:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.