From d2719fb452a4ae8f181797b161d3eb96d37421e1 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Tue, 12 Feb 2019 18:47:12 +1000 Subject: [PATCH] Add --stopped and --online to wait command --- README.asciidoc | 16 ++++++++++++---- tools/arkmanager | 27 ++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index 7ab017b..74725f3 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -404,14 +404,22 @@ instances. `remove-cronjob `:: 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 ------------------- diff --git a/tools/arkmanager b/tools/arkmanager index b9cca09..dfaeb38 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -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