From c828985ebe36c44ef57d5af133e1bf38f534ea31 Mon Sep 17 00:00:00 2001 From: Felipe Paschoal Bergamo <64669985+felipepasc@users.noreply.github.com> Date: Wed, 5 Jun 2024 20:48:35 -0300 Subject: [PATCH] Add SERVER_HOST Environment in mc-monitor command (#2875) --- bin/mc-health | 2 +- docs/configuration/misc-options.md | 8 ++++++++ files/auto/autopause-fcns.sh | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bin/mc-health b/bin/mc-health index d5f2f65c..d3cc1919 100755 --- a/bin/mc-health +++ b/bin/mc-health @@ -13,6 +13,6 @@ elif isTrue "${ENABLE_AUTOPAUSE}" && [[ "$( ps -ax -o stat,comm | grep 'java' | echo "Java process suspended by Autopause function" exit 0 else - mc-monitor status "${MC_HEALTH_EXTRA_ARGS[@]}" --host localhost --port "${SERVER_PORT:-25565}" + mc-monitor status "${MC_HEALTH_EXTRA_ARGS[@]}" --host "${SERVER_HOST:-localhost}" --port "${SERVER_PORT:-25565}" exit $? fi diff --git a/docs/configuration/misc-options.md b/docs/configuration/misc-options.md index 49701d4c..da401261 100644 --- a/docs/configuration/misc-options.md +++ b/docs/configuration/misc-options.md @@ -55,6 +55,14 @@ To allow time for players to finish what they're doing during a graceful server The grace period can be increased using [the -t option on docker-compose down](https://docs.docker.com/compose/reference/down/) or set the [stop_grace_period](https://docs.docker.com/compose/compose-file/05-services/#stop_grace_period) in the compose file. +## Configuration Options for Minecraft Server Health Monitoring + +The image tags include specific variables to simplify configuration for monitoring the health of a Minecraft server: + +- `-e SERVER_HOST=localhost` : This variable sets the host address of the Minecraft server to be monitored. By default, it is set to `localhost`, but you can replace it with the actual hostname or IP address of your Minecraft server. + +- `-e SERVER_PORT=25565` : This variable sets the port number on which the Minecraft server is running. By default, Minecraft servers run on port 25565, but if your server is configured to use a different port, you should replace `25565` with the correct port number. This helps the monitoring system to accurately check the health status of the Minecraft server on the specified port. + ## OpenJ9 Specific Options The openj9 image tags include specific variables to simplify configuration: diff --git a/files/auto/autopause-fcns.sh b/files/auto/autopause-fcns.sh index 7a40cca7..2d4dc354 100644 --- a/files/auto/autopause-fcns.sh +++ b/files/auto/autopause-fcns.sh @@ -17,13 +17,13 @@ rcon_client_exists() { } mc_server_listening() { - mc-monitor status --host localhost --port "$SERVER_PORT" --timeout 10s >& /dev/null + mc-monitor status --host "${SERVER_HOST:-localhost}" --port "$SERVER_PORT" --timeout 10s >& /dev/null } java_clients_connections() { local connections if java_running ; then - if ! connections=$(mc-monitor status --host localhost --port "$SERVER_PORT" --show-player-count); then + if ! connections=$(mc-monitor status --host "${SERVER_HOST:-localhost}" --port "$SERVER_PORT" --show-player-count); then # consider it a non-zero player count if the ping fails # otherwise a laggy server with players connected could get paused connections=1