我的软路由【矿渣们的救赎】の Phicomm N1刷OpenWrt 已经无故障,正常运作一个多月了!
但是最近发现其中一个插件,偶尔会异常退出,无法重新启动。而且这个插件比较关键,没有启动会导致无法上网。
于是,自己写了一个进程守护的脚本restart.sh,放到计划任务里面。每隔10分钟检查一次,如果插件没有运行的话,就自动启动插件。
*/10 * * * * sh /etc/smartdns/restart.sh > /dev/null 2>&1 &
功能很简单,判断一下插件是否在运行,没有的话就启动:
#!/bin/sh
ISRUNNING=`ps | grep smartdns | grep -v "grep"`
if [ "$ISRUNNING" == "" ]
then
echo `date` "Restart SmartDNS" >> /tmp/smartdns.log
/usr/sbin/smartdns -f -c /var/etc/smartdns/smartdns.conf &
else
echo `date` "SmartDNS is running" >> /tmp/smartdns.log
fi
脚本复制到即可:
/etc/smartdns/restart.sh
效果如何?拭目以待!