diff --git a/files/autopause/autopause-daemon.sh b/files/autopause/autopause-daemon.sh index 5c49cce5..e2f48608 100644 --- a/files/autopause/autopause-daemon.sh +++ b/files/autopause/autopause-daemon.sh @@ -15,17 +15,35 @@ autopause_error_loop() { logAutopause "Autopause failed to initialize. This log entry will be printed every 30 minutes." while : do - if [[ -n $(ps -ax -o comm | grep java) ]] ; then - break - fi - sleep 0.1 + sleep 1800 + logAutopause "Autopause failed to initialize." done +} + +# wait for java process to be started +while : +do + if java_process_exists ; then + break + fi + sleep 0.1 +done + +# check for interface existence +if [[ -z "$AUTOPAUSE_KNOCK_INTERFACE" ]] ; then + logAutopause "AUTOPAUSE_KNOCK_INTERFACE variable must not be empty!" + autopause_error_loop +fi +if ! [[ -d "/sys/class/net/$AUTOPAUSE_KNOCK_INTERFACE" ]] ; then + logAutopause "Selected interface \"$AUTOPAUSE_KNOCK_INTERFACE\" does not exist!" + autopause_error_loop +fi + +sudo /usr/sbin/knockd -c /tmp/knockd-config.cfg -d -i "$AUTOPAUSE_KNOCK_INTERFACE" +if [ $? -ne 0 ] ; then logAutopause "Failed to start knockd daemon." - logAutopause "Possible cause: docker's host network mode." - logAutopause "Recreate without host mode or disable autopause functionality." - logAutopause "Stopping server." - pkill -SIGTERM java - exit 1 + logAutopause "Probable cause: Unable to attach to interface \"$AUTOPAUSE_KNOCK_INTERFACE\"." + autopause_error_loop fi STATE=INIT diff --git a/files/autopause/autopause-fcns.sh b/files/autopause/autopause-fcns.sh index 69b7f9e4..69eb9d08 100644 --- a/files/autopause/autopause-fcns.sh +++ b/files/autopause/autopause-fcns.sh @@ -9,7 +9,7 @@ java_running() { } java_process_exists() { - [[ -n "$(ps -a -o comm | grep 'java')" ]] + [[ -n "$(ps -ax -o comm | grep 'java')" ]] } rcon_client_exists() {