监控进程并自动重启脚本
监测py文件是否运行,如果没有重启该目录下的所有py文件
shell脚本,后台运行即可
#!/bin/sh while true do SERVER_MAIN_DIR='/data/crawl_redis/save_redis' for main in $(find ${SERVER_MAIN_DIR} -name "*.py" | awk -F"/" '{print $NF}') do SERVICE_NUM=$(ps -ef | grep "${main}" | egrep -v 'grep|monitor' | wc -l) # check service status if [ ${SERVICE_NUM} -lt 1 ];then echo "Process [${main}] not be found !" cd ${SERVER_MAIN_DIR} && \ nohup python ${main} >> nohup.out 2>&1 & else echo "Process [${main}] has started... nothing to do" fi done sleep 10 done