Os:centos/redhat Series
and tested properly on CentOS 6.7 and CentOS 7.2
#!/bin/bash## auth:daxin# time:2018/07/10## nginx start Nginx Web server# # chkconfig:-90# Description:start, S Tops and reload Nginx Web server## config:/usr/local/nginx/conf/nginx.conf# config:/usr/local/nginx/conf/vhosts#### BEGIN INIT info# provides:nginx# required-start:# required-stop:# default-start:3# default-stop: # short-description:st Art and Stop Nginx Web server# description:start, stop and reload Nginx Web server### END INIT info# Source function Libr ary. /etc/init.d/functionsnginx_dir= "/usr/local/nginx" nginx= "${nginx_dir}/sbin/nginx" NGINX_CONF= "${NGINX_DIR}/conf/ Nginx.conf "prog=$ (basename $NGINX) lock_file=" ${nginx_dir}/${prog}.lock "# check Command existsif [!-x ${nginx}]; Then echo-n $ "${nginx} does not exists."; Warning Echo Exit 5fifunction Start () {[-F $NGINX _conf] | | Exit 6 $NGINX-C $NGINX _conf retval=$? If [$retval-eq 0]; Then touch $LOCK _file action "starting $PROG"/bin/true Else Action "Starting $PROG "/bin/false fi return $retval}function stop () {Pkill $PROG retval=$? If [$retval-eq 0]; Then rm-f $LOCK _file action "Stop $PROG"/bin/true else Action "Stop $PROG"/bin/false fi return $retval}function restart () {configtest_q | | Return 6 STOP start}function reload () {Configtest_q | | Return 6 nginx_main_process=$ (ps aux | grep $NGINX | grep-v grep | awk ' {print $} ') Kill-hup $nginx _main_process Retval=$? If [$retval-eq 0]; Then action "Reload $PROG"/bin/true else Action "Reload $PROG"/bin/false fi return $retval}functi On Configtest_q () {$NGINX-T-C $NGINX _conf}function status () {nginx_main_process=$ (ps aux | grep $NGINX | grep-v grep | awk ' {print $} ') if [-Z $nginx _main_process]; Then action "$PROG are not running"/bin/false else Action "$PROG is runing"/bin/true fi}case "$" in Start) Start; Stop) stop ;; reload) reload;; restart) restart;; Configtest) configtest_q;; status) status; *) echo $ "Usage: $ Start|stop|reload|configtest|status|restart}" Exit 2esac
Shell Script-Nginx startup script