Add Nginx to system service (service Nginx Start/stop/restart)

Source: Internet
Author: User

#!/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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.