Skip to content

Commit

Permalink
feat: graceful task timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
micdes-pagopa committed Apr 12, 2024
1 parent 5b44ae7 commit 00d5c5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ printf "Executing GitHub Runner for $GITHUB_REPOSITORY\n"

if [[ -n $ECS_TASK_MAX_DURATION_SECONDS ]]; then
echo "This task will stop after ${ECS_TASK_MAX_DURATION_SECONDS} seconds"
. /home/github/killProcess.sh "run.sh" &
. /home/github/killProcess.sh "/actions-runner/run.sh" &
fi

. /actions-runner/run.sh
bash /actions-runner/run.sh
8 changes: 7 additions & 1 deletion killProcess.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
sleep $ECS_TASK_MAX_DURATION_SECONDS

PROCESS_TO_FIND=$1
PROCESS_TO_KILL=$(ps -eux | grep -v "grep" | grep "$PROCESS_TO_FIND" | tr -s ' ')
PID_TO_KILL=$(ps -eux | grep -v "grep" | grep "$PROCESS_TO_FIND" | tr -s ' ' | cut -d ' ' -f 2)

echo "Task timeout" >&2
echo "Stop process $PROCESS_TO_FIND with PID: $PID_TO_KILL" >&2
echo "Process name: $PROCESS_TO_KILL"

kill -9 $PID
# Graceful stop
kill -s TERM $PID_TO_KILL
sleep 30

kill -9 $PID_TO_KILL

0 comments on commit 00d5c5d

Please sign in to comment.