Skip to content

Commit

Permalink
feat: task timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
micdes-pagopa committed Apr 5, 2024
1 parent 8306367 commit 5b44ae7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ RUN useradd github && \

WORKDIR /home/github

COPY killProcess.sh ./killProcess.sh
RUN chmod +x ./killProcess.sh

COPY entrypoint.sh ./entrypoint.sh
RUN chmod +x ./entrypoint.sh

Expand Down
8 changes: 7 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ printf "\tRunner Name: $RUNNER_NAME\n\tWorking Directory: $WORK_DIR\n\tReplace E
if [ "$INTERACTIVE" == "FALSE" ]; then
echo -ne "$REPLACEMENT_POLICY" | . /actions-runner/config.sh --name $RUNNER_NAME --url $GITHUB_REPOSITORY --token $GITHUB_TOKEN --agent $RUNNER_NAME --work $WORK_DIR
else
. /actions-runner/config.sh --name $RUNNER_NAME --url $GITHUB_REPOSITORY --token $GITHUB_TOKEN --agent $RUNNER_NAME --work $WORK_DIR
. /actions-runner/config.sh --name $RUNNER_NAME --url $GITHUB_REPOSITORY --token $GITHUB_TOKEN --agent $RUNNER_NAME --work $WORK_DIR
fi

# Start the runner.
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" &
fi

. /actions-runner/run.sh
11 changes: 11 additions & 0 deletions killProcess.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

sleep $ECS_TASK_MAX_DURATION_SECONDS

PROCESS_TO_FIND=$1
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

kill -9 $PID

0 comments on commit 5b44ae7

Please sign in to comment.