服务老是自己挂,还是内存溢出,得,无人值守,自己重启吧
#!/bin/bash
OUTOFMEMORY=$(tail -n100 ./chat.log | grep "OutOfMemoryError" | grep "UncaughtExceptionHandler" | grep -v "resp")
if [[ ! -z $OUTOFMEMORY ]]; then
./api.sh stop
sleep 2
./api.sh start
# Get current date and time
NOW=$(date +"%m-%d-%Y %T")
echo "Restarted due to OutOfMemoryError on $NOW" >> ./restart.log
fi
然后配置 crontab -e
* * * * * cd /opt/sh;/opt/webapp/api/auto.sh

该bash脚本用于监控chat.log文件,检查是否存在OutOfMemoryError异常。如果检测到异常,脚本会停止api服务,等待2秒后重新启动。同时,它将当前日期和时间记录在restart.log中。此功能已通过crontab设置为定期执行。
2981

被折叠的 条评论
为什么被折叠?



