首页 > 系统服务 > 详细

Linux中nginx服务器启动脚本

时间:2017-07-15 12:30:10      阅读:303      评论:0      收藏:0      [点我收藏+]

     Linux中nginx服务器启动脚本,将此脚本放入/etc/init.d/目录下,进行启动和关闭,并用chkconfig命令将nginx加入到chkconfig管理中,设置开机自启动。

     详细脚本如下:

#!/bin/bash
#author wangning
#date 2017-7-14
#qq 1198143315
#Email 1198143315@qq.com

[ -f /etc/init.d/functions ] && . /etc/init.d/functions

#chkconfig: 2345 46 78
#description: nginx service manage

#################define variable################################################
num=`ps -ef|grep worker|grep -v grep|wc -l`
nginx=/application/nginx/sbin/nginx
########################start stop restart reload functions##########################
nginx_start(){
if [ $num -gt 5 ];then
   echo "the nginx service has running"
   exit 1
else
   $nginx    &>/dev/null
   action "start nginx" /bin/true 
fi
}

nginx_stop(){
if [ $num -lt 5 ];then
   echo "the nginx service has stoped"
   exit 2
else  
   $nginx -s stop
   action "stop nginx" /bin/true
fi
}

nginx_restart(){
$nginx -s stop
$nginx
action "restart nginx" /bin/true
}

nginx_reload(){
$nginx -s reload
action "reload nginx" /bin/true
}
#########################nginx manage###########################################


case $1 in
  start)
        nginx_start
        ;;
  stop)
        nginx_stop
        ;;
  restart)
        nginx_restart
        ;;
  reload)
        nginx_reload
        ;;
  *)
        echo "USAGE:$0 {start|stop|restart|reload}"
esac


本文出自 “飞奔的骆驼” 博客,请务必保留此出处http://wn2100.blog.51cto.com/9915310/1947817

Linux中nginx服务器启动脚本

原文:http://wn2100.blog.51cto.com/9915310/1947817

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!