保证程序发生异常的时候,自动的换起一个程序。
#! /bin/sh #进程名字可修改 PRO_NAME=ConsumerPointBeanstalkd:consumer echo `pwd` while true ; do # 用ps获取$PRO_NAME进程数量 NUM=`ps aux | grep ${PRO_NAME} | grep -v grep |wc -l` # echo $NUM # 少于1,重启进程 if [ "${NUM}" -lt "1" ];then echo "${PRO_NAME} was killed" php artisan ${PRO_NAME} >> /dev/null 2>&1 # php artisan ConsumerPointBeanstalkd:consumer # 大于1,杀掉所有进程,重启 # elif [ "${NUM}" -gt "1" ];then # echo "more than 1 ${PRO_NAME},killall ${PRO_NAME}" fi done exit 0 启动: nohup ./deamonConsumerPointBeanstalkd.sh &
停止,先停止守护进行程序。
# 先检查守护进程的程序,然后将其杀掉 ps -ef | grep deamonConsumerPointBeanstalkd kill -9 ${pid} # 再将 主程序的进程杀掉 ps -ef | grep ConsumerPointBeanstalkd:consumer kill -9 ${pid}