Add wait command

This commit is contained in:
Ben Peddell 2019-02-06 23:41:12 +10:00
parent 76e71f3c5a
commit 9cfb38cc2d
2 changed files with 59 additions and 0 deletions

View File

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

View File

@ -3053,6 +3053,48 @@ printStatus(){
fi
}
doWait(){
local waitall=
local waitany=
declare -A pidfiles
for arg in "$@"; do
case "$arg" in
--all) waitall=1; ;;
--any) waitany=1; ;;
esac
done
for instance in "${instances[@]}"; do
pidfile="$(useConfig "$instance"; echo "${arkserverroot}/${arkmanagerpidfile}")"
pidfiles[$instance]="$pidfile"
done
(
trap exit INT
trap exit TERM
while sleep 5; do
anyrunning=0
allrunning=1
for instance in "${instances[@]}"; do
pidfile="${pidfiles[$instance]}"
if [ -f "${pidfile}" ]; then
pid="$(<"${pidfile}")"
if kill -0 "${pid}"; then
anyrunning=1
else
allrunning=0
fi
fi
done
if [[ ( "${waitall}" == 1 && "${anyrunning}" == 0 ) || ( "${waitany}" == 1 && "${allrunning}" == 0 ) ]]; then
return
fi
done
)
}
getAllInstanceNames(){
declare -A instancenames
if [ -n "${defaultinstance}" ]; then
@ -3492,6 +3534,14 @@ main(){
instances=( $(getAllInstanceNames) )
fi
# Handle wait command specially
case "$command" in
wait)
doWait "${options[@]}"
continue
;;
esac
# Run the command for each instance requested
for instance in "${instances[@]}"; do
(