1
1
#! /bin/bash
2
2
3
- # Validate not sudo
4
- user_id=` id -u`
5
- if [ $user_id -eq 0 -a -z " $RUNNER_ALLOW_RUNASROOT " ]; then
6
- echo " Must not run interactively with sudo"
7
- exit 1
8
- fi
9
-
10
3
# Change directory to the script root directory
11
4
# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
12
5
SOURCE=" ${BASH_SOURCE[0]} "
@@ -17,54 +10,15 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli
17
10
done
18
11
DIR=" $( cd -P " $( dirname " $SOURCE " ) " && pwd ) "
19
12
20
- # Do not "cd $DIR". For localRun, the current directory is expected to be the repo location on disk.
21
-
22
- # Run
23
- shopt -s nocasematch
24
-
25
- safe_sleep () {
26
- if [ ! -x " $( command -v sleep) " ]; then
27
- if [ ! -x " $( command -v ping) " ]; then
28
- COUNT=" 0"
29
- while [[ $COUNT != 5000 ]]; do
30
- echo " SLEEP" > /dev/null
31
- COUNT=$[$COUNT +1]
32
- done
33
- else
34
- ping -c 5 127.0.0.1 > /dev/null
35
- fi
36
- else
37
- sleep 5
38
- fi
39
- }
40
-
13
+ # run the helper process which keep the listener alive
41
14
while : ;
42
15
do
43
- if [[ " $1 " == " localRun" ]]; then
44
- " $DIR " /bin/Runner.Listener $*
45
- else
46
- " $DIR " /bin/Runner.Listener run $*
47
- fi
48
-
16
+ " $DIR " /bin/run-helper.sh $*
49
17
returnCode=$?
50
- if [[ $returnCode == 0 ]]; then
51
- echo " Runner listener exit with 0 return code, stop the service, no retry needed."
52
- exit $returnCode
53
- elif [[ $returnCode == 1 ]]; then
54
- echo " Runner listener exit with terminated error, stop the service, no retry needed."
55
- exit $returnCode
56
- elif [[ $returnCode == 2 ]]; then
57
- echo " Runner listener exit with retryable error, re-launch runner in 5 seconds."
58
- safe_sleep
59
- elif [[ $returnCode == 3 ]]; then
60
- # Sleep 5 seconds to wait for the runner update process finish
61
- echo " Runner listener exit because of updating, re-launch runner in 5 seconds"
62
- safe_sleep
63
- elif [[ $returnCode == 4 ]]; then
64
- # Sleep 5 seconds to wait for the ephemeral runner update process finish
65
- echo " Runner listener exit because of updating, re-launch ephemeral runner in 5 seconds"
66
- safe_sleep
18
+ if [[ $returnCode -ge 2 ]]; then
19
+ echo " Restart runner after it exited with return code '${returnCode} '"
67
20
else
21
+ echo " Exit runner after it exited with return code '${returnCode} '"
68
22
exit $returnCode
69
23
fi
70
24
done
0 commit comments