Skip to content

Instantly share code, notes, and snippets.

@dstrelau
Created September 1, 2009 14:26
Show Gist options
  • Save dstrelau/179117 to your computer and use it in GitHub Desktop.
Save dstrelau/179117 to your computer and use it in GitHub Desktop.
#!/bin/sh
NAME=nginx
DESC=nginx
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/nginx
DAEMON_ARGS=""
CONFIG=/etc/nginx/nginx.conf
PID_FILE="/var/run/${NAME}.pid"
set -e
# Check if DAEMON binary exist
test -x $DAEMON || exit 0
# Include nginx defaults if available
test -f /etc/default/nginx && . /etc/default/nginx
d_start() {
start-stop-daemon --start --quiet \
--pidfile $PID_FILE --exec $DAEMON -- $DAEMON_ARGS
}
d_stop() {
start-stop-daemon --stop --quiet --signal QUIT \
--pidfile $PID_FILE --exec $DAEMON --retry 5
}
d_reload() {
start-stop-daemon --stop --quiet --signal HUP \
--pidfile $PID_FILE --exec $DAEMON
}
case "$1" in
start)
echo -n "Starting $DESC: "
d_start && echo "success." || echo "failure."
;;
stop)
echo -n "Stopping $DESC: "
d_stop && echo "success." || echo "failure."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
(d_stop && sleep 1 && d_start && echo "success.") || echo "failure."
;;
reload)
echo -n "Reloading $DESC configuration: "
($DAEMON -t && d_reload && echo "success.") || echo "failure."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload|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