Skip to content

Commit 87054ff

Browse files
committed
Working container runner update with run.sh
1 parent 9675941 commit 87054ff

File tree

2 files changed

+44
-38
lines changed

2 files changed

+44
-38
lines changed

src/Misc/layoutroot/run.sh

+43-37
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,60 @@ fi
1111
# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
1212
SOURCE="${BASH_SOURCE[0]}"
1313
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
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
1717
done
1818
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
1919

2020
# Do not "cd $DIR". For localRun, the current directory is expected to be the repo location on disk.
2121

2222
# Run
2323
shopt -s nocasematch
24-
if [[ "$1" == "localRun" ]]; then
25-
"$DIR"/bin/Runner.Listener $*
26-
else
27-
"$DIR"/bin/Runner.Listener run $*
2824

29-
# Return code 3 means the run once runner received an update message.
30-
# Sleep 5 seconds to wait for the update process finish
31-
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
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
5733
else
58-
sleep 5
34+
ping -c 5 127.0.0.1 > /dev/null
5935
fi
36+
else
37+
sleep 5
38+
fi
39+
}
40+
41+
while :;
42+
do
43+
if [[ "$1" == "localRun" ]]; then
44+
"$DIR"/bin/Runner.Listener $*
45+
else
6046
"$DIR"/bin/Runner.Listener run $*
47+
fi
48+
49+
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
6167
else
6268
exit $returnCode
6369
fi
64-
fi
70+
done

src/Runner.Listener/Runner.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ private async Task<int> RunAsync(RunnerSettings settings, bool runOnce = false)
408408
autoUpdateInProgress = true;
409409
var runnerUpdateMessage = JsonUtility.FromString<AgentRefreshMessage>(message.Body);
410410
var selfUpdater = HostContext.GetService<ISelfUpdater>();
411-
selfUpdateTask = selfUpdater.SelfUpdate(runnerUpdateMessage, jobDispatcher, !runOnce && HostContext.StartupType != StartupType.Service, HostContext.RunnerShutdownToken);
411+
selfUpdateTask = selfUpdater.SelfUpdate(runnerUpdateMessage, jobDispatcher, false, HostContext.RunnerShutdownToken);
412412
Trace.Info("Refresh message received, kick-off selfupdate background process.");
413413
}
414414
else

0 commit comments

Comments
 (0)