b77f9e2910
This adds the `status-checker` container, which aggregates the statuses of the task containers. This is useful for quickly checking whether AIAP is in a failed or successful state, allowing for early exit during gating or testing. This also prevents the containers from stopping for any reason, allowing for easy debugging. Change-Id: I1571d006fb3c856e4d2bedee0befdccae6082a66
39 lines
1012 B
Bash
Executable File
39 lines
1012 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# wait_for takes a container name and runs until the named container has
|
|
# reported a "SUCCESS" or "FAILURE" status in the "/tmp/status" directory.
|
|
# When the status becomes "SUCCESS" or "FAILURE", the `wait_for` script exits
|
|
# with a corresponding exit code. It can be used to prevent a container from
|
|
# executing until pre-requisite containers have indicated successful
|
|
# completion.
|
|
|
|
container="$1"
|
|
mkdir -p "/tmp/status"
|
|
status_file="/tmp/status/$container"
|
|
if [[ ! -e "$status_file" ]]; then
|
|
# Create the status file to prevent errors when checking its contents
|
|
touch "$status_file"
|
|
fi
|
|
|
|
while true; do
|
|
# Assume we're finished, prove otherwise
|
|
finished=true
|
|
for container in "$@"; do
|
|
if (! grep -q -e "SUCCESS" -e "FAILURE" "$status_file"); then
|
|
printf "Waiting on status from '%s'...\n" "$container"
|
|
finished=false
|
|
sleep 10
|
|
break
|
|
fi
|
|
done
|
|
if $finished; then
|
|
break
|
|
fi
|
|
done
|
|
|
|
if (grep -q "SUCCESS" "$status_file"); then
|
|
exit 0
|
|
else
|
|
exit 1
|
|
fi
|