#!/bin/sh NGINX=/usr/local/nginx/sbin/nginx CMD="$1" PID=`ps -ax | grep nginx | grep master | awk -F ' ' '{print $1}'` if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then RUN=1 else RUN=0 fi case $CMD in start) if [ $RUN -eq 1 ]; then echo "$0 $CMD: nginx (pid $PID) already running" exit 1 fi if $NGINX ; then echo "$0 $CMD: nginx started" else echo "$0 $CMD: nginx could not be started" fi ;; stop) if [ $RUN -eq 0 ]; then echo "$0 $CMD: nginx not running" exit 1 fi if kill $PID ; then echo "$0 $CMD: nginx stopped" else echo "$0 $CMD: nginx could not be stopped" fi ;; graceful) if [ $RUN -eq 0 ]; then echo "$0 $CMD: nginx not running, trying to start" if $NGINX ; then echo "$0 $CMD: nginx started" else echo "$0 $CMD: nginx could not be started" fi else if $NGINX -t >/dev/null 2>&1; then if kill -1 $PID ; then echo "$0 $CMD: nginx gracefully restarted" else echo "$0 $CMD: nginx could not be restarted" fi else echo "$0 $CMD: configuration broken, ignoring restart" echo "$0 $CMD: run 'nginxctl configtest' for details" fi fi ;; configtest) $NGINX -t ;; *) echo "usage: $0 (start|stop|graceful|configtest|help)" cat <