swoole服务定时监控、重启脚本

#!/usr/bin/bash
count=`ps -ef|grep “swoole进程” | grep -v “grep” | grep “master” | wc -l`
echo $count

if [ $count -lt 1 ]; then
ps -eaf |grep “swoole进程” | grep -v “grep”| awk ‘{print $2}’|xargs kill -9
sleep 2
ulimit -c unlimited
/usr/bin/php /你的swoole服务脚本路径/xxx.php start -d -h 127.0.0.1 -p 8901
echo “restart”;
echo $(date +%Y-%m-%d_%H:%M:%S) >/data/log/restart.log
fi

 

 

添加到定时任务(crontab)

*/1 * * * * /脚本路径/swoole_server.sh > /dev/null 2>&1 &