Skip to content

Commit be9d5b8

Browse files
committed
allow some runners to proceed, even if others fail to init
1 parent 461a0bb commit be9d5b8

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

src/ec2_gha/templates/user-script.sh.templ

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ source $$B/runner-common.sh
6969
logger "EC2-GHA: Starting userdata script"
7070
trap 'logger "EC2-GHA: Script failed at line $$LINENO with exit code $$?"' ERR
7171
trap 'terminate_instance "Setup script failed with error on line $$LINENO"' ERR
72+
# Handle watchdog termination signal
73+
trap 'if [ -f $$V-watchdog-terminate ]; then terminate_instance "No runners registered within timeout"; else terminate_instance "Script terminated"; fi' TERM
7274

7375
# Set up registration timeout failsafe - terminate if runner doesn't register in time
7476
REGISTRATION_TIMEOUT="$runner_registration_timeout"
@@ -78,15 +80,21 @@ if ! [[ "$$REGISTRATION_TIMEOUT" =~ ^[0-9]+$$ ]]; then
7880
REGISTRATION_TIMEOUT=300
7981
fi
8082
logger "EC2-GHA: Registration timeout set to $$REGISTRATION_TIMEOUT seconds"
83+
# Create a marker file for watchdog termination request
84+
touch $$V-watchdog-active
8185
(
8286
log "Watchdog: Starting $$REGISTRATION_TIMEOUT second timeout"
8387
sleep $$REGISTRATION_TIMEOUT
8488
if [ ! -f $$V-registered ]; then
8589
log "Watchdog: Registration marker not found after timeout"
86-
terminate_instance "Runner failed to register within $$REGISTRATION_TIMEOUT seconds"
90+
# Signal main process to terminate instead of doing it directly
91+
touch $$V-watchdog-terminate
92+
# Kill the main script process to trigger its ERR trap
93+
kill -TERM $$$$ 2>/dev/null || true
8794
else
8895
log "Watchdog: Registration marker found, exiting normally"
8996
fi
97+
rm -f $$V-watchdog-active
9098
) &
9199
REGISTRATION_WATCHDOG_PID=$$!
92100
log "Watchdog PID: $$REGISTRATION_WATCHDOG_PID"
@@ -333,24 +341,34 @@ done
333341
# Wait for all background jobs to complete
334342
log "Waiting for all runner configurations to complete..."
335343
failed=0
344+
succeeded=0
336345
for i in $${!pids[@]}; do
337346
wait $${pids[$$i]}
338347
if [ -f /tmp/runner-$$i-status ]; then
339348
status=$$(cat /tmp/runner-$$i-status)
340349
rm -f /tmp/runner-$$i-status
341350
if [ "$$status" != "0" ]; then
342351
log_error "Runner $$i configuration failed"
343-
failed=1
352+
failed=$$((failed + 1))
353+
else
354+
succeeded=$$((succeeded + 1))
344355
fi
345356
fi
346357
done
347358

348-
if [ $$failed -ne 0 ]; then
349-
terminate_instance "One or more runners failed to register"
359+
# Allow partial success - only terminate if ALL runners failed
360+
if [ $$succeeded -eq 0 ] && [ $$failed -gt 0 ]; then
361+
terminate_instance "All runners failed to register"
362+
elif [ $$failed -gt 0 ]; then
363+
log "WARNING: $$failed runner(s) failed, but $$succeeded succeeded. Continuing with partial capacity."
350364
fi
351365

352-
log "All runners registered and started"
353-
touch $$V-registered
366+
if [ $$succeeded -gt 0 ]; then
367+
log "$$succeeded runner(s) registered and started successfully"
368+
touch $$V-registered
369+
else
370+
log_error "No runners registered successfully"
371+
fi
354372

355373
# Kill registration watchdog now that runners are registered
356374
if [ -f $$V-watchdog.pid ]; then

0 commit comments

Comments
 (0)