Centos/rhel implementation Nginx Self-startup script instance _linux Shell

Source: Internet
Author: User
Tags centos

Usually in the CentOS, Rhel OS, we mostly through the chkconfig to manage services, such as the boot automatic service.
Here to introduce a very useful nginx startup script. and simple to use, as follows:

1. Execute the following order:

Vim/etc/init.d/nginxd

2. Enter the following content:

Note: The following variables in the file need to be rewritten according to your actual directory.

Nginx= "/usr/local/nginx/sbin/nginx" # #nginx的可执行文件路径 lockfile= "/var/nginx/nginx.lock" # #需要先创建/var/nginx directory Nginx_  Conf_file= "/etc/nginx/nginx.conf" # #需要先创建该配置文件 #!/bin/sh # nginx-this script starts and stops the Nginx daemon # Chkconfig:-Description:nginx is a HTTP (s) server, HTTP (s) reverse \ # Proxy and IMAP/POP3 proxy ser 
Ver # processname:nginx # Source function library. . 
/etc/rc.d/init.d/functions # Source Networking configuration. . 
/etc/sysconfig/network # Check that networking are up. ["$NETWORKING" = "no"] && exit 0 nginx= "/usr/local/nginx/sbin/nginx" prog=$ (basename $nginx) sysconfig= "/etc/" sysconfig/$prog "lockfile="/var/nginx/nginx.lock "pidfile="/var/nginx/${prog}.pid "nginx_conf_file="/etc/nginx/ Nginx.conf "[F $sysconfig] &&. $sysconfig start () {[x $nginx] | | Exit 5 [f $NGINX _conf_file] | | | Exit 6 ECHO-N $ "Starting $prog:" Da 
  Emon $nginx-C $NGINX _conf_file retval=$? echo [$rEtval-eq 0] && touch $lockfile return $retval} stop () {echo-n $ "stopping $prog:" Killproc-p $pid 
  File $prog retval=$?  
  echo [$retval-eq 0] && rm-f $lockfile return $retval} restart () {configtest_q | |-Return 6 STOP 
  Start} reload () {configtest_q | | Return 6 ECHO-N $ "Reloading $prog:" Killproc-p $pidfile $prog-hup echo} configtest () {$nginx-T-c $NGINX _conf_file} configtest_q () {$nginx-t-q-c $NGINX _conf_file} rh_ Status () {status $prog} rh_status_q () {rh_status >/dev/null 2>&1} # Upgrade the binary with no Dow 
Ntime. Upgrade () {local oldbin_pidfile= ' ${pidfile}.oldbin ' configtest_q | | Return 6 ECHO-N $ "Upgrading $prog:" Kil 
  Lproc-p $pidfile $prog-usr2 retval=$? Sleep 1 if [[F ${oldbin_pidfile} && f ${pidfile}]]; Then killproc-p $oldbin _pidfile $prog-quit Success $ "$prog online Upgrade" Echo return 0 Else
    Failure $ "$prog online Upgrade" echo return 1 fi} # tell Nginx to reopen logs reopen_logs () {con Figtest_q | | 
  Return 6 echo-n $ "Reopening $prog logs:" Killproc-p $pidfile $prog-usr1 retval=$? 
  echo return $retval} rh_status_q && exit 0 $; Stop) rh_status_q | | 
  Exit 0 $;; 
  Restart|configtest|reopen_logs) $;; Force-reload|upgrade) rh_status_q | | 
  Exit 7 upgrade;; Reload) Rh_status_q | | 
  Exit 7 $;; 
  STATUS|STATUS_Q) rh_$1;; Condrestart|try-restart) rh_status_q | | 
  Exit 7 restart;;  

 * echo $ "Usage: $ {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}" Exit 2 Esac

After the save is complete, you can start the Nginx by executing the following command

chmod 777/etc/init.d/nginxd 
/etc/init.d/nginxd start

3. Configure Boot Boot

Execute the following command:

Chkconfig Nginxd on

You can view the following command to see if the success

Chkconfig--list | grep nginxd

Related Article

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.