#! /bin/bash # # nginx Start/Stop the nginx daemon. # # chkconfig: 2345 90 60 # description: nginx # processname: nginx # pidfile: $pidf # Source function library. . /etc/init.d/functions # Progran name prog="nginx" pidf="/nginx/logs/nginx.pid" exe="/nginx/sbin/nginx" start() { echo -n $"Starting $prog: " if [ -e /var/lock/subsys/nginx ]; then if [ -e $pidf ] && [ -e /proc/`cat $pidf` ]; then echo -n $"cannot start $prog: nginx is already running." failure $"cannot start $prog: nginx is already running." echo return 1 fi fi $exe RETVAL=$? [ $RETVAL -eq 0 ] && success $"$prog start" || failure $"$prog start" [ $RETVAL -eq 0 ] && touch /var/lock/subsys/nginx echo return $RETVAL } stop() { echo -n $"Stopping $prog: " if [ ! -e /var/lock/subsys/nginx ] || [ ! -e $pidf ]; then echo -n $"cannot stop $prog: nginx is not running." failure $"cannot stop $prog: nginx is not running." echo return 1 fi PID=`cat $pidf` if checkpid $PID 2>&1; then # TERM first, then KILL if not dead kill -TERM $PID >/dev/null 2>&1 usleep 100000 if checkpid $PID && sleep 1 && checkpid $PID && sleep 3 && checkpid $PID; then kill -KILL $PID >/dev/null 2>&1 usleep 100000 fi fi checkpid $PID RETVAL=$((! $?)) [ $RETVAL -eq 0 ] && success $"$prog shutdown" || failure $"$prog shutdown" [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/nginx; echo return $RETVAL } status() { status $prog } restart() { stop start } reload() { echo -n $"Reloading $prog: " if [ ! -e /var/lock/subsys/nginx ] || [ ! -e $pidf ]; then echo -n $"cannot reload $prog: nginx is not running." failure $"cannot reload $prog: nginx is not running." echo return 1 fi kill -HUP `cat $pidf` >/dev/null 2>&1 RETVAL=$? [ $RETVAL -eq 0 ] && success $"$prog reload" || failure $"$prog reload" echo return $RETVAL } case "$1" in start) start ;; stop) stop ;; restart) restart ;; reload) reload ;; status) status ;; condrestart) [ -f /var/lock/subsys/nginx ] && restart || : ;; configtest) $exe -t ;; *) echo $"Usage: $0 {start|stop|status|reload|restart|condrestart|configtest}" exit 1 esac