From 6b0c08ab092804034adc643c203151e66aa6e44c Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 7 Aug 2015 23:05:45 +1000 Subject: [PATCH 1/3] Add option to warn players before update --- tools/arkmanager | 57 ++++++++++++++++++++++++++++++++++++++++++++ tools/arkmanager.cfg | 1 + 2 files changed, 58 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index 0eaef0d..b82f720 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -162,6 +162,14 @@ doBroadcast(){ rconcmd "broadcast $1" >/dev/null } +# +# Broadcast message with echo +# +doBroadcastWithEcho(){ + echo "$1" + doBroadcast "$1" +} + # # Check if a new version is available but not apply it # @@ -442,6 +450,51 @@ doSafeUpdate(){ fi } +# +# Waits for a configurable number of minutes before updating the server +# +doWarnUpdate(){ + cd "$arkserverroot" + + if isUpdateNeeded; then + local pid=`getServerPID` + if [ -n "$pid" ]; then + local warnminutes=$(( arkwarnminutes )) + if (( warnminutes == 0 )); then + warnminutes=60 + fi + + local warnintervals=( 90 60 45 30 20 15 10 5 4 3 2 1 ) + + for warninterval in "${warnintervals[@]}"; do + if [ "`getServerPID`" != "$pid" ]; then + echo "Server has stopped. Aborting update" + fi + if (( arkwarnminutes > warninterval )); then + doBroadcastWithEcho "This ARK server will shutdown for an update in $warnminutes minutes" + sleep $(( warnminutes - warninterval ))m + warnminutes=$warninterval + fi + done + + local warnseconds=90 + warnintervals=( 60 45 30 20 15 10 5 0 ) + for warninterval in "${warnintervals[@]}"; do + if [ "`getServerPID`" != "$pid" ]; then + echo "Server has stopped. Aborting update" + fi + doBroadcastWithEcho "This ARK server will shutdown for an update in $warnseconds seconds" + sleep $(( warnseconds - warninterval ))s + done + fi + + if [ "`getServerPID`" != "$pid" ]; then + echo "Server has stopped. Aborting update" + fi + doUpdate + fi +} + # # Copies server state to a backup directory # @@ -646,6 +699,9 @@ while true; do elif [ "$2" == "--safe" ]; then doSafeUpdate shift + elif [ "$2" == "--warn" ]; then + doWarnUpdate + shift else doUpdate fi @@ -693,6 +749,7 @@ while true; do echo "update Check for a new ARK server version, if needed, stops the server, updates it, and starts it again" echo "update --force Apply update without check the current version" echo "update --safe Wait for server to perform world save and update." + echo "update --warn Warn players before updating server" echo "upgrade Check for a new ARK Server Tools version and upgrades it if needed" echo "useconfig Use the configuration overrides in the specified config name or file" exit 1 diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index 394230a..4525da0 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -10,6 +10,7 @@ steamcmd_appinfocache="/home/steam/Steam/appcache/appinfo.vdf" # cache of t arkserverroot="/home/steam/ARK" # path of your ARK server files (default ~/ARK) arkserverexec="ShooterGame/Binaries/Linux/ShooterGameServer" # name of ARK server executable arkbackupdir="/home/steam/ARK-Backups" # path to backup directory +arkwarnminutes="60" # number of minutes to warn players when using update --warn # ARK server options - use ark_= # comment out these values if you want to define them From c0793a818632e3507d561db24a97aec82793f330 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Mon, 14 Sep 2015 17:02:07 +1000 Subject: [PATCH 2/3] Make warning broadcast message customisable --- tools/arkmanager | 17 +++++++++++++++-- tools/arkmanager.cfg | 5 +++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 65b02c1..df92d7d 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -554,6 +554,7 @@ doWarnUpdate(){ if isUpdateNeeded; then local pid=`getServerPID` if [ -n "$pid" ]; then + local warnmsg local warnminutes=$(( arkwarnminutes )) if (( warnminutes == 0 )); then warnminutes=60 @@ -564,9 +565,15 @@ doWarnUpdate(){ for warninterval in "${warnintervals[@]}"; do if [ "`getServerPID`" != "$pid" ]; then echo "Server has stopped. Aborting update" + return 1 fi if (( arkwarnminutes > warninterval )); then - doBroadcastWithEcho "This ARK server will shutdown for an update in $warnminutes minutes" + if [ -n "$msgWarnUpdateMinutes" ]; then + warnmsg="$(printf "$msgWarnUpdateMinutes" "$warnminutes")" + else + warnmsg="$(printf "This ARK server will shutdown for an update in %d minutes" "$warnminutes")" + fi + doBroadcastWithEcho "$warnmsg" sleep $(( warnminutes - warninterval ))m warnminutes=$warninterval fi @@ -577,8 +584,14 @@ doWarnUpdate(){ for warninterval in "${warnintervals[@]}"; do if [ "`getServerPID`" != "$pid" ]; then echo "Server has stopped. Aborting update" + return 1 fi - doBroadcastWithEcho "This ARK server will shutdown for an update in $warnseconds seconds" + if [ -n "$msgWarnUpdateMinutes" ]; then + warnmsg="$(printf "$msgWarnUpdateMinutes" "$warnminutes")" + else + warnmsg="$(printf "This ARK server will shutdown for an update in %d seconds" "$warnseconds")" + fi + doBroadcastWithEcho "$warnmsg" sleep $(( warnseconds - warninterval ))s done fi diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index 8c7f165..6d55038 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -12,6 +12,11 @@ arkserverexec="ShooterGame/Binaries/Linux/ShooterGameServer" # name of AR arkbackupdir="/home/steam/ARK-Backups" # path to backup directory arkwarnminutes="60" # number of minutes to warn players when using update --warn +# Update warning messages +# Modify as desired, putting the %d replacement operator where the number belongs +msgWarnUpdateMinutes="This ARK server will shutdown for an update in %d minutes" +msgWarnUpdateSeconds="This ARK server will shutdown for an update in %d seconds" + # ARK server options - use ark_= # comment out these values if you want to define them # inside your GameUserSettings.ini file From b0e41d088f1142412f705852842d0add06e65ce7 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Mon, 14 Sep 2015 17:17:15 +1000 Subject: [PATCH 3/3] Add update --warn to readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 9cafe98..63b194c 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,9 @@ Apply update without check the current version #### arkmanager update --safe Waits for server to perform world save and then updates. +#### arkmanager update --warn +Warns the players for a configurable amount of time before updating. Should be suitable for adding to a cron job. + #### arkmanager status Get the status of the server. Show if the process is running, if the server is up and the current version number