mirror of
https://github.com/eliasstepanik/ark-ac-server-tools.git
synced 2026-01-26 16:28:28 +00:00
Add wait command
This commit is contained in:
parent
76e71f3c5a
commit
9cfb38cc2d
@ -404,6 +404,15 @@ instances.
|
|||||||
`remove-cronjob <command>`::
|
`remove-cronjob <command>`::
|
||||||
Removes a cron job previously installed by `install-cronjob`
|
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
|
Configuration files
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
|||||||
@ -3053,6 +3053,48 @@ printStatus(){
|
|||||||
fi
|
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(){
|
getAllInstanceNames(){
|
||||||
declare -A instancenames
|
declare -A instancenames
|
||||||
if [ -n "${defaultinstance}" ]; then
|
if [ -n "${defaultinstance}" ]; then
|
||||||
@ -3492,6 +3534,14 @@ main(){
|
|||||||
instances=( $(getAllInstanceNames) )
|
instances=( $(getAllInstanceNames) )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Handle wait command specially
|
||||||
|
case "$command" in
|
||||||
|
wait)
|
||||||
|
doWait "${options[@]}"
|
||||||
|
continue
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
# Run the command for each instance requested
|
# Run the command for each instance requested
|
||||||
for instance in "${instances[@]}"; do
|
for instance in "${instances[@]}"; do
|
||||||
(
|
(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user