|
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]}"
|
13 | 6 | while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
14 |
| - DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
15 |
| - SOURCE="$(readlink "$SOURCE")" |
16 |
| - [[ $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 |
| 7 | + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
| 8 | + SOURCE="$(readlink "$SOURCE")" |
| 9 | + [[ $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 |
17 | 10 | done
|
18 | 11 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
19 |
| - |
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 |
| -if [[ "$1" == "localRun" ]]; then |
25 |
| - "$DIR"/bin/Runner.Listener $* |
26 |
| -else |
27 |
| - "$DIR"/bin/Runner.Listener run $* |
28 |
| - |
29 |
| -# Return code 3 means the run once runner received an update message. |
30 |
| -# Sleep 5 seconds to wait for the update process finish |
| 12 | +cp -f run-helper.sh.template run-helper.sh |
| 13 | +# run the helper process which keep the listener alive |
| 14 | +while :; |
| 15 | +do |
| 16 | + "$DIR"/run-helper.sh $* |
31 | 17 | returnCode=$?
|
32 |
| - if [[ $returnCode == 3 ]]; then |
33 |
| - if [ ! -x "$(command -v sleep)" ]; then |
34 |
| - if [ ! -x "$(command -v ping)" ]; then |
35 |
| - COUNT="0" |
36 |
| - while [[ $COUNT != 5000 ]]; do |
37 |
| - echo "SLEEP" > /dev/null |
38 |
| - COUNT=$[$COUNT+1] |
39 |
| - done |
40 |
| - else |
41 |
| - ping -c 5 127.0.0.1 > /dev/null |
42 |
| - fi |
43 |
| - else |
44 |
| - sleep 5 |
45 |
| - fi |
46 |
| - elif [[ $returnCode == 4 ]]; then |
47 |
| - if [ ! -x "$(command -v sleep)" ]; then |
48 |
| - if [ ! -x "$(command -v ping)" ]; then |
49 |
| - COUNT="0" |
50 |
| - while [[ $COUNT != 5000 ]]; do |
51 |
| - echo "SLEEP" > /dev/null |
52 |
| - COUNT=$[$COUNT+1] |
53 |
| - done |
54 |
| - else |
55 |
| - ping -c 5 127.0.0.1 > /dev/null |
56 |
| - fi |
57 |
| - else |
58 |
| - sleep 5 |
59 |
| - fi |
60 |
| - "$DIR"/bin/Runner.Listener run $* |
| 18 | + if [[ $returnCode == 1 ]]; then |
| 19 | + echo "Restarting runner..." |
61 | 20 | else
|
62 |
| - exit $returnCode |
| 21 | + echo "Exiting runner..." |
| 22 | + exit 0 |
63 | 23 | fi
|
64 |
| -fi |
| 24 | +done |
0 commit comments