#!/bin/sh#chkconfig:2345#description:startup script for Nginx webserver on Debian. Place IN/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 nginx using Start-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. Pidcase" $" 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"Exit1ElseEcho" 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"Exit1ElseEcho" Done"fi;; Status)ifNETSTAT-TNPL | grep-q Nginx; then PID=' pidof nginx ' echo"$NAME (PID $PID) is running ..." ElseEcho"$NAME is stopped"exit 0 fi;; 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"Exit1ElseEcho" Done"fi;; Restart) $ stop sleep1$ start; 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
[email protected] ~]# ln/usr/local/nginx/sbin/nginx/usr/bin/
[email protected] ~]# CP nginx/etc/init.d/
[Email protected] ~]# chmod 755/etc/init.d/nginx
[Email protected] ~]# chkconfig--add nginx
3, Nginx start, stop, uninterrupted service restart
[[Email protected] ~]# service Nginx start
[[Email protected] ~]# service Nginx stop
[[Email protected] ~]# service Nginx Reload
I think I should. You can also add other services in this way.
Add Nginx to system service (service Nginx Start/stop/restart)