Skip to content

Instantly share code, notes, and snippets.

@ncherro
Last active January 4, 2016 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncherro/8672609 to your computer and use it in GitHub Desktop.
Save ncherro/8672609 to your computer and use it in GitHub Desktop.
upstart script for nginx
# save to /etc/init/nginx.conf and chmod +x on a Ubuntu server with upstart
#
# start with `sudo service nginx start`
# stop with `sudo service nginx stop`
#
# DAEMON is the full path to the nginx binary. in this case, nginx
# was installed with passenger - passenger-install-nginx-module
#
# PIDFILE is the full path to the nginx pidfile, defined with the pid
# directive in nginx.conf http://wiki.nginx.org/CoreModule#pid
description "nginx http daemon"
author "Nick Herro <ncherro@gmail.com>"
start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]
env DAEMON=/opt/nginx/sbin/nginx
env PIDFILE=/var/run/nginx/nginx.pid
expect fork
respawn
respawn limit 10 5
# ensure there are no errors with nginx config
pre-start exec $DAEMON -t
# upstart will be tracking the wrong PID after forking, so check our $PIDFILE
post-stop exec start-stop-daemon --stop --pidfile $PIDFILE --name nginx --exec $DAEMON --signal QUIT
exec $DAEMON
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment