2019-08-06 17:42:16 +00:00
|
|
|
#!/bin/sh
|
2019-11-30 18:05:23 +00:00
|
|
|
|
|
|
|
# The following script is a failsafe for killing the Minecraft server if it happens
|
|
|
|
# to be stuck
|
|
|
|
|
2019-11-30 18:51:52 +00:00
|
|
|
set -x
|
|
|
|
|
2019-08-06 17:42:16 +00:00
|
|
|
while true; do
|
2019-09-27 12:45:00 +00:00
|
|
|
sleep 420
|
2019-08-16 01:32:46 +00:00
|
|
|
logfile=$HOME/logs/latest.log
|
2019-11-30 16:18:45 +00:00
|
|
|
|
|
|
|
if [ -f "$logfile" ]; then
|
2019-11-30 18:05:23 +00:00
|
|
|
|
|
|
|
# If localhost:25565 doesn't respond to ping, or if the log file is older than
|
|
|
|
# 3 minutes, kill the server
|
|
|
|
|
2020-01-06 00:04:34 +00:00
|
|
|
if [ "$(( $(date +%s) - $(date -r $logfile +%s) ))" -gt 180 ] ||
|
2020-01-06 00:03:35 +00:00
|
|
|
[ "$(tail -20 $logfile | grep -cE 'Server thread|Paper Watchdog Thread|Async Chat Thread')" -eq 0 ]; then
|
2019-08-16 01:32:46 +00:00
|
|
|
if [ "$(tail -20 $logfile | grep -c 'ERROR]: Requested chunk')" -eq 1 ]; then
|
|
|
|
rm -rf $HOME/worlds/
|
|
|
|
fi
|
|
|
|
pkill -9 java
|
|
|
|
fi
|
2019-08-06 17:42:16 +00:00
|
|
|
fi
|
2019-12-22 18:59:31 +00:00
|
|
|
done
|