|
[楼主] jexus 服务自动守护.sh #!/bin/bash ##create by goosns.com @ qqfei@qq.com,2011-4-2 # usage: # 1.Copy Shell To monoPath # chmod +x checkjexus.sh # 2.Add Crontab # */2 * * * * [monoPath]/checkjexus.sh jexuspath=/tools/jexus-4.2 logfile='/tools/jexus-4.2/log/checkjexus.log'; function mono_is_running(){ threadnum=`ps aux|grep mono|grep -v grep -wc`; if [ "$threadnum" -eq '0' ];then echo '0'; else echo '1'; fi return; } function current_time(){ if [ -z "$1" ];then format="%Y-%m-%d %H:%M:%S%Z"; else format=$1; fi echo `date +"$format"` `uptime`; return; } function logtofile(){ echo $(current_time) $2>>$1; } function mono_restart(){ killall -9 mono >/dev/null 2>&1; $jexuspath/jws.start sleep 3; threadnum=$(mono_is_running); if [ $threadnum -eq '0' ]; then echo "0"; else echo '1'; fi return; } isrunning=$(mono_is_running); if [ "$isrunning" -eq '0' ];then logtofile $logfile "mono service was died."; restart=$(mono_restart); if [ $restart -eq '0' ];then logtofile $logfile "mono service restart failed."; else logtofile $logfile "mono service restart success."; fi else logtofile $logfile "mono service is running."; fi exit 0; -----------运行效果如下-------- [/tools/jexus-4.2]#cat log/checkjexus.log 2011-04-02 17:46:57CST mono service is running. 2011-04-02 17:50:00CST 17:50:00 up 2 days, 8:15, 4 users, load average: 0.01, 0.22, 0.72 mono service is running. 2011-04-02 17:51:18CST 17:51:18 up 2 days, 8:16, 4 users, load average: 0.01, 0.19, 0.70 mono service was died. 2011-04-02 17:51:21CST 17:51:21 up 2 days, 8:16, 4 users, load average: 0.25, 0.24, 0.71 mono service restart success. 2011-04-02 17:51:38CST 17:51:38 up 2 days, 8:16, 4 users, load average: 0.35, 0.26, 0.71 mono service was died. 2011-04-02 17:51:41CST 17:51:41 up 2 days, 8:16, 4 users, load average: 0.48, 0.29, 0.72 mono service restart success --------------------- 最新sh:: http://hi.baidu.com/xc_hai/ [1楼] 回复:jexus 服务自动守护.sh 新颖实用,感谢! | |