Skip to content

Commit

Permalink
recovery nginx init.d file
Browse files Browse the repository at this point in the history
  • Loading branch information
licess committed May 31, 2017
1 parent 8936800 commit f147ab3
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions init.d/init.d.nginx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ NAME=nginx
NGINX_BIN=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
if [ -s /bin/ss ]; then
StatBin=/bin/ss
else
StatBin=/bin/netstat
fi


case "$1" in
start)
echo -n "Starting $NAME... "

if [ -f "$PIDFILE" ]; then
if $StatBin -tnpl | grep -q nginx;then
echo "$NAME (pid `pidof $NAME`) already running."
exit 1
fi
Expand All @@ -45,8 +51,8 @@ case "$1" in
stop)
echo -n "Stoping $NAME... "

if [ ! -f "$PIDFILE" ]; then
echo "$NAME is stopped."
if ! $StatBin -tnpl | grep -q nginx; then
echo "$NAME is not running."
exit 1
fi

Expand All @@ -61,8 +67,9 @@ case "$1" in
;;

status)
if [ -f "$PIDFILE" ]; then
echo "$NAME (pid `pidof $NAME`) is running..."
if $StatBin -tnpl | grep -q nginx; then
PID=`pidof nginx`
echo "$NAME (pid $PID) is running..."
else
echo "$NAME is stopped."
exit 0
Expand All @@ -72,7 +79,12 @@ case "$1" in
force-quit|kill)
echo -n "Terminating $NAME... "

killall $NAME
if ! $StatBin -tnpl | grep -q nginx; then
echo "$NAME is is stopped."
exit 1
fi

kill `pidof $NAME`

if [ "$?" != 0 ] ; then
echo " failed"
Expand All @@ -91,7 +103,7 @@ case "$1" in
reload)
echo -n "Reload service $NAME... "

if [ -f "$PIDFILE" ]; then
if $StatBin -tnpl | grep -q nginx; then
$NGINX_BIN -s reload
echo " done"
else
Expand Down

0 comments on commit f147ab3

Please sign in to comment.