Skip to content

Instantly share code, notes, and snippets.

@morkevicius
Created October 16, 2015 13:49
Show Gist options
  • Save morkevicius/c08423207eb50ef82d97 to your computer and use it in GitHub Desktop.
Save morkevicius/c08423207eb50ef82d97 to your computer and use it in GitHub Desktop.
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: nginx init.d script for Ubuntu.
# Description: nginx init.d script for Ubuntu.
### END INIT INFO
# Import init-functions
. /lib/lsb/init-functions
INSTALL_DIR="/opt/nginx"
### Location of nginx binary. Change path as neccessary
DAEMON="$INSTALL_DIR/sbin/nginx"
### Location of configuration file. Change path as neccessary
CONFIG_FILE=/etc/nginx/nginx.conf
DAEMON_OPTS="-c $CONFIG_FILE"
NAME=nginx
DESC="Web Server"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
test -x $DAEMON || exit 0
set -e
case "$1" in
start)
log_daemon_msg "Starting $DESC" $NAME
if ! start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS ; then
log_end_msg 1
else
log_end_msg 0
fi
;;
stop)
log_daemon_msg "Stopping $DESC" $NAME
if start-stop-daemon --quiet --stop --oknodo --retry 30 --pidfile $PIDFILE --exec $DAEMON; then
rm -f $PIDFILE
log_end_msg 0
else
log_end_msg 1
fi
;;
reload)
log_daemon_msg "Reloading $DESC configuration" $NAME
if start-stop-daemon --stop --signal 2 --oknodo --retry 30 --quiet --pidfile $PIDFILE --exec $DAEMON; then
if start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS ; then
log_end_msg 0
else
log_end_msg 1
fi
else
log_end_msg 1
fi
;;
restart|force-reload)
$0 stop
sleep 1
$0 start
;;
*)
echo "Usage: $SCRIPTNAME {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