linux shell脚本监控进程崩溃自动重启,由于目前有Python实现的通讯组件时不时会异常中断,在还没有找到问题的解决办法时先暂时用shell监控并自动重启处理。
basepath=$(
cd `dirname
$0`;
pwd)
while true
do
procnum=`ps -ef|grep
"服务名称"|grep -v grep|wc
-l`
if [
$procnum -eq 0 ]
then
启动命令
echo `date +%Y-%m-%d` `date +%H:%M:%S`
"restart 服务" >>
$basepath/shell.log
fi
sleep
1
done
后台执行 nohup ./shell.sh &