Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0f5f30b

Browse files
authored
fix: make agent scripts easier to troubleshoot (#2922)
- Adds distinct exit statuses to the bootstrap scripts- Makes the bootstrap scripts loop forever trying to download the coder agent- Surfaces and logs the status codes returned by the download tool
1 parent6f34cbf commit0f5f30b

File tree

5 files changed

+93
-20
lines changed

5 files changed

+93
-20
lines changed
Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
#!/usr/bin/env sh
22
set -eux pipefail
3-
trap"echo === Agent script exited with non-zero code. Sleeping 24h to preserve logs... && sleep 86400" EXIT
3+
# Sleep for a good long while before exiting.
4+
# This is to allow folks to exec into a failed workspace and poke around to
5+
# troubleshoot.
6+
waitonexit() {
7+
echo"=== Agent script exited with non-zero code. Sleeping 24h to preserve logs..."
8+
sleep 86400
9+
}
10+
trap waitonexit EXIT
411
BINARY_DIR=$(mktemp -d -t coder.XXXXXX)
512
BINARY_NAME=coder
13+
BINARY_URL=${ACCESS_URL}bin/coder-darwin-${ARCH}
614
cd"$BINARY_DIR"
7-
curl -fsSL --compressed"${ACCESS_URL}bin/coder-darwin-${ARCH}" -o"${BINARY_NAME}"
8-
chmod +x$BINARY_NAME
15+
# Attempt to download the coder agent.
16+
# This could fail for a number of reasons, many of which are likely transient.
17+
# So just keep trying!
18+
while:;do
19+
curl -fsSL --compressed"${BINARY_URL}" -o"${BINARY_NAME}"&&break
20+
status=$?
21+
echo"error: failed to download coder agent using curl"
22+
echo"curl exit code:${status}"
23+
echo"Trying again in 30 seconds..."
24+
sleep 30
25+
done
26+
27+
if! chmod +x$BINARY_NAME;then
28+
echo"Failed to make$BINARY_NAME executable"
29+
exit 1
30+
fi
31+
932
export CODER_AGENT_AUTH="${AUTH_TYPE}"
1033
export CODER_AGENT_URL="${ACCESS_URL}"
1134
exec ./$BINARY_NAME agent
Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
11
#!/usr/bin/env sh
22
set -eux pipefail
3-
trap"echo === Agent script exited with non-zero code. Sleeping 24h to preserve logs... && sleep 86400" EXIT
3+
# Sleep for a good long while before exiting.
4+
# This is to allow folks to exec into a failed workspace and poke around to
5+
# troubleshoot.
6+
waitonexit() {
7+
echo"=== Agent script exited with non-zero code. Sleeping 24h to preserve logs..."
8+
sleep 86400
9+
}
10+
trap waitonexit EXIT
411
BINARY_DIR=$(mktemp -d -t coder.XXXXXX)
512
BINARY_NAME=coder
613
BINARY_URL=${ACCESS_URL}bin/coder-linux-${ARCH}
714
cd"$BINARY_DIR"
8-
ifcommand -v curl>/dev/null2>&1;then
9-
curl -fsSL --compressed"${BINARY_URL}" -o"${BINARY_NAME}"
10-
elifcommand -v wget>/dev/null2>&1;then
11-
wget -q"${BINARY_URL}" -O"${BINARY_NAME}"
12-
elifcommand -v busybox>/dev/null2>&1;then
13-
busybox wget -q"${BINARY_URL}" -O"${BINARY_NAME}"
14-
else
15-
echo"error: no download tool found, please install curl, wget or busybox wget"
15+
# Attempt to download the coder agent.
16+
# This could fail for a number of reasons, many of which are likely transient.
17+
# So just keep trying!
18+
while:;do
19+
# Try a number of different download tools, as we don't know what we'll
20+
# have available
21+
status=""
22+
ifcommand -v curl>/dev/null2>&1;then
23+
curl -fsSL --compressed"${BINARY_URL}" -o"${BINARY_NAME}"&&break
24+
status=$?
25+
elifcommand -v wget>/dev/null2>&1;then
26+
wget -q"${BINARY_URL}" -O"${BINARY_NAME}"&&break
27+
status=$?
28+
elifcommand -v busybox>/dev/null2>&1;then
29+
busybox wget -q"${BINARY_URL}" -O"${BINARY_NAME}"&&break
30+
status=$?
31+
else
32+
echo"error: no download tool found, please install curl, wget or busybox wget"
33+
exit 127
34+
fi
35+
echo"error: failed to download coder agent"
36+
echo" command returned:${status}"
37+
echo"Trying again in 30 seconds..."
38+
sleep 30
39+
done
40+
41+
if! chmod +x$BINARY_NAME;then
42+
echo"Failed to make$BINARY_NAME executable"
1643
exit 1
1744
fi
18-
chmod +x$BINARY_NAME
45+
1946
export CODER_AGENT_AUTH="${AUTH_TYPE}"
2047
export CODER_AGENT_URL="${ACCESS_URL}"
2148
exec ./$BINARY_NAME agent

‎provisionersdk/scripts/bootstrap_windows.ps1

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
1-
# On Windows, VS Code Remote requires a parent process of the
2-
# executing shell to be named "sshd", otherwise it fails. See:
3-
# https://github.com/microsoft/vscode-remote-release/issues/5699
4-
$ProgressPreference="SilentlyContinue"
5-
Invoke-WebRequest-Uri${ACCESS_URL}bin/coder-windows-${ARCH}.exe-OutFile$env:TEMP\sshd.exe
1+
# Sleep for a while in case the underlying provider deletes the resource on error.
2+
trap {
3+
Write-Error'=== Agent script exited with non-zero code. Sleeping 24h to preserve logs...'
4+
Start-Sleep-Seconds86400
5+
}
6+
7+
# Attempt to download the coder agent.
8+
# This could fail for a number of reasons, many of which are likely transient.
9+
# So just keep trying!
10+
while ($true) {
11+
try {
12+
$ProgressPreference="SilentlyContinue"
13+
# On Windows, VS Code Remote requires a parent process of the
14+
# executing shell to be named "sshd", otherwise it fails. See:
15+
# https://github.com/microsoft/vscode-remote-release/issues/5699
16+
$BINARY_URL="${ACCESS_URL}/bin/coder-windows-${ARCH}.exe"
17+
Write-Output"Fetching coder agent from${BINARY_URL}"
18+
Invoke-WebRequest-Uri"${BINARY_URL}"-OutFile$env:TEMP\sshd.exe
19+
break
20+
}catch {
21+
Write-Output"error: unhandled exception fetching coder agent:"
22+
Write-Output$_
23+
Write-Output"trying again in 30 seconds..."
24+
Start-Sleep-Seconds30
25+
}
26+
}
27+
28+
# If the below fails, retrying probably won't help.
629
Set-MpPreference-DisableRealtimeMonitoring$true-ExclusionPath$env:TEMP\sshd.exe
730
$env:CODER_AGENT_AUTH="${AUTH_TYPE}"
831
$env:CODER_AGENT_URL="${ACCESS_URL}"

‎scripts/coder-dev.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
set -euo pipefail
66

77
SCRIPT_DIR=$(dirname"${BASH_SOURCE[0]}")
8-
# shellcheck disable=SC1091
8+
# shellcheck disable=SC1091,SC1090
99
source"${SCRIPT_DIR}/lib.sh"
1010
PROJECT_ROOT=$(cd"$SCRIPT_DIR"&& git rev-parse --show-toplevel)
1111

‎scripts/develop.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
set -euo pipefail
66

77
SCRIPT_DIR=$(dirname"${BASH_SOURCE[0]}")
8-
# shellcheck disable=SC1091
8+
# shellcheck disable=SC1091,SC1090
99
source"${SCRIPT_DIR}/lib.sh"
1010
PROJECT_ROOT=$(cd"$SCRIPT_DIR"&& git rev-parse --show-toplevel)
1111
CODER_DEV_BIN="${PROJECT_ROOT}/.coderv2/coder"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp