swoole服务挂掉,配合cron定时任务,自动启动

swoole常用的命令:

        swoole停止服务: kill -9 $(ps aux|grep 'socket.php'|grep -v grep|awk '{print $2}')

开启swoole服务压人后台命令:

    nohup php socket.php &
    screen socket.php

 

 

swoole 脚本,如果服务停止,每一分钟检测自动启动,配合cron定时任务运行下边的脚本文件

#!/bin/bash
count=`ps -fe |grep "socket.php" | grep -v "grep" | wc -l`

echo $count
if [ $count -lt 1 ]; then
ps -eaf |grep "socket.php" | grep -v "grep"| awk '{print $2}'|xargs kill -9
sleep 2
ulimit -c unlimited
/usr/local/php7/bin/php /data/www/shoxot-api/mqtt/socket.php
echo "restart";
echo $(date +%Y-%m-%d_%H:%M:%S) >/data/script/log/restart.log
fi

这里有一个梗 ulimit -c unlimited 这里设置了unlimited 如果报错了 会生成一个很大的core文件 ,并且很可能会重复的生成,导致硬盘直接占满,正式环境最好去掉。

 

posted @ 2018-09-12 14:15  博飞  阅读(1705)  评论(0编辑  收藏  举报