Skip to content

Commit 5a619e0

Browse files
committed
heredoc fixes
1 parent be9d5b8 commit 5a619e0

2 files changed

Lines changed: 393 additions & 244 deletions

File tree

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

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ touch $$V-watchdog-active
8989
log "Watchdog: Registration marker not found after timeout"
9090
# Signal main process to terminate instead of doing it directly
9191
touch $$V-watchdog-terminate
92-
# Kill the main script process to trigger its ERR trap
92+
# Kill the main script process to trigger its TERM trap
9393
kill -TERM $$$$ 2>/dev/null || true
9494
else
9595
log "Watchdog: Registration marker found, exiting normally"
@@ -211,25 +211,23 @@ log "Downloaded runner binary"
211211

212212
# Create job tracking scripts - these are called by GitHub runner hooks
213213
# job-started-hook.sh is called when a job starts
214-
cat > $$B/job-started-hook.sh << 'EOFS'
214+
cat > $$B/job-started-hook.sh << EOFS
215215
#!/bin/bash
216216
exec >> /tmp/job-started-hook.log 2>&1
217-
V="/var/run/github-runner"
218-
RUNNER_IDX="$${RUNNER_INDEX:-0}"
219-
echo "[$$(date)] Runner-$$RUNNER_IDX: ${log_prefix_job_started} $${GITHUB_JOB}"
217+
I="\$${RUNNER_INDEX:-0}"
218+
echo "[\$$(date)] Runner-\$$I: ${log_prefix_job_started} \$${GITHUB_JOB}"
220219
mkdir -p $$V-jobs
221-
echo '{\"status\":\"running\",\"runner\":\"'$$RUNNER_IDX'\"}' > $$V-jobs/$${GITHUB_RUN_ID}-$${GITHUB_JOB}-$$RUNNER_IDX.job
220+
echo '{"status":"running","runner":"'\$$I'"}' > $$V-jobs/\$${GITHUB_RUN_ID}-\$${GITHUB_JOB}-\$$I.job
222221
touch $$V-last-activity $$V-has-run-job
223222
EOFS
224223

225224
# job-completed-hook.sh is called when a job completes
226-
cat > $$B/job-completed-hook.sh << 'EOFC'
225+
cat > $$B/job-completed-hook.sh << EOFC
227226
#!/bin/bash
228227
exec >> /tmp/job-completed-hook.log 2>&1
229-
V="/var/run/github-runner"
230-
RUNNER_IDX="$${RUNNER_INDEX:-0}"
231-
echo "[$$(date)] Runner-$$RUNNER_IDX: ${log_prefix_job_completed} $${GITHUB_JOB}"
232-
rm -f $$V-jobs/$${GITHUB_RUN_ID}-$${GITHUB_JOB}-$$RUNNER_IDX.job
228+
I="\$${RUNNER_INDEX:-0}"
229+
echo "[\$$(date)] Runner-\$$I: ${log_prefix_job_completed} \$${GITHUB_JOB}"
230+
rm -f $$V-jobs/\$${GITHUB_RUN_ID}-\$${GITHUB_JOB}-\$$I.job
233231
touch $$V-last-activity
234232
EOFC
235233

@@ -238,23 +236,22 @@ cat > $$B/check-runner-termination.sh << EOFT
238236
#!/bin/bash
239237
exec >> /tmp/termination-check.log 2>&1
240238
source $$B/runner-common.sh
241-
V="/var/run/github-runner"
242-
A="\\$$V-last-activity"
243-
J="\\$$V-jobs"
244-
H="\\$$V-has-run-job"
245-
[ ! -f "\\$$A" ] && touch "\\$$A"
246-
L=\\$$(stat -c %Y "\\$$A" 2>/dev/null || echo 0)
247-
N=\\$$(date +%s)
248-
I=\\$$((N-L))
249-
[ -f "\\$$H" ] && G=\\$${RUNNER_GRACE_PERIOD:-60} || G=\\$${RUNNER_INITIAL_GRACE_PERIOD:-180}
250-
R=\\$$(grep -l '\"status\":\"running\"' \\$$J/*.job 2>/dev/null | wc -l || echo 0)
251-
if [ \\$$R -eq 0 ] && [ \\$$I -gt \\$$G ]; then
252-
log "TERMINATING: idle \\$$I > grace \\$$G"
239+
A="$$V-last-activity"
240+
J="$$V-jobs"
241+
H="$$V-has-run-job"
242+
[ ! -f "\$$A" ] && touch "\$$A"
243+
L=\$$(stat -c %Y "\$$A" 2>/dev/null || echo 0)
244+
N=\$$(date +%s)
245+
I=\$$((N-L))
246+
[ -f "\$$H" ] && G=\$${RUNNER_GRACE_PERIOD:-60} || G=\$${RUNNER_INITIAL_GRACE_PERIOD:-180}
247+
R=\$$(grep -l '"status":"running"' \$$J/*.job 2>/dev/null | wc -l || echo 0)
248+
if [ \$$R -eq 0 ] && [ \$$I -gt \$$G ]; then
249+
log "TERMINATING: idle \$$I > grace \$$G"
253250
deregister_all_runners
254251
flush_cloudwatch_logs
255252
debug_sleep_and_shutdown
256253
else
257-
[ \\$$R -gt 0 ] && log "\\$$R job(s) running" || log "Idle \\$$I/\\$$G sec"
254+
[ \$$R -gt 0 ] && log "\$$R job(s) running" || log "Idle \$$I/\$$G sec"
258255
fi
259256
EOFT
260257

0 commit comments

Comments
 (0)