linux nginx自动重启脚本,linux下nginx启动停止重启控制脚本

这是控制nginx服务的脚本文件,包括控制nginx的启动、重启、停止、平滑重启、对配置文件的额检查。

[[email protected] ~]# cat nginx.sh

#!/bin/env bash

# description:nginx server   ###必须加描述

# nginx - this script is used to control nginx service

# processname nginx

# chkconfig: - 85 15

# edit by sun

# date 2014-07-03

# email address [email protected]

nginx="/usr/local/nginx/sbin/nginx"

prog="nginx"

conf_file="/usr/local/nginx/conf/nginx.conf"

start() {

if [ `pgrep $prog | wc -l` -eq 0 ];then

if [ -x $nginx ] && [ -f $conf_file ];then

$nginx -c $conf_file

ret=$?

if [ $ret -eq 0 ];then

echo "$prog start       successed"

else

echo "$prog start       failed"

fi

else

echo "$prog config file not exist"

fi

else

echo "$prog is already started ... "

fi

}

stop() {

if [ `pgrep $prog | wc -l` -ne 0 ];then

killall -9 $prog

ret=$?

if [ $ret -eq 0 ];then

echo "$prog stop       successed"

else

echo "$prog stop   failed"

fi

else

echo "$prog is already stopped ..."

fi

}

restart() {

stop

sleep 2

start

}

reload() {

if [ `pgrep $prog | wc -l` -ne 0 ];then

pid=`ps -ef | grep $prog | grep master | awk ‘{print $2}‘`

if [ -x $nginx ] && [ -f $conf_file ];then

kill -HUP $pid

ret=$?

if [ $ret -eq 0 ];then

echo "$prog reload  successed"

else

echo "$prog reload    failed"

fi

else

echo "$prog config file is not exist"

fi

else

echo "$prog is stopped, please start $prog first ..."

fi

}

check() {

if [ -x $nginx ] && [ -f $conf_file ];then

$nginx -t -c $conf_file

ret=$?

if [ $ret -eq 0 ];then

echo "$prog check successed"

else

echo "$prog check failed"

fi

fi

}

case $1 in

start)

start

;;

stop)

stop

;;

restart)

restart

;;

reload)

reload

;;

check)

check

;;

*)

echo "Usage: $0 {start|stop|restart|reload|check}"

esac

运行bash nginx.sh start等操作即可。

时间: 07-03

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值