#! /bin/sh# chkconfig:2345 - -# Description:startup Script forNginx webserver on Debian. Placeinch/etc/INIT.D and# Run'update-rc.d-f nginx Defaults', or use the appropriate command on your# distro. For CentOS/redhat Run:'chkconfig--add Nginx'# # # BEGIN INIT info# provides:nginx# Required-Start: $all # Required-Stop: $all # Default-start:2 3 4 5# Default-stop:0 1 6# Short-description:starts the Nginx web server# description:starts nginxusingstart-stop-daemon### END INIT info# author:licess# website:http://lnmp.orgPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/Binname=Nginxnginx_bin=/usr/local/nginx/sbin/$NAMECONFIGFILE=/usr/local/nginx/conf/$NAME. Confpidfile=/usr/local/nginx/logs/$NAME. PID Case " $" inchstart) echo-N"starting $NAME ..." ifNETSTAT-TNPL | grep-Q Nginx;then Echo"$NAME (PID ' pidof $NAME ') already running."Exit1fi $NGINX _bin-C $CONFIGFILEif["$?"!=0 ] ; Then Echo"failed"Exit1 ElseEcho" Done"fi;; Stop) Echo-N"stoping $NAME ..." if! NETSTAT-TNPL | grep-q Nginx; then echo"$NAME is not running."Exit1fi $NGINX _bin-s Stopif["$?"!=0 ] ; Then Echo"failed. Use Force-quit"Exit1 ElseEcho" Done"fi;; Status)ifNETSTAT-TNPL | grep-q Nginx; then PID=' pidof nginx ' echo"$NAME (PID $PID) is running ..." ElseEcho"$NAME is stopped"Exit0fi;; Force-quit) echo-N"terminating $NAME ..." if! NETSTAT-TNPL | grep-q Nginx; then echo"$NAME is not running."Exit1fi kill ' pidof $NAME 'if["$?"!=0 ] ; Then Echo"failed"Exit1 ElseEcho" Done"fi;; Restart) $0Stop Sleep1 $0start;; Reload) echo-N"Reload service $NAME ..." ifNETSTAT-TNPL | grep-q Nginx; then $NGINX _bin-s Reload Echo" Done" ElseEcho"$NAME is not running, can ' t reload."Exit1fi;; Configtest) echo-N"Test $NAME Configure files ..."$NGINX _bin-T;; *) echo"Usage: $ {start|stop|force-quit|restart|reload|status|configtest}"Exit1 ;; Esac
Chkconfig--add/etc/init.d/nginx
Chkconfig--level 3 Nginx on
/etc/init.d/nginx footstep Boot file