Use Shell to write Nginx script startup, shutdown, Reload

Source: Internet
Author: User

#!/bin/bash                  ----The default execution shell mode #chkconfig: 2345 10 80        ---- Add to boot execution mode path= "/usr/local/nginx/sbin/nginx"         ---- The boot path after the source code installation Nginx name= "Nginxd"    test=0log=/tmp/nginxd.log                 ----nginx log date= ' date  ' +%f  %h:%m: %s "'         ----Get system time command # to determine if Nginx has been installed or to determine if the path initiated after the source installation exists. if [ ! -x  $path  ];thenecho  -n  "${path} not installed!" exit 10fi# boot option, start with Nginx, start successfully or fail to output a reminder. Start () {echo -n  " starting  $name  ;" $path  -ttest=$?if [  $test  -eq 0 ];thentouch /tmp/nginx.pid$pathecho  "$ date and  $path  is starting " >>  $logelseecho   "Please check you config" Exit 20fi} #停止nginx服务, and redirects the output information to the specified log file. Stop () {echo -n  "stopping  $name  ;" ps -ef |grep nginx | awk  ' {print $2} '  | xargs kill - 9test=0if [  $test  -eq 0 ] ;thenrm -rf /tmp/nginx.pid echo  "$ date and  $path  is stop " >>  $logfi} #重加载选项, reload the service and identify whether the service is functioning properly. Reload () {echo -n  "reloading  $name  ;" #ps  -ef |grep nginx | awk  ' {print $2} '  | xargs kill -9$ path -ttest=$?if [  $test  -eq 0 ];thentouch /tmp/reload.pidecho  "$DATE  and  $path  is reloading   >>  $logrm  -rf /tmp/ reload.pidelseecho  "Please check you config" Exit 20fi} #整个脚本使用case方式来进行调用, An informational reminder is output when the script is executed. case  "$"  instaRT)  start;; Stop)  stop;; Reload)  reload;; *)  echo  "/usr/local/nginx/sbin/nginx start|stop|reload !";; esac######---Exit the shell, do the following---##### #1. Add permissions to Files Chmod +x nginxd2. Perform bash nginxd [start| on files Stop|reload]


This article is from the "Leoheng" blog, make sure to keep this source http://leoheng.blog.51cto.com/12202141/1955762

Use Shell to write Nginx script startup, shutdown, Reload

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.