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