Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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 and using this script in /etc/init.d: The only thing I modified is this line:




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

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
This issue is referenced in the FAQ, here – Morgan May 30 '12 at 5:13

Your Answer


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.