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

Source: Internet
Author: User

1. Write script in/etc/init.d/directory named Nginx

1#!/bin/SH 2 # 3# Nginx-This script starts and stops the Nginx daemon4 # 5# Chkconfig:- -  the 6 # Description:nginx is an HTTP (s) server, HTTP (s) reverse \7# Proxy and imap/POP3 Proxy Server8 # Processname:nginx9# config:/etc/nginx/nginx.confTen# config:/etc/sysconfig/Nginx One# Pidfile:/var/run/Nginx.pid A  -# SourcefunctionLibrary. -. /etc/rc.d/init.d/functions the  - # Source Networking configuration. -. /etc/sysconfig/Network -  + # Check that networking are up. -["$NETWORKING"="No"] && exit0  +  Anginx="/usr/local/nginx/sbin/nginx"  atprog=$ (basename$nginx) -  -nginx_conf_file="/usr/local/nginx/conf/nginx.conf"  -  -[-f/etc/sysconfig/nginx] &&. /etc/sysconfig/Nginx -  in Lockfile=/var/lock/subsys/Nginx -  to start () { +[-X $nginx] | | Exit5  -[-F $NGINX _conf_file] | | Exit6  the     Echo-N $"starting $prog:"  *Daemon $nginx-C $NGINX _conf_file $Retval=$?Panax Notoginseng     Echo  -[$retval-eq0] &&Touch$Lockfile  the return $retval + }  A  the Stop () { +     Echo-N $"stopping $prog:"  -Killproc $prog-QUIT $Retval=$? $     Echo  -[$retval-eq0] &&RM-F $Lockfile  - return $retval the Killall-9Nginx - } Wuyi  the Restart () { -Configtest | | Return $? Wu Stop -     Sleep 1  About Start $ }  -  - Reload () { -Configtest | | Return $? A     Echo-N $"Reloading $prog:"  +Killproc $nginx-HUP theRetval=$? -     Echo  $ }  the  the force_reload () { the Restart the }  -  in configtest () { the$nginx-T-C $NGINX _conf_file the }  About  the Rh_status () { the Status $prog the }  +  - rh_status_q () { theRh_status >/dev/NULL 2>&1 Bayi }  the  the  Case " $" inch  - start) -Rh_status_q && exit0  the$1  the         ;;  the stop) theRh_status_q | | Exit0  -$1  the         ;;  theRestart|configtest) the$1 94         ;;  the Reload) theRh_status_q | | Exit7  the$1 98         ;;  Aboutforce-Reload) - Force_reload101         ;; 102 status)103 Rh_status104         ;;  thecondrestart|try-restart)106Rh_status_q | | Exit0 107             ;; 108*)    109       Echo$"Usage: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"  theExit2 111  the Esac  

[email protected] ~]# CP nginx/etc/init.d/
[Email protected] ~]# chmod 755/etc/init.d/nginx
[Email protected] ~]# chkconfig--add nginx

[[Email protected] ~]# service Nginx start

[[Email protected] ~]# service Nginx stop

[[Email protected] ~]# service Nginx Reload

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.