判斷Nginx存活狀態

Dusk_Yun發表於2024-08-17
#!/bin/bash
. /etc/init.d/functions

te(){
	if [ $? -eq 0 ];then
		action "Nginx $1 " /bin/true
	else
		action "Nginx $1" /bin/false
	fi
}

case $1 in
	start)
		/usr/sbin/nginx
		te $1
	;;
	stop)
		/usr/sbin/nginx -s stop
		te $1
	;;
	reload)
		/usr/sbin/nginx -s reload
	;;
	restart)
		/usr/sbin/nginx -s stop && sleep 1 && /usr/sbin/nginx
	;;
	status)
		Nginx_port=`netstat -tnulp|grep nginx|sed -rn '/\btcp\b/p'|awk '{print $4}'`
		echo "Nginx_port: $Nginx_port"
	;;
	*)
		echo "Usage: $0 [start|stop|reload|restart|status]"
esac

相關文章