autopause: improve network interface lookup (#1949)

This commit is contained in:
Geoff Bourne
2023-02-04 10:57:06 -06:00
committed by GitHub
parent 1c670815d2
commit b400dfbb74
2 changed files with 9 additions and 5 deletions
+2 -4
View File
@@ -10,9 +10,7 @@ fi
autopause_error_loop() { autopause_error_loop() {
logAutopause "Available interfaces within the docker container:" logAutopause "Available interfaces within the docker container:"
INTERFACES=$(echo /sys/class/net/*) logAutopause " $(available_interfaces)"
INTERFACES=${INTERFACES//\/sys\/class\/net\//}
logAutopause " $INTERFACES"
logAutopause "Please set the environment variable AUTOPAUSE_KNOCK_INTERFACE to the interface that handles incoming connections." logAutopause "Please set the environment variable AUTOPAUSE_KNOCK_INTERFACE to the interface that handles incoming connections."
logAutopause "If unsure which interface to choose, run the ifconfig command in the container." logAutopause "If unsure which interface to choose, run the ifconfig command in the container."
logAutopause "Autopause failed to initialize. This log entry will be printed every 30 minutes." logAutopause "Autopause failed to initialize. This log entry will be printed every 30 minutes."
@@ -37,7 +35,7 @@ if [[ -z "$AUTOPAUSE_KNOCK_INTERFACE" ]] ; then
logAutopause "AUTOPAUSE_KNOCK_INTERFACE variable must not be empty!" logAutopause "AUTOPAUSE_KNOCK_INTERFACE variable must not be empty!"
autopause_error_loop autopause_error_loop
fi fi
if ! [[ -d "/sys/class/net/$AUTOPAUSE_KNOCK_INTERFACE" ]] ; then if ! available_interfaces | grep -q "$AUTOPAUSE_KNOCK_INTERFACE" ; then
logAutopause "Selected interface \"$AUTOPAUSE_KNOCK_INTERFACE\" does not exist!" logAutopause "Selected interface \"$AUTOPAUSE_KNOCK_INTERFACE\" does not exist!"
autopause_error_loop autopause_error_loop
fi fi
+7 -1
View File
@@ -23,7 +23,9 @@ mc_server_listening() {
java_clients_connections() { java_clients_connections() {
local connections local connections
if java_running ; then if java_running ; then
connections=$(mc-monitor status --host localhost --port "$SERVER_PORT" --show-player-count) if ! connections=$(mc-monitor status --host localhost --port "$SERVER_PORT" --show-player-count); then
connections=0
fi
else else
connections=0 connections=0
fi fi
@@ -33,3 +35,7 @@ java_clients_connections() {
java_clients_connected() { java_clients_connected() {
(( $(java_clients_connections) > 0 )) (( $(java_clients_connections) > 0 ))
} }
available_interfaces() {
ifconfig -s | tail +2 | cut -f1 -d ' '
}