一个php项目,laravel框架,使用了nginx php redis mysql 还有进程守护supervisor,用于laravel的异步队列进程queue,当服务器重启后有可能部分服务没有成功启动这个时候可以用定时任务去检查服务状态,然后对不正常的自动启动就可以。直接上shell代码
echo "start..."
nginx_procnum=`ps -ef|grep "nginx"|grep -v grep|wc -l`
mysql_procnum=`ps -ef|grep "mysqld"|grep -v grep|wc -l`
redis_procnum=`ps -ef|grep "redis"|grep -v grep|wc -l`
supervisorctl_procnum=`ps -ef|grep "supervisor"|grep -v grep|wc -l`
queue_procnum=`ps -ef|grep "queue"|grep -v grep|wc -l`
if [ $redis_procnum -eq 0 ]
then
echo "start redis..."
/etc/init.d/redis restart
fi
if [ $mysql_procnum -eq 0 ]
then
echo "start mysqld..."
/etc/init.d/mysqld restart
fi
if [ $nginx_procnum -eq 0 ]
then
echo "start nginx..."
/etc/init.d/nginx restart
fi
if [ $supervisorctl_procnum -eq 0 ]
then
echo "start supervisor..."
/www/server/panel/pyenv/bin/supervisorctl restart all
elif [ $queue_procnum -eq 0 ]
then
echo "start supervisor..."
/www/server/panel/pyenv/bin/supervisorctl restart queue:queue_00
fi
echo "end==="
建议设置成每3分钟运行一次。