干货分享,灵感创作,不定期更新,敬请期待。

php5-fpm启动重启shell脚本

Linux运维 xhq 1559℃ 0评论

网上还有写得更好的,我也就写着玩,可以拿去参考,也可以自己扩展平滑重启
用法:yourpath/scriptname.sh {start|restart|reload}

#!/bin/bash
state="$1"
psphpfpm(){
echo "the bash 'ps -e | grep php' result:"
ps -e | grep php
}
chStop1(){
if [ ! -f "/run/php5-fpm.pid" ];
then
#echo "the process php5-fpm not running"
echo false
else
echo `cat /run/php5-fpm.pid`
fi
}
chStop2(){
pid="$1"
fpm=`ps -P ${pid} | grep php5-fpm`
if [ "${fpm}" == "" ];
then
echo "the process php5-fpm is stopped"
else
echo "there are something error in php5-fpm stop"
fi
#fi
psphpfpm
}
chStart(){
if [ -f "/run/php5-fpm.pid" ];
then
echo "the process php5-fpm is running"
else
echo "there are something error in php5-fpm start"
fi
psphpfpm
}
chRestart1(){
if [ ! -f "/run/php5-fpm.pid" ];
then
echo "place start the php5-fpm first"
exit 0
fi
}
chRestart2(){
if [ -f "/run/php5-fpm.pid" ];
then
echo "the process php5-fpm restart successful"
else
echo "there are something error in your process php5-fpm restart"
fi
psphpfpm
}
chStatus(){
if [ -f "/run/php5-fpm.pid" ];
then
echo "php5-fpm is running"
else
echo "php5-fpm is stopped"
fi
psphpfpm
}
if [ "${state}" == "status" ];
then
chStatus
elif [ "${state}" == "start" ];
then
php5-fpm
chStart
elif [ "${state}" == "stop" ];
then
pid=$(chStop1)
if [ "${pid}" == "false" ];
then
echo "the process php5-fpm already stopped,which mean is not running"
exit 0
fi
kill -INT `cat /run/php5-fpm.pid`
chStop2 ${pid}
elif [ "${state}" == "restart" ];
then
chRestart1
kill -USR2 `cat /run/php5-fpm.pid`
chRestart2
else
echo "please enter the parameters within {start|stop|restart}"
fi

这个写得不错
http://www.ttlsa.com/php/php-fpm-service-scripts/

转载请注明:爱游思 » php5-fpm启动重启shell脚本

喜欢 (2)

您必须 登录 才能发表评论!