buildpack/script/alivecheck
2019-08-16 04:32:46 +03:00

22 lines
631 B
Bash
Executable file

#!/bin/sh
while true; do
sleep 180
logfile=$HOME/logs/latest.log
if [ "$(env printf '\xFE' | nc -w 5 localhost 25565 | wc -m)" -eq 0 ]; then
if [ -f "$logfile" ]; then
if [ "$(tail -20 $logfile | grep -c 'ERROR]: Requested chunk')" -eq 1 ]; then
rm -rf $HOME/worlds/
fi
fi
pkill -9 java
elif [ -f "$logfile" ]; then
date="$(tail -1 $logfile | grep -oP '(?<=\[).*?(?=\])' | head -1 | date -f - +%s)"
if [ "$(( $(date +%s) - ${date:=$(date +%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