docker-minecraft-server/files/auto/autopause-fcns.sh

47 lines
1.1 KiB
Bash
Raw Normal View History

2020-05-20 13:17:58 +00:00
#!/bin/bash
# shellcheck source=../scripts/start-utils
. "${SCRIPTS:-/}start-utils"
2020-05-20 13:17:58 +00:00
current_uptime() {
awk '{print $1}' /proc/uptime | cut -d . -f 1
2020-05-20 13:17:58 +00:00
}
java_running() {
[[ $( ps -ax -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^S.*$ ]]
2020-05-20 13:17:58 +00:00
}
java_process_exists() {
2021-01-12 22:05:12 +00:00
[[ -n "$(ps -ax -o comm | grep 'java')" ]]
}
2020-05-20 13:17:58 +00:00
rcon_client_exists() {
[[ -n "$(ps -ax -o comm | grep 'rcon-cli')" ]]
2020-05-20 13:17:58 +00:00
}
use_proxy() {
if isTrue "$USES_PROXY_PROTOCOL"; then
echo "--use-proxy"
fi
}
2020-05-20 13:17:58 +00:00
mc_server_listening() {
mc-monitor status $(use_proxy) --host "${SERVER_HOST:-localhost}" --port "$SERVER_PORT" --timeout 10s >&/dev/null
2020-05-20 13:17:58 +00:00
}
java_clients_connections() {
2020-05-20 13:17:58 +00:00
local connections
if java_running; then
if ! connections=$(mc-monitor status $(use_proxy) --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
fi
else
connections=0
2020-05-20 13:17:58 +00:00
fi
echo $connections
}
java_clients_connected() {
(( $(java_clients_connections) > 0 ))
}