Skip to content

Instantly share code, notes, and snippets.

@Zelnox
Created August 9, 2009 21:38
Show Gist options
  • Save Zelnox/164909 to your computer and use it in GitHub Desktop.
Save Zelnox/164909 to your computer and use it in GitHub Desktop.
#! /bin/sh
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'sudo update-rc.d nginx defaults', or use the appropriate command on your
# distro.
#
# Author: Ryan Norbauer <[email protected]>
# Modified: Geoffrey Grosenbach http://topfunky.com
# Modified: zelnox
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
# More info: http://topfunky.net/svn/shovel/nginx/init.d/nginx
# http://articles.slicehost.com/2009/3/4/ubuntu-intrepid-adding-an-nginx-init-script
### END INIT INFO
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=nginx
DESC=nginx
DAEMON=/usr/bin/$NAME
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTFILE=/etc/init.d/$NAME
# Gracefully exit if nginx is missing
test -x $DAEMON || exit 0
# Include nginx defaults if available
#if [ -f /etc/default/nginx ] ; then
# . /etc/default/nginx
#fi
d_start() {
$DAEMON -c $CONFIGFILE || echo -n " already running"
}
d_stop() {
kill -QUIT `cat $PIDFILE` || echo -n " not running"
}
d_reload() {
kill -HUP `cat $PIDFILE` || echo -n " could not reload"
}
d_status() {
echo -n " not implemented"
}
case "$1" in
start)
echo -n "Starting $DESC: "
d_start
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
d_stop
echo "$NAME."
;;
restart)
echo -n "Restarting $DESC: "
d_stop
sleep 1
d_start
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
d_reload
echo "$NAME."
;;
status)
#status_of_proc -p /usr/local/nginx/logs/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
;;
*)
echo "Usage: $NAME {start|stop|restart|reload|status}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment