Merge pull request #326 from klightspeed/1.5-dev#restarttimer

Add option to warn on shutdown and restart
This commit is contained in:
Fez Vrasta 2015-12-11 14:49:40 +01:00
commit dd41a24a3c
2 changed files with 103 additions and 35 deletions

View File

@ -682,6 +682,9 @@ doStartAll(){
# #
doStop() { doStop() {
if isTheServerRunning; then if isTheServerRunning; then
if [ " $* " =~ " --warn " ]; then
doWarn "$1"
fi
tput sc tput sc
echo "Stopping server..." echo "Stopping server..."
echo "`timestamp`: stopping" >> "$logdir/$arkmanagerLog" echo "`timestamp`: stopping" >> "$logdir/$arkmanagerLog"
@ -758,9 +761,47 @@ doInstall() {
# #
# Waits for a configurable number of minutes before updating the server # Waits for a configurable number of minutes before updating the server
# #
doUpdateWarn(){ doWarn(){
cd "$arkserverroot" cd "$arkserverroot"
local warnmsgmin
local warnmsgsec
if [ "$1" == "update" ]; then
if [ -n "$msgWarnUpdateMinutes" ]; then
warnmsgmin="$msgWarnUpdateMinutes"
else
warnmsgmin="This ARK server will shutdown for an update in %d minutes"
fi
if [ -n "$msgWarnUpdateSeconds" ]; then
warnmsgsec="$msgWarnUpdateSeconds"
else
warnmsgsec="This ARK server will shutdown for an update in %d seconds"
fi
elif [ "$1" == "restart" ]; then
if [ -n "$msgWarnRestartMinutes" ]; then
warnmsgmin="$msgWarnRestartMinutes"
else
warnmsgmin="This ARK server will shutdown for a restart in %d minutes"
fi
if [ -n "$msgWarnRestartSeconds" ]; then
warnmsgsec="$msgWarnRestartSeconds"
else
warnmsgsec="This ARK server will shutdown for a restart in %d seconds"
fi
else
if [ -n "$msgWarnShutdownMinutes" ]; then
warnmsgmin="$msgWarnShutdownMinutes"
else
warnmsgmin="This ARK server will shutdown in %d minutes"
fi
if [ -n "$msgWarnShutdownSeconds" ]; then
warnmsgsec="$msgWarnShutdownSeconds"
else
warnmsgsec="This ARK server will shutdown in %d seconds"
fi
fi
local pid=`getServerPID` local pid=`getServerPID`
local sleeppid local sleeppid
if [ -n "$pid" ]; then if [ -n "$pid" ]; then
@ -774,22 +815,18 @@ doUpdateWarn(){
for warninterval in "${warnintervals[@]}"; do for warninterval in "${warnintervals[@]}"; do
if [ "`getServerPID`" != "$pid" ]; then if [ "`getServerPID`" != "$pid" ]; then
echo "Server has stopped. Aborting update" echo "Server has stopped. Aborting $1"
return 1 return 1
fi fi
if (( warnminutes > warninterval )); then if (( warnminutes > warninterval )); then
sleep 1m & sleep 1m &
sleeppid=$! sleeppid=$!
if [ -n "$msgWarnUpdateMinutes" ]; then warnmsg="$(printf "$warnmsgmin" "$warnminutes")"
warnmsg="$(printf "$msgWarnUpdateMinutes" "$warnminutes")"
else
warnmsg="$(printf "This ARK server will shutdown for an update in %d minutes" "$warnminutes")"
fi
doBroadcastWithEcho "$warnmsg" doBroadcastWithEcho "$warnmsg"
for (( min = warnminutes - 1; min >= warninterval; min-- )); do for (( min = warnminutes - 1; min >= warninterval; min-- )); do
numplayers=$(numPlayersConnected) numplayers=$(numPlayersConnected)
if (( numplayers + 0 == 0 )); then if (( numplayers + 0 == 0 )); then
echo "Nobody is connected. Updating immediately" echo "Nobody is connected. Shutting down immediately"
return 0 return 0
fi fi
wait $sleeppid wait $sleeppid
@ -811,16 +848,12 @@ doUpdateWarn(){
echo "Server has stopped. Aborting update" echo "Server has stopped. Aborting update"
return 1 return 1
fi fi
if [ -n "$msgWarnUpdateSeconds" ]; then warnmsg="$(printf "$warnmsgsec" "$warnseconds")"
warnmsg="$(printf "$msgWarnUpdateSeconds" "$warnseconds")"
else
warnmsg="$(printf "This ARK server will shutdown for an update in %d seconds" "$warnseconds")"
fi
doBroadcastWithEcho "$warnmsg" doBroadcastWithEcho "$warnmsg"
if (( warnseconds >= 20 )); then if (( warnseconds >= 20 )); then
numplayers=$(numPlayersConnected) numplayers=$(numPlayersConnected)
if (( numplayers + 0 == 0 )); then if (( numplayers + 0 == 0 )); then
echo "Nobody is connected. Updating immediately" echo "Nobody is connected. Shutting down immediately"
return 0 return 0
fi fi
fi fi
@ -830,7 +863,7 @@ doUpdateWarn(){
fi fi
if [ "`getServerPID`" != "$pid" ]; then if [ "`getServerPID`" != "$pid" ]; then
echo "Server has stopped. Aborting update" echo "Server has stopped. Aborting $1"
return 1 return 1
fi fi
@ -952,7 +985,7 @@ doUpdate() {
done done
echo "`timestamp`: Save file newer than 1 minute. Performing an update." >> "$logdir/update.log" echo "`timestamp`: Save file newer than 1 minute. Performing an update." >> "$logdir/update.log"
elif [ "$updatetype" == "warn" ]; then elif [ "$updatetype" == "warn" ]; then
if ! doUpdateWarn; then if ! doWarn update; then
return 1 return 1
fi fi
elif [ "$updatetype" == "ifempty" ]; then elif [ "$updatetype" == "ifempty" ]; then
@ -1456,12 +1489,51 @@ useConfig() {
checkConfig checkConfig
while true; do while true; do
case "$1" in options=( )
args=( )
command="$1"
shift
nrarg=0
# get the number of arguments for commands that take arguments
case "$command" in
installmod) nrarg=1; ;;
broadcast) nrarg=1; ;;
rconcmd) nrarg=1; ;;
useconfig) nrarg=1; ;;
esac
# Enumerate the options and arguments
while [ $# -ne 0 ]; do
case "$1" in
--)
shift
break
;;
--args)
nrarg=$#
;;
--*)
options+=( "$1" )
;;
*)
if [ $nrarg -gt 0 ]; then
args+=( "$1" )
(( nrarg-- ))
else
break
fi
;;
esac
shift
done
case "$command" in
run) run)
doRun doRun
;; ;;
start) start)
if [ "$2" == "--all" ]; then if [ " ${options[*]} " =~ " --all " ]; then
doStartAll doStartAll
shift shift
else else
@ -1469,22 +1541,22 @@ while true; do
fi fi
;; ;;
stop) stop)
if [ "$2" == "--all" ]; then if [ " ${options[*]} " =~ " --all " ]; then
doStopAll doStopAll
shift shift
else else
doStop doStop stop "${options[@]}"
fi fi
;; ;;
restart) restart)
if [ "$2" == "--all" ]; then if [ " ${options[*]} " =~ " --all " ]; then
doStopAll doStopAll
else else
doStop doStop restart "${options[@]}"
fi fi
echo "`timestamp`: stop" >> "$logdir/$arkmanagerLog" echo "`timestamp`: stop" >> "$logdir/$arkmanagerLog"
sleep 1 sleep 1
if [ "$2" == "--all" ]; then if [ " ${options[*]} " =~ " --all " ]; then
doStartAll doStartAll
shift shift
else else
@ -1497,34 +1569,27 @@ while true; do
doInstall doInstall
;; ;;
update) update)
args=() doUpdate "${options[@]}"
while [[ "$2" =~ ^-- ]]; do
args=( "${args[@]}" "$2" )
shift
done
doUpdate "${args[@]}"
;; ;;
checkupdate) checkupdate)
checkForUpdate checkForUpdate
;; ;;
installmod) installmod)
doInstallMod "$2" doInstallMod "${args[@]}"
shift shift
;; ;;
backup) backup)
doBackup doBackup
;; ;;
broadcast) broadcast)
doBroadcast "$2" doBroadcast "${args[@]}"
shift shift
;; ;;
saveworld) saveworld)
doSaveWorld doSaveWorld
;; ;;
rconcmd) rconcmd)
rconcmd "$2" rconcmd "${args[@]}"
shift shift
;; ;;
status) status)
@ -1597,7 +1662,6 @@ while true; do
;; ;;
esac esac
status=$? status=$?
shift
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
break break
fi fi

View File

@ -24,6 +24,10 @@ arkTimeToKeepBackupFiles="10" #Set to Auto
# Modify as desired, putting the %d replacement operator where the number belongs # Modify as desired, putting the %d replacement operator where the number belongs
msgWarnUpdateMinutes="This ARK server will shutdown for an update in %d minutes" msgWarnUpdateMinutes="This ARK server will shutdown for an update in %d minutes"
msgWarnUpdateSeconds="This ARK server will shutdown for an update in %d seconds" msgWarnUpdateSeconds="This ARK server will shutdown for an update in %d seconds"
msgWarnRestartMinutes="This ARK server will shutdown for a restart in %d minutes"
msgWarnRestartSeconds="This ARK server will shutdown for a restart in %d seconds"
msgWarnShutdownMinutes="This ARK server will shutdown in %d minutes"
msgWarnShutdownSeconds="This ARK server will shutdown in %d seconds"
# ARK server options - use ark_<optionname>=<value> # ARK server options - use ark_<optionname>=<value>
# comment out these values if you want to define them # comment out these values if you want to define them