nginx 启动服务脚本(shell)

#!/bin/bash
ng_path='/usr/local/nginx'
ng_bin="$ng_path/sbin/nginx"
ng_pid="$ng_path/logs/nginx.pid"

#Configure Script Variables
red='\033[31m'
green='\033[32m'
end='\033[0m'

#check
if [ ! -d $ng_path ];then
     echo -e "${red}ERROR:${end} $ng_path Directory does not exist !!"
     exit 1
elif [ ! -f $ng_bin ];then
     echo -e "${red}ERROR:${end} $ng_bin File does not exist !!"
     exit 1
fi

#Service state function
ng_start() {
     if [ -f $ng_pid ];then
        echo -e "${green}Service is running PID is `cat $ng_pid` ${end}"
     else
	$ng_bin &> /dev/null
        if [ $? -eq 1 ];then
           echo -n -e "${red}ERROR ${end}" && $ng_bin
        else
           echo -e "${green}Service startup succeeded PID is `cat $ng_pid` ${end}"
        fi
     fi
     }

ng_stop() {
     $ng_bin -s stop &> /dev/null
        if [ $? -eq 1 ];then
           echo -n -e "${red}ERROR ${end}" && $ng_bin -s stop
        else
           rm -rf $ng_pid
           echo -e "${green}Service is down${end}"
        fi
     }

ng_check() {
     $ng_bin -t
     }

ng_status() {
     if [ -f $ng_pid ];then
        echo -e "${green}Service is running PID is `cat $ng_pid` ${end}"
     else 
        echo -e "${red}Service is not running${end}" 
     fi
     }

ng_reload() {
     $ng_bin -s reload &> /dev/null
        if [ $? -eq 1 ];then
           echo -n -e "${red}ERROR ${end}" && $ng_bin -s reload
        else
           echo -e "${green}Service load succeeded${end}"
        fi
     }

#================================
case $1 in 
     start)
          ng_start;;
     stop)
          ng_stop;;
     status)
          ng_status;;
     check)
          ng_check;;
     reload)
          ng_reload;;
     restart)
          ng_stop && ng_start;;
     *)
          echo "Usage: $0 {start|stop|restart|reload|status|check}"
esac

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值