Add --stopped and --online to wait command

This commit is contained in:
Ben Peddell 2019-02-12 18:47:12 +10:00
parent 784d9f3092
commit d2719fb452
2 changed files with 38 additions and 5 deletions

View File

@ -404,14 +404,22 @@ instances.
`remove-cronjob <command>`::
Removes a cron job previously installed by `install-cronjob`
`wait {--any|--all}`::
Waits until any or all instances are stopped
`wait`::
Waits until any or all instances are stopped or online
Defaults to any stopped
`--any`;;
Waits until any specified instance is stopped
Waits until any specified instance is in specified state
`--all`;;
Waits until all specified instances are stopped
Waits until all specified instances are in specified state
`--stopped`;;
Waits until instances are stopped
`--online`;;
Waits until instances are online
Configuration files
-------------------

View File

@ -3056,15 +3056,27 @@ printStatus(){
doWait(){
local waitall=
local waitany=
local waitonline=
local waitstopped=
declare -A pidfiles
for arg in "$@"; do
case "$arg" in
--all) waitall=1; ;;
--any) waitany=1; ;;
--online) waitonline=1; ;;
--stopped) waitstopped=1; ;;
esac
done
if [[ -z "${waitany}" && -z "${waitall}" ]]; then
waitany=1
fi
if [[ -z "${waitonline}" && -z "${waitstopped}" ]]; then
waitstopped=1
fi
for instance in "${instances[@]}"; do
pidfile="$(useConfig "$instance"; echo "${arkserverroot}/${arkmanagerpidfile}")"
pidfiles[$instance]="$pidfile"
@ -3077,18 +3089,31 @@ doWait(){
while sleep 5; do
anyrunning=0
allrunning=1
anyonline=0
allonline=1
for instance in "${instances[@]}"; do
pidfile="${pidfiles[$instance]}"
if [ -f "${pidfile}" ]; then
pid="$(<"${pidfile}")"
if kill -0 "${pid}"; then
anyrunning=1
if [ -n "$waitonline" ]; then
if (useConfig "$instance"; isTheServerOnline); then
anyonline=1
else
allonline=0
fi
fi
else
allrunning=0
allonline=0
fi
fi
done
if [[ ( "${waitall}" == 1 && "${anyrunning}" == 0 ) || ( "${waitany}" == 1 && "${allrunning}" == 0 ) ]]; then
if [[ ( "${waitstopped}" == 1 && "${waitall}" == 1 && "${anyrunning}" == 0 ) ||
( "${waitstopped}" == 1 && "${waitany}" == 1 && "${allrunning}" == 0 ) ||
( "${waitonline}" == 1 && "${waitall}" == 1 && "${allonline}" == 1 ) ||
( "${waitonline}" == 1 && "${waitany}" == 1 && "${anyonline}" == 1 ) ]]; then
return
fi
done