#!/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
nginx 启动服务脚本(shell)
最新推荐文章于 2024-09-06 14:29:33 发布