作者:心语
监听并重启:
#!/bin/sh
# 天龙服务端监听Server运行状态
# shell by 心语难诉
# 2021-3-19 22:19:51
echo "
+----------------------------------------------------------------------
| TLBB Server Listener
+----------------------------------------------------------------------
| Copyright © 2020-2099 Wigiesen
+----------------------------------------------------------------------
| Author: Wigiesen QQ:437723442
+----------------------------------------------------------------------
"
AddCrontab(){
# 查询是否已经写入过计划任务
crontabCount=`crontab -l|grep listenServer_sp.sh |grep -v grep|wc -l`
if [ $crontabCount = 0 ];then
(echo "*/2 * * * *;sh /home/tlbb/listenServer_sp.sh > /dev/null 2>&1 &"; crontab -l) | crontab
fi
}
AddCrontab
# 记录日志时间
echo `date +"%Y-%m-%d %H:%M:%S"` >> /home/tlbb/listenServer.log
echo "[CHECK]:Check server running status..."
# 查询Server是否正常
ServerTestCount=`ps -fe|grep ServerTest |grep -v grep|wc -l`
# 如果 Server 不存在,就重启Server
if [ $ServerTestCount = 0 ];then
#写入日志
echo "[ERROR]:TLBB Service is not running !!!"
echo "[STATUS]:restart TLBB Server..." >> /home/tlbb/listenServer.log
cd /home/tlbb/Server/ && ./ServerTest >/dev/null 2>&1 &
# cd /home/tlbb/Server/
# ./ServerTest >/dev/null 2>&1 &
echo "[STATUS]:Server restart is complete..." >> /home/tlbb/listenServer.log
echo "-----------------------------------------" >> /home/tlbb/listenServer.log
else
#写入日志
echo "[STATUS]:TLBB Server is runing....." >> /home/tlbb/listenServer.log
echo "-----------------------------------------" >> /home/tlbb/listenServer.log
fi
监听并抓取掉引擎前最后10秒的日志,方便排错
#!/bin/bash
# 监听并抓取掉引擎前最后10秒的日志,方便排错
run(){
ServerTestCount=`ps -fe|grep ServerTest |grep -v grep|wc -l`
if [ $ServerTestCount = 0 ];then
echo `date +"%Y-%m-%d %H:%M:%S"`
echo "Server dump"
cd /home/tlbb/Server/
zip -r Log.zip Log/
break
else
echo `date +"%Y-%m-%d %H:%M:%S"`
echo "Server is ok"
cd /home/tlbb/Server/Log
rm -rf *
fi
}
while true;do
run
sleep 10
done
|