System Service nginx startup control script

Source: Internet
Author: User
#! /Bin/sh # nginx-this script starts and stops the nginx daemon # chkconfig:-85 15 # Description: nginx is an HTTP (s) server, HTTP (s) reverse \ # proxy and IMAP/POP3 Proxy Server # processname: nginx # config:/etc/nginx. conf # config:/etc/sysconfig/nginx # pidfile:/var/run/nginx. pid # source function library .. /etc/rc. d/init. d/functions # source networking configuration .. /etc/Sysco Nfig/Network # Check that networking is up. ["$ networking" = "no"] & Exit 0 ##### path of the nginx execution program ###### nginx = "/usr/local/nginx/ sbin/nginx "prog =$ (basename $ nginx) ##### path of the nginx configuration file ##### nginx_conf_file = "/etc/nginx. conf "[-F/etc/sysconfig/nginx] &. /etc/sysconfig/nginx lockfile =/var/lock/subsys/nginx make_dirs () {# Make Required Directories user = 'nginx-V 2> & 1 | grep "Configure argu Ments: "| SED's/[^ *] * -- user = \ ([^] * \). */\ 1/G'-'Options = '$ nginx-V 2> & 1 | grep 'configure arguments: ''for opt in $ options; do if ['echo $ opt | grep '. *-temp-path '']; then value = 'echo $ opt | cut-d" = "-F 2' if [! -D "$ value"]; then # echo "Creating" $ value mkdir-p $ Value & chown-r $ user $ value fi done} start () {[-x $ nginx] | Exit 5 [-F $ nginx_conf_file] | exit 6 make_dirs echo-N $ "Starting $ prog: "daemon $ nginx-C $ nginx_conf_file retval =$? Echo [$ retval-EQ 0] & touch $ lockfile return $ retval} STOP () {echo-N $ "Stopping $ prog:" killproc $ prog-Quit retval =$? Echo [$ retval-EQ 0] & Rm-F $ lockfile return $ retval} restart () {configtest | return $? Stop sleep 1 start} reload () {configtest | return $? Echo-N $ "reloading $ prog:" killproc $ nginx-hup retval =$? Echo} force_reload () {restart} configtest () {$ nginx-T-C $ nginx_conf_file} rh_status () {Status $ prog} rh_status_q () {rh_status>/dev/null 2> & 1} case "$1" in START) rh_status_q & Exit 0 $1; stop) rh_status_q | exit 0 $1 ;; restart | configtest) $1; RELOAD) rh_status_q | exit 7 $1; force-Reload) force_reload; Status) rh_status; condrestart | try-Restart) rh_status_q | exit 0; *) echo $ "Usage: $0 {START | stop | status | restart | condrestart | try-Restart | reload | force-Reload | configtest} "Exit 2 esac

Save the preceding content as/etc/init. d/nginx and add executable permissions,

Add another system service, chkconfig -- add nginx

The last step is to start the system: chkconfig nginx on

Start: Service nginx start

View status: netstat-ntlp | grep 80


This article from the "sense of direction" blog, please be sure to keep this source http://itech.blog.51cto.com/192113/1616874

System Service nginx startup control script

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.