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

View File

@ -24,6 +24,10 @@ arkTimeToKeepBackupFiles="10" #Set to Auto
# 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"
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>
# comment out these values if you want to define them