mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-22 15:02:23 +00:00
Fix wait-for-it script to work with external signals
The wait-for-it script used during tests would setup a timer that would send SIGUSR2 to the parent process after the timer ends. Since node was ignoring additional signals, the timer ending would have no effect after the node process had replaced the start script. However when node has pid != 1, SIGUSR2 default behavior is to terminate the process, meaning the tests would fail after 30 seconds. The script is now updated so the timer is killed once the services are ready for the tests.
This commit is contained in:
parent
6683bca07d
commit
4d74505087
@ -72,21 +72,18 @@ set_abort_timer() {
|
||||
kill -USR2 "$2"
|
||||
}
|
||||
|
||||
# Flag indicating whether the required services are ready
|
||||
ready=0
|
||||
abort_if_not_ready() {
|
||||
# If the timeout is reached and the required services are not ready, it probably
|
||||
# means something went wrong so we terminate the program with an error
|
||||
if [ "${ready}" = "0" ]; then
|
||||
echo "Something happened, failed to start in ${timeout}s" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Trap the signal and start the timer if user timeout is greater than 0
|
||||
if [ "$timeout" -gt 0 ]; then
|
||||
trap 'abort_if_not_ready' USR2
|
||||
set_abort_timer "$timeout" $$ &
|
||||
timer_pid=$!
|
||||
fi
|
||||
|
||||
# Wait for docker
|
||||
@ -110,7 +107,9 @@ if [ "${with_supervisor}" = "1" ]; then
|
||||
done
|
||||
fi
|
||||
|
||||
# Ignore signal if received
|
||||
ready=1
|
||||
# Kill the timer since we are ready to start
|
||||
if [ "$timer_pid" != "" ]; then
|
||||
kill $timer_pid
|
||||
fi
|
||||
|
||||
exec ${cmd}
|
||||
|
Loading…
Reference in New Issue
Block a user