2022-02-02 11:16:01 +01:00
#!/bin/bash
# Validate not sudo
user_id = ` id -u`
if [ $user_id -eq 0 -a -z " $RUNNER_ALLOW_RUNASROOT " ] ; then
echo "Must not run interactively with sudo"
exit 1
fi
# Run
shopt -s nocasematch
2022-02-02 12:08:35 +01:00
SOURCE = " ${ BASH_SOURCE [0] } "
while [ -h " $SOURCE " ] ; do # resolve $SOURCE until the file is no longer a symlink
DIR = " $( cd -P " $( dirname " $SOURCE " ) " && pwd ) "
SOURCE = " $( readlink " $SOURCE " ) "
[ [ $SOURCE != /* ] ] && SOURCE = " $DIR / $SOURCE " # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR = " $( cd -P " $( dirname " $SOURCE " ) " && pwd ) "
2022-08-08 23:37:43 +02:00
2023-02-15 16:05:36 -05:00
# Wait for docker to start
if [ ! -z " $RUNNER_WAIT_FOR_DOCKER_IN_SECONDS " ] ; then
if [ " $RUNNER_WAIT_FOR_DOCKER_IN_SECONDS " -gt 0 ] ; then
echo "Waiting for docker to be ready."
for i in $( seq " $RUNNER_WAIT_FOR_DOCKER_IN_SECONDS " ) ; do
if docker ps > /dev/null 2>& 1; then
echo "Docker is ready."
break
fi
" $DIR " /safe_sleep.sh 1
done
fi
fi
2022-08-08 23:37:43 +02:00
updateFile = "update.finished"
2022-02-02 12:08:35 +01:00
" $DIR " /bin/Runner.Listener run $*
2022-02-02 11:16:01 +01:00
returnCode = $?
if [ [ $returnCode = = 0 ] ] ; then
echo "Runner listener exit with 0 return code, stop the service, no retry needed."
exit 0
2026-03-13 19:16:31 +01:00
elif [ [ " $ACTIONS_RUNNER_RETURN_VERSION_DEPRECATED_EXIT_CODE " = = "1" && $returnCode -eq 7 ] ] ; then
echo " Runner listener exit with deprecated version exit code: ${ returnCode } . "
exit " $returnCode "
2022-02-02 11:16:01 +01:00
elif [ [ $returnCode = = 1 ] ] ; then
echo "Runner listener exit with terminated error, stop the service, no retry needed."
exit 0
elif [ [ $returnCode = = 2 ] ] ; then
echo "Runner listener exit with retryable error, re-launch runner in 5 seconds."
2022-03-01 14:08:52 +01:00
" $DIR " /safe_sleep.sh 5
2022-02-24 21:10:52 +01:00
exit 2
2022-02-02 11:16:01 +01:00
elif [ [ $returnCode = = 3 ] ] ; then
2022-08-08 23:37:43 +02:00
# Wait for 30 seconds or for flag file to exists for the runner update process finish
echo "Runner listener exit because of updating, re-launch runner after successful update"
2022-08-09 16:50:52 +02:00
for i in { 0..30} ; do
2022-08-08 23:37:43 +02:00
if test -f " $updateFile " ; then
echo "Update finished successfully."
rm " $updateFile "
break
fi
" $DIR " /safe_sleep.sh 1
done
2022-02-24 21:10:52 +01:00
exit 2
2022-02-02 11:16:01 +01:00
elif [ [ $returnCode = = 4 ] ] ; then
2022-08-08 23:37:43 +02:00
# Wait for 30 seconds or for flag file to exists for the ephemeral runner update process finish
echo "Runner listener exit because of updating, re-launch runner after successful update"
2022-08-09 16:50:52 +02:00
for i in { 0..30} ; do
2022-08-08 23:37:43 +02:00
if test -f " $updateFile " ; then
echo "Update finished successfully."
rm " $updateFile "
break
fi
" $DIR " /safe_sleep.sh 1
done
2022-02-24 21:10:52 +01:00
exit 2
2024-03-27 14:49:58 -04:00
elif [ [ $returnCode = = 5 ] ] ; then
echo "Runner listener exit with Session Conflict error, stop the service, no retry needed."
exit 0
2022-02-02 11:16:01 +01:00
else
echo " Exiting with unknown error code: ${ returnCode } "
exit 0
fi