Skip to content

Instantly share code, notes, and snippets.

@jcxplorer
Created November 3, 2010 14:01
Show Gist options
  • Save jcxplorer/661106 to your computer and use it in GitHub Desktop.
Save jcxplorer/661106 to your computer and use it in GitHub Desktop.
Nginx init script for Ubuntu with Passenger.
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using its daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/nginx/sbin
DAEMON=/opt/nginx/sbin/nginx
NAME=nginx
PIDFILE=/var/run/nginx.pid
test -x $DAEMON || exit 0
set -e
. /lib/lsb/init-functions
test_nginx_config() {
if $DAEMON -t $DAEMON_OPTS
then
return 0
else
return $?
fi
}
case "$1" in
start)
echo -n "Starting $NAME: "
test_nginx_config
$DAEMON
echo "$NAME."
;;
stop)
echo -n "Stopping $NAME: "
$DAEMON -s stop
echo "$NAME."
;;
restart)
echo -n "Restarting $NAME: "
$DAEMON -s stop
sleep 1
test_nginx_config
$DAEMON
echo "$NAME."
;;
reload)
echo -n "Reloading $NAME configuration: "
test_nginx_config
$DAEMON -s reload
echo "$NAME."
;;
configtest)
echo -n "Testing $NAME configuration: "
if test_nginx_config
then
echo "$NAME."
else
exit $?
fi
;;
status)
status_of_proc -p $PIDFILE "$DAEMON" nginx && exit 0 || exit $?
;;
*)
echo "Usage: $NAME {start|stop|restart|reload|status|configtest}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment