Created
March 1, 2013 10:15
-
-
Save sagarbommidi/5063735 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### 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 | |
### END INIT INFO | |
# An init.d script that works under Ubuntu 12.04 | |
# load with sudo update-rc.d -f nginx defaults | |
PATH=/opt/nginx/sbin:/sbin:/bin:/usr/sbin:/usr/bin | |
NAME=nginx | |
DESC="Nginx HTTP and reverse proxy server" | |
DAEMON=/opt/nginx/sbin/nginx | |
PID=/opt/nginx/logs/$NAME.pid | |
test -x $DAEMON || exit 0 | |
set -e | |
# Include nginx defaults if available | |
if [ -f /etc/default/nginx ] ; then | |
. /etc/default/nginx | |
fi | |
. /lib/lsb/init-functions | |
case "$1" in | |
start) | |
log_daemon_msg "Starting $DESC" || true | |
if start-stop-daemon --start --quiet --oknodo --pidfile $PID --exec $DAEMON \ | |
-- $DAEMON_OPTS; then | |
log_end_msg 0 || true | |
else | |
log_end_msg 1 || true | |
fi | |
;; | |
stop) | |
log_daemon_msg "Stopping $DESC" || true | |
if start-stop-daemon --stop --quiet --oknodo --pidfile $PID --exec $DAEMON; then | |
log_end_msg 0 || true | |
else | |
log_end_msg 1 || true | |
fi | |
;; | |
restart) | |
log_daemon_msg "Restarting $DESC" || true | |
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $PID --exec $DAEMON | |
sleep 3 | |
if start-stop-daemon --start --quiet --oknodo --pidfile $PID --exec $DAEMON \ | |
-- $DAEMON_OPTS; then | |
log_end_msg 0 || true | |
else | |
log_end_msg 1 || true | |
fi | |
;; | |
reload|force-reload) | |
log_daemon_msg "Reloading $DESC configuration" || true | |
if start-stop-daemon --stop --signal HUP --quiet --oknodo --pidfile $PID \ | |
--exec $DAEMON; then | |
log_end_msg 0 || true | |
else | |
log_end_msg 1 || true | |
fi | |
;; | |
status) | |
status_of_proc -p $PID $DAEMON $NAME && exit 0 || exit $? | |
;; | |
*) | |
N=/etc/init.d/$NAME | |
log_action_msg "Usage: $N {start|stop|restart|reload|force-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