Skip to content

Instantly share code, notes, and snippets.

@sletix
Created January 18, 2010 12:19
Show Gist options
  • Save sletix/279966 to your computer and use it in GitHub Desktop.
Save sletix/279966 to your computer and use it in GitHub Desktop.
#!/bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $remote_fs $syslog $named $network $time
# Required-Stop: $remote_fs $syslog $named $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start nginx at boot time
# Description: Enable service provided by nginx.
### END INIT INFO
# $Id$
NGINXHOME=/opt/nginx
NGINXPID=$NGINXHOME/logs/nginx.pid
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=$NGINXHOME/sbin/nginx
NAME=nginx
DESC=nginx
if [ ! -x $DAEMON ]
then
echo "Couldn't find $DAEMON. Please set path to DAEMON."
exit 0
fi
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --pidfile $NGINXPID \
--exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --pidfile $NGINXPID \
--exec $DAEMON
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --pidfile \
$NGINXHOME/run/$NAME.pid --exec $DAEMON
sleep 1
start-stop-daemon --start --pidfile \
$NGINXPID --exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
start-stop-daemon --stop --signal HUP --pidfile $NGINXPID \
--exec $DAEMON
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment