Skip to content

Commit

Permalink
Use presence of token file during termination
Browse files Browse the repository at this point in the history
When the token file is present, remove through creating a termination
file. Otherwise, kill the entire process tree directly, as the runner
has not (yet) been registered at GitHub.
  • Loading branch information
efrecon committed Feb 21, 2024
1 parent f9a97d4 commit 7412f21
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ kill_tree() {
verbose "Killing process tree for $1"
for pid in $(ps_tree "$1"|tac); do
debug "Killing process $pid"
kill -s "${2:-TERM}" -- "$pid"
kill -s "${2:-TERM}" -- "$pid" 2>/dev/null
done
}

Expand Down
21 changes: 16 additions & 5 deletions runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,24 @@ vm_delete() {
}

vm_terminate() {
if [ -n "$RUNNER_ENVIRONMENT" ] && [ -n "${RUNNER_SECRET:-}" ]; then
printf %s\\n "$RUNNER_SECRET" > "${RUNNER_ENVIRONMENT}/${RUNNER_ID}.trm"
if [ "$RUNNER_PID" ]; then
if [ -n "$RUNNER_ENVIRONMENT" ]; then
if [ -f "${RUNNER_ENVIRONMENT}/${RUNNER_ID}.tkn" ]; then
if [ -n "${RUNNER_SECRET:-}" ]; then
verbose "Requesting termination via ${RUNNER_ENVIRONMENT}/${RUNNER_ID}.trm"
printf %s\\n "$RUNNER_SECRET" > "${RUNNER_ENVIRONMENT}/${RUNNER_ID}.trm"
elif [ -n "$RUNNER_PID" ]; then
kill_tree "$RUNNER_PID"
fi
if [ "$RUNNER_PID" ]; then
# shellcheck disable=SC2046 # We want to wait for all children
waitpid $(ps_tree "$RUNNER_PID"|tac)
else
warning "No PID to wait for"
fi
elif [ -n "$RUNNER_PID" ]; then
kill_tree "$RUNNER_PID"
# shellcheck disable=SC2046 # We want to wait for all children
waitpid $(ps_tree "$RUNNER_PID"|tac)
else
warning "No PID to wait for"
fi
elif [ -n "$RUNNER_PID" ]; then
kill_tree "$RUNNER_PID"
Expand Down

0 comments on commit 7412f21

Please sign in to comment.