mirror of
https://github.com/kaboomserver/buildpack.git
synced 2024-09-28 19:23:01 +00:00
24 lines
596 B
Bash
Executable file
24 lines
596 B
Bash
Executable file
#!/bin/sh
|
|
|
|
# The following script is a failsafe for killing the Minecraft server if it happens
|
|
# to be stuck
|
|
|
|
while true; do
|
|
sleep 420
|
|
logfile=$HOME/logs/latest.log
|
|
|
|
if [ -f "$logfile" ]; then
|
|
|
|
# If localhost:25565 doesn't respond to ping, or if the log file is older than
|
|
# 3 minutes, kill the server
|
|
|
|
if [ "$(env printf '\xFE' | nc -w 5 localhost 25565 | wc -m)" -eq 0 ] ||
|
|
[ "$(( $(date +%s) - $(date -r $logfile +%s) ))" -gt 180 ]; then
|
|
if [ "$(tail -20 $logfile | grep -c 'ERROR]: Requested chunk')" -eq 1 ]; then
|
|
rm -rf $HOME/worlds/
|
|
fi
|
|
pkill -9 java
|
|
fi
|
|
fi
|
|
done
|