0

Can someone help me to setup nginx on my box? I have compiled it (i'm using it to run Django app using uwsgi_rs).

Its running OK but i have to start it manually. How can i setup it to autorun? And start it again (automatically) if it ware killed? I'm talking about nginx and uwsgi...

NilColor
  • 103
  • 1
  • 3

3 Answers3

2

I would suggest to take a look at runit. I've grown quite fond of it. There are packages for it on most distributions and the setup is not that hard.

coredump
  • 12,573
  • 2
  • 34
  • 53
0

You can find an Ubuntu 9 compatible init script for nginx on the nginx wiki. It also contains instructions on how to install it so that it is started when the system boots.

user9517
  • 114,104
  • 20
  • 206
  • 289
  • 1
    I suspect the "right" answer here might be to write an Upstart script. – Tom O'Connor Mar 21 '11 at 10:31
  • Does Upstart can restart nginx process? If it were killed? I saw http://wiki.nginx.org/Nginx-init-ubuntu script but i'm not sure it support auto-restarting... Am I wrong? – NilColor Mar 21 '11 at 11:41
0

I don't know about the capabilities of nginx, so I just assume you've checked (man nginx) that it doesn't have an option to automatically respawn. You can create (as root) a simple script like this:

#!/bin/bash
while [ 1 ]
  do /usr/local/sbin/nginx
done

save as, for example, /usr/local/bin/loopnginx.sh, then do chmod +x /usr/local/bin/loopnginx.sh and finally, in the init script you mentioned, replace the line

DAEMON=/usr/local/sbin/nginx

with:

DAEMON=/usr/local/bin/loopnginx.sh
jankes
  • 301
  • 1
  • 7