02.case案例Nginx启动脚本
/usr/sbin/nginx 启动
/usr/sbin/nginx -s stop 停止
/usr/sbin/nginx -s reload 重新加载
/usr/sbin/nginx -s restart 不支持
/usr/sbin/nginx -s stop && sleep 1 && /usr/sbin/nginx 重启
-----------------Nginx启动脚本
[root@web01 ~]# cat nginx_start.sh
#!/bin/bash
[ -f /etc/init.d/functions ] && . /etc/init.d/functions
Nginx='/usr/sbin/nginx'
te(){
if [ $? -eq 0 ];then
action "Nginx $1 is" /bin/true
else
action "Nginx $1 is" /bin/false
fi
}
case $1 in
start)
$Nginx
te $1
;;
stop)
$Nginx -s stop
te $1
;;
reload)
$Nginx -s reload
te $1
;;
restart)
$Nginx -s stop && sleep 1 && $Nginx
te $1
;;
status)
Nginx_port=`netstat -tnulp|grep nginx|awk '{print $4}'`
echo "Nginx_Port=$Nginx_port"
;;
*)
echo "Usage $0 [start|stop|restart|reload|status]"
esac