nginx启动脚本

#!/bin/bash
start_file="/usr/local/nginx/sbin/nginx"
PID="/usr/local/nginx/logs/nginx.pid"
#start
start(){
	if [ -f $PID ];then
		echo "nginx already start"
		exit 1
	else
		$start_file && echo "start success" || echo "start failed"
	fi
}

stop(){
	if [ -f $PID ];then
		$start_file -s stop && echo "stop success" || echo "stop failed"
	else
		echo "nginx already stop"
	fi
}

status(){
	if [ -f $PID ];then
		echo "nginx is running"
	else
		echo "nginx is dead"
	fi
}

#main
case $1 in
start)
	start;;
stop)
	stop;;
status)
	status;;
restart)
	stop
	sleep 1 
	start;;
*)
	echo "usage:$0 start|stop|status|restart";;
esac

  stop和start之间最好有停留时间,因为防止nginx没有完全关闭

猜你喜欢

转载自www.cnblogs.com/dccrussell/p/9095847.html