Nginx启动脚本
#!/bin/bash #author Template #Time 2018-06-30 22:07 # chkconfig 2345 40 98 # description nginx start/stop script prefix=/usr/local/nginx Nginx_Bin=${prefix}/sbin/nginx Nginx_Pid=${prefix}/logs/nginx.pid Nginx_Conf=${prefix}/conf/nginx.conf . /etc/init.d/functions function start(){ if [ ! -f ${Nginx_Pid} ];then #if [ `netstat -tlunp | grep nginx | wc -l` -eq 0 ];then ${Nginx_Bin} RETVAL=$? if [ ${RETVAL} -eq 0 ];then action "Nginx started" /bin/true else action "Nginx started" /bin/false fi return ${RETVAL} else echo "Nginx is running" return 0 fi } function stop(){ if [ -f ${Nginx_Pid} ];then ${Nginx_Bin} -s stop RETVAL=$? if [ ${RETVAL} -eq 0 ];then action "Nginx stoped" /bin/true return ${RETVAL} else action "Nginx stoped" /bin/false return ${RETVAL} fi else echo "Nginx is not running" return 1 fi } function reload(){ ${Nginx_Bin} -t -q -c ${Nginx_Conf} &> /dev/null RETVAL=$? if [ $RETVAL -eq 0 ];then ${Nginx_Bin} -s reload RETVAL=$? [ ${RETVAL} -eq 0 ] && action "Nginx reload" /bin/true || action "Nginx reload" /bin/false else action "Reload" /bin/false echo "Please check your configuration" return ${RETVAL} fi } case $1 in start) start RETVAL=$? ;; stop) stop RETVAL=$? ;; restart) stop sleep 1 start RETVAL=$? ;; reload) reload RETVAL=$? ;; *) echo "Usage: $0 {start|stop|restart|reload}" exit 1 esac exit $RETVAL