2

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?

endofu
  • 61
  • 3

1 Answers1

4

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)
endofu
  • 61
  • 3
  • 1
    This issue is referenced in the [FAQ, here](http://docs.fabfile.org/en/1.4.2/faq.html#init-scripts-don-t-work) – Morgan May 30 '12 at 05:13