INIT Script for Nginx


#! /bin/bash

Variables & Paths
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

Include Nginx Defaults
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi

set -e

. /lib/lsb/init-functions

case “$1” in
start)
echo -n “Starting $DESC: ”
start-stop-daemon –start –quiet –pidfile /usr/local/nginx/logs/$NAME.pid
–exec $DAEMON — $DAEMON_OPTS || true
echo “$NAME.”
;;
stop)
echo -n “Stopping $DESC: ”
start-stop-daemon –stop –quiet –pidfile /usr/local/nginx/logs/$NAME.pid
–exec $DAEMON || true
echo “$NAME.”
;;
restart|force-reload)
echo -n “Restarting $DESC: ”
start-stop-daemon –stop –quiet –pidfile
/usr/local/nginx/logs/$NAME.pid –exec $DAEMON || true
sleep 1
start-stop-daemon –start –quiet –pidfile
/usr/local/nginx/logs/$NAME.pid –exec $DAEMON — $DAEMON_OPTS || true
echo “$NAME.”
;;
reload)
echo -n “Reloading $DESC configuration: ”
start-stop-daemon –stop –signal HUP –quiet –pidfile /usr/local/nginx   /logs/$NAME.pid
–exec $DAEMON || true
echo “$NAME.”
;;
status)
status_of_proc -p /usr/local/nginx/logs/$NAME.pid “$DAEMON” nginx && exit 0 || exit $?
;;
*)
N=/etc/init.d/$NAME
echo “Usage: $N {start|stop|restart|reload|force-reload|status}” >&2
exit 1
;;
esac
exit 0

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s