Skip to content

Commit 47ba120

Browse files
authored
Revert "Make run.sh|cmd handle update without quitting so container… (#1635)
* Revert "Make `run.sh|cmd` handle update without quitting so containers using them as entrypoints don't exit on update (#1494)" d8251bf * update runnerversion as well
1 parent dc8b1b6 commit 47ba120

File tree

7 files changed

+72
-123
lines changed

7 files changed

+72
-123
lines changed

src/Misc/layoutroot/run-helper.cmd.template

-39
This file was deleted.

src/Misc/layoutroot/run-helper.sh.template

-54
This file was deleted.

src/Misc/layoutroot/run.cmd

+16-14
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,21 @@ if defined VERBOSE_ARG (
1313
rem Unblock files in the root of the layout folder. E.g. .cmd files.
1414
powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "$VerbosePreference = %VERBOSE_ARG% ; Get-ChildItem -LiteralPath '%~dp0' | ForEach-Object { Write-Verbose ('Unblock: {0}' -f $_.FullName) ; $_ } | Unblock-File | Out-Null"
1515

16+
if /i "%~1" equ "localRun" (
17+
rem ********************************************************************************
18+
rem Local run.
19+
rem ********************************************************************************
20+
"%~dp0bin\Runner.Listener.exe" %*
21+
) else (
22+
rem ********************************************************************************
23+
rem Run.
24+
rem ********************************************************************************
25+
"%~dp0bin\Runner.Listener.exe" run %*
1626

17-
rem ********************************************************************************
18-
rem Run.
19-
rem ********************************************************************************
20-
21-
:launch_helper
22-
copy run-helper.cmd.template run-helper.cmd /Y
23-
call "%~dp0run-helper.cmd" %*
24-
25-
if %ERRORLEVEL% EQU 1 (
26-
echo "Restarting runner..."
27-
goto :launch_helper
28-
) else (
29-
echo "Exiting runner..."
30-
exit 0
27+
rem Return code 4 means the run once runner received an update message.
28+
rem Sleep 5 seconds to wait for the update process finish and run the runner again.
29+
if ERRORLEVEL 4 (
30+
timeout /t 5 /nobreak > NUL
31+
"%~dp0bin\Runner.Listener.exe" run %*
32+
)
3133
)

src/Misc/layoutroot/run.sh

+53-13
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,64 @@
11
#!/bin/bash
22

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+
310
# Change directory to the script root directory
411
# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
512
SOURCE="${BASH_SOURCE[0]}"
613
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
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
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
1017
done
1118
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
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 $*
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
1731
returnCode=$?
18-
if [[ $returnCode == 1 ]]; then
19-
echo "Restarting runner..."
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 $*
2061
else
21-
echo "Exiting runner..."
22-
exit 0
62+
exit $returnCode
2363
fi
24-
done
64+
fi

src/Runner.Listener/Configuration/ConfigurationManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public RunnerSettings LoadSettings()
5454
Trace.Info(nameof(LoadSettings));
5555
if (!IsConfigured())
5656
{
57-
throw new NonRetryableException("Not configured. Run config.(sh/cmd) to configure the runner.");
57+
throw new InvalidOperationException("Not configured. Run config.(sh/cmd) to configure the runner.");
5858
}
5959

6060
RunnerSettings settings = _store.GetSettings();

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, false, HostContext.RunnerShutdownToken);
411+
selfUpdateTask = selfUpdater.SelfUpdate(runnerUpdateMessage, jobDispatcher, !runOnce && HostContext.StartupType != StartupType.Service, HostContext.RunnerShutdownToken);
412412
Trace.Info("Refresh message received, kick-off selfupdate background process.");
413413
}
414414
else

src/runnerversion

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.287.0
1+
2.287.1

0 commit comments

Comments
 (0)