Autopause logs (#539)

This commit is contained in:
Michael Kirsch authored and GitHub committed 2020-05-23 09:15:10 -05:00
1 parent b11806e341
commit f2806d9335
5 files changed
+29 -20

No files matched your search

+15 -15
View File
@@ -1,9 +1,9 @@
#!/bin/bash #!/bin/bash
exec 1>/tmp/terminal-mc
. /autopause/autopause-fcns.sh . /autopause/autopause-fcns.sh
. /start-utils
sudo /usr/sbin/knockd -c /autopause/knockd-config.cfg -d sudo /usr/sbin/knockd -c /autopause/knockd-config.cfg -d
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
while : while :
@@ -13,10 +13,10 @@ if [ $? -ne 0 ] ; then
fi fi
sleep 0.1 sleep 0.1
done done
echo "[Autopause loop] Failed to start knockd daemon." logAutopause "Failed to start knockd daemon."
echo "[Autopause loop] Possible cause: docker's host network mode." logAutopause "Possible cause: docker's host network mode."
echo "[Autopause loop] Recreate without host mode or disable autopause functionality." logAutopause "Recreate without host mode or disable autopause functionality."
echo "[Autopause loop] Stopping server." logAutopause "Stopping server."
killall -SIGTERM java killall -SIGTERM java
exit 1 exit 1
fi fi
@@ -30,18 +30,18 @@ do
# Server startup # Server startup
if mc_server_listening ; then if mc_server_listening ; then
TIME_THRESH=$(($(current_uptime)+$AUTOPAUSE_TIMEOUT_INIT)) TIME_THRESH=$(($(current_uptime)+$AUTOPAUSE_TIMEOUT_INIT))
echo "[Autopause loop] MC Server listening for connections - stopping in $AUTOPAUSE_TIMEOUT_INIT seconds" logAutopause "MC Server listening for connections - stopping in $AUTOPAUSE_TIMEOUT_INIT seconds"
STATE=K STATE=K
fi fi
;; ;;
XK) XK)
# Knocked # Knocked
if java_clients_connected ; then if java_clients_connected ; then
echo "[Autopause loop] Client connected - waiting for disconnect" logAutopause "Client connected - waiting for disconnect"
STATE=E STATE=E
else else
if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then
echo "[Autopause loop] No client connected since startup / knocked - stopping" logAutopause "No client connected since startup / knocked - stopping"
/autopause/pause.sh /autopause/pause.sh
STATE=S STATE=S
fi fi
@@ -51,18 +51,18 @@ do
# Established # Established
if ! java_clients_connected ; then if ! java_clients_connected ; then
TIME_THRESH=$(($(current_uptime)+$AUTOPAUSE_TIMEOUT_EST)) TIME_THRESH=$(($(current_uptime)+$AUTOPAUSE_TIMEOUT_EST))
echo "[Autopause loop] All clients disconnected - stopping in $AUTOPAUSE_TIMEOUT_EST seconds" logAutopause "All clients disconnected - stopping in $AUTOPAUSE_TIMEOUT_EST seconds"
STATE=I STATE=I
fi fi
;; ;;
XI) XI)
# Idle # Idle
if java_clients_connected ; then if java_clients_connected ; then
echo "[Autopause loop] Client reconnected - waiting for disconnect" logAutopause "Client reconnected - waiting for disconnect"
STATE=E STATE=E
else else
if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then
echo "[Autopause loop] No client reconnected - stopping" logAutopause "No client reconnected - stopping"
/autopause/pause.sh /autopause/pause.sh
STATE=S STATE=S
fi fi
@@ -75,17 +75,17 @@ do
fi fi
if java_running ; then if java_running ; then
if java_clients_connected ; then if java_clients_connected ; then
echo "[Autopause loop] Client connected - waiting for disconnect" logAutopause "Client connected - waiting for disconnect"
STATE=E STATE=E
else else
TIME_THRESH=$(($(current_uptime)+$AUTOPAUSE_TIMEOUT_KN)) TIME_THRESH=$(($(current_uptime)+$AUTOPAUSE_TIMEOUT_KN))
echo "[Autopause loop] Server was knocked - waiting for clients or timeout" logAutopause "Server was knocked - waiting for clients or timeout"
STATE=K STATE=K
fi fi
fi fi
;; ;;
*) *)
echo "[Autopause loop] Error: invalid state: $STATE" logAutopause "Error: invalid state: $STATE"
;; ;;
esac esac
if [[ "$STATE" == "S" ]] ; then if [[ "$STATE" == "S" ]] ; then
+3 -1
View File
@@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
. /start-utils
if [[ $( ps -a -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^S.*$ ]] ; then if [[ $( ps -a -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^S.*$ ]] ; then
# save world # save world
rcon-cli save-all >/dev/null rcon-cli save-all >/dev/null
@@ -14,6 +16,6 @@ if [[ $( ps -a -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^S.*$ ]] ; th
done done
# finally pause the process # finally pause the process
echo "[$(date -Iseconds)] [Autopause] Pausing Java process" >/tmp/terminal-mc logAutopauseAction "Pausing Java process"
killall -q -STOP java killall -q -STOP java
fi fi
+3 -1
View File
@@ -1,6 +1,8 @@
#!/bin/bash #!/bin/bash
. /start-utils
if [[ $( ps -a -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^T.*$ ]] ; then if [[ $( ps -a -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^T.*$ ]] ; then
echo "[$(date -Iseconds)] [Autopause] Knocked, resuming Java process" >/tmp/terminal-mc logAutopauseAction "Knocked, resuming Java process"
killall -q -CONT java killall -q -CONT java
fi fi
-3
View File
@@ -41,9 +41,6 @@ if [ $(id -u) = 0 ]; then
chown -R ${runAsUser}:${runAsGroup} /autopause chown -R ${runAsUser}:${runAsGroup} /autopause
fi fi
ln -fs $(tty) /tmp/terminal-mc
chmod 777 /tmp/terminal-mc
if [[ ${SKIP_NSSWITCH_CONF^^} != TRUE ]]; then if [[ ${SKIP_NSSWITCH_CONF^^} != TRUE ]]; then
echo 'hosts: files dns' > /etc/nsswitch.conf echo 'hosts: files dns' > /etc/nsswitch.conf
fi fi
+8
View File
@@ -49,6 +49,14 @@ function log {
echo "[init] $*" echo "[init] $*"
} }
function logAutopause {
echo "[Autopause loop] $*"
}
function logAutopauseAction {
echo "[$(date -Iseconds)] [Autopause] $*"
}
function normalizeMemSize { function normalizeMemSize {
local scale=1 local scale=1
case ${1,,} in case ${1,,} in