From ffb50cfe28346c1b64df2c16021c2a1d42b63304 Mon Sep 17 00:00:00 2001 From: ErstBlack <52228294+ErstBlack@users.noreply.github.com> Date: Thu, 31 Dec 2020 14:15:44 -0500 Subject: [PATCH] Fixing AUTOPAUSE on Raspberry Pi 4s (#708) * Replacing killall with pkill and ps -a to ps -ax * Adding net-tools and removing -q from pkill * Missed the resume.sh * Christ there's a lot of ps calls * Adding -x to health.sh, replacing killall with pkill in sudoers-mv, and replacing su-exec with gosu in knockd-config.cfg Co-authored-by: sean.sullivan.ctr@progeny.net --- Dockerfile | 1 + files/autopause/autopause-daemon.sh | 4 ++-- files/autopause/autopause-fcns.sh | 4 ++-- files/autopause/knockd-config.cfg | 4 ++-- files/autopause/pause.sh | 4 ++-- files/autopause/resume.sh | 4 ++-- files/sudoers-mc | 2 +- health.sh | 2 +- 8 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index b049e493..5b05af5d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ RUN apt-get update \ imagemagick \ gosu \ sudo \ + net-tools \ curl wget \ jq \ dos2unix \ diff --git a/files/autopause/autopause-daemon.sh b/files/autopause/autopause-daemon.sh index e46fdffa..0c757993 100644 --- a/files/autopause/autopause-daemon.sh +++ b/files/autopause/autopause-daemon.sh @@ -8,7 +8,7 @@ sudo /usr/sbin/knockd -c /tmp/knockd-config.cfg -d if [ $? -ne 0 ] ; then while : do - if [[ -n $(ps -o comm | grep java) ]] ; then + if [[ -n $(ps -ax -o comm | grep java) ]] ; then break fi sleep 0.1 @@ -17,7 +17,7 @@ if [ $? -ne 0 ] ; then logAutopause "Possible cause: docker's host network mode." logAutopause "Recreate without host mode or disable autopause functionality." logAutopause "Stopping server." - killall -SIGTERM java + pkill -SIGTERM java exit 1 fi diff --git a/files/autopause/autopause-fcns.sh b/files/autopause/autopause-fcns.sh index 5ebae93c..31f016a6 100644 --- a/files/autopause/autopause-fcns.sh +++ b/files/autopause/autopause-fcns.sh @@ -5,11 +5,11 @@ current_uptime() { } java_running() { - [[ $( ps -a -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^S.*$ ]] + [[ $( ps -ax -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^S.*$ ]] } rcon_client_exists() { - [[ -n "$(ps -a -o comm | grep 'rcon-cli')" ]] + [[ -n "$(ps -ax -o comm | grep 'rcon-cli')" ]] } mc_server_listening() { diff --git a/files/autopause/knockd-config.cfg b/files/autopause/knockd-config.cfg index 86c98d02..68ab28de 100644 --- a/files/autopause/knockd-config.cfg +++ b/files/autopause/knockd-config.cfg @@ -3,10 +3,10 @@ [unpauseMCServer-server] sequence = 25565 seq_timeout = 1 - command = /sbin/su-exec minecraft:minecraft /autopause/resume.sh + command = /usr/sbin/gosu minecraft:minecraft /autopause/resume.sh tcpflags = syn [unpauseMCServer-rcon] sequence = 25575 seq_timeout = 1 - command = /sbin/su-exec minecraft:minecraft /autopause/resume.sh + command = /usr/sbin/gosu minecraft:minecraft /autopause/resume.sh tcpflags = syn diff --git a/files/autopause/pause.sh b/files/autopause/pause.sh index c84bdda5..bcd1a06c 100755 --- a/files/autopause/pause.sh +++ b/files/autopause/pause.sh @@ -2,7 +2,7 @@ . /start-utils -if [[ $( ps -a -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^S.*$ ]] ; then +if [[ $( ps -ax -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^S.*$ ]] ; then # save world rcon-cli save-all >/dev/null @@ -17,5 +17,5 @@ if [[ $( ps -a -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^S.*$ ]] ; th # finally pause the process logAutopauseAction "Pausing Java process" - killall -q -STOP java + pkill -STOP java fi diff --git a/files/autopause/resume.sh b/files/autopause/resume.sh index 73ab648e..6ae5a8cf 100755 --- a/files/autopause/resume.sh +++ b/files/autopause/resume.sh @@ -2,7 +2,7 @@ . /start-utils -if [[ $( ps -a -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^T.*$ ]] ; then +if [[ $( ps -ax -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^T.*$ ]] ; then logAutopauseAction "Knocked, resuming Java process" - killall -q -CONT java + pkill -CONT java fi diff --git a/files/sudoers-mc b/files/sudoers-mc index 419c352e..39926d72 100644 --- a/files/sudoers-mc +++ b/files/sudoers-mc @@ -1,2 +1,2 @@ -%minecraft ALL=(ALL) NOPASSWD:/usr/bin/killall +%minecraft ALL=(ALL) NOPASSWD:/usr/bin/pkill %minecraft ALL=(ALL) NOPASSWD:/usr/sbin/knockd diff --git a/health.sh b/health.sh index e2ad7e72..a3f14aa6 100644 --- a/health.sh +++ b/health.sh @@ -5,7 +5,7 @@ if isTrue "${DISABLE_HEALTHCHECK}"; then echo "Healthcheck disabled" exit 0 -elif isTrue "${ENABLE_AUTOPAUSE}" && [[ "$( ps -a -o stat,comm | grep 'java' | awk '{ print $1 }')" =~ ^T.*$ ]]; then +elif isTrue "${ENABLE_AUTOPAUSE}" && [[ "$( ps -ax -o stat,comm | grep 'java' | awk '{ print $1 }')" =~ ^T.*$ ]]; then echo "Java process suspended by Autopause function" exit 0 else