1,shell脚本:check_app.sh
代码:
#!/bin/sh
#设置环境变量 export PYTHONPATH=/python/python_workspace/python_runapp:$PYTHONPATH #检测进程是否运行 isRunning=$(ps -ef | grep "app" | grep -v "grep" | grep -v "vim") if [ "$isRunning" ] ; then echo "app service was already started" else echo "app service was not started" echo "Starting service ..." python /python/application/app.py > /dev/null 2>&1 & fi #检测站点是否可正常访问 #$? 指访问状态 #0 正常 #urls='http://www.app.com http://www.jbxue.com' urls='http://www.app.com' for url in $urls do curl -sf $url state=$? if [ $state != 0 ]; then PIDS=`ps -ef | grep "app" | grep -v "grep" | grep -v "vim" | grep -v "sh" | awk {"print $2"}` for P in $PIDS do kill -9 $P done python /python/application/app.py > /dev/null 2>&1 & else echo "$url is available" fi done
2,添加计时任务
crontab -e
*/20 * * * * bash /sh/check_app.sh (责任编辑:IT) |