#!/bin/bash #监控进程是否出现堆空间内存溢出,如果发现内存溢出,则重启脚本 base_path=/opt/apps/test log_path=${base_path}/log while ((1==1)) do grep 'OutOfMemoryError' ${log_path}/server_nohup.log > /dev/null #进程日志中存在内存溢出 if [ "$?" == "0" ] ; then curr_now=$(date +'%F %T') echo "${curr_now}. OutOfMemoryError found in server_nohup.log, restart script will be invoked." | tee ${log_path}/monitor.log > ${log_path}/server_nohup.log sh ${base_path}/start_server.sh echo "Restart OK." | tee ${log_path}/monitor.log fi; #60秒检测一次 sleep 60 done
start_server.sh 为应用程序的启动脚本。
完事,以后就安心了,等有时间再去检查程序存在的问题。