-
Notifications
You must be signed in to change notification settings - Fork 887
fix: make agent scripts easier to troubleshoot #2922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ca8aac5
add sleeps to agent startup script
johnstcn 51235b9
exit 1
johnstcn 1b9368f
add more detailed exit statuses
johnstcn 9586595
quick
johnstcn 4942335
make scripts loop forever
johnstcn 38bb5f5
more shellcheck
johnstcn 89f2f7c
address PR comments
johnstcn 5e315ef
Update provisionersdk/scripts/bootstrap_windows.ps1
johnstcn 9f90ee3
Merge branch 'main' into cj/gh-1544/agent-script-wait
johnstcn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,34 @@ | ||
#!/usr/bin/env sh | ||
set -eux pipefail | ||
trap "echo === Agent script exited with non-zero code. Sleeping 24h to preserve logs... && sleep 86400" EXIT | ||
# Sleep for a good long while before exiting. | ||
# This is to allow folks to exec into a failed workspace and poke around to | ||
# troubleshoot. | ||
waitonexit() { | ||
echo "=== Agent script exited with non-zero code. Sleeping 24h to preserve logs..." | ||
sleep 86400 | ||
} | ||
trap waitonexit EXIT | ||
BINARY_DIR=$(mktemp -d -t coder.XXXXXX) | ||
BINARY_NAME=coder | ||
BINARY_URL=${ACCESS_URL}bin/coder-darwin-${ARCH} | ||
cd "$BINARY_DIR" | ||
curl -fsSL --compressed "${ACCESS_URL}bin/coder-darwin-${ARCH}" -o "${BINARY_NAME}" | ||
chmod +x $BINARY_NAME | ||
# Attempt to download the coder agent. | ||
# This could fail for a number of reasons, many of which are likely transient. | ||
# So just keep trying! | ||
while :; do | ||
curl -fsSL --compressed "${BINARY_URL}" -o "${BINARY_NAME}" && break | ||
status=$? | ||
echo "error: failed to download coder agent using curl" | ||
echo "curl exit code: ${status}" | ||
echo "Trying again in 30 seconds..." | ||
sleep 30 | ||
done | ||
|
||
if ! chmod +x $BINARY_NAME; then | ||
echo "Failed to make $BINARY_NAME executable" | ||
exit 1 | ||
fi | ||
|
||
export CODER_AGENT_AUTH="${AUTH_TYPE}" | ||
export CODER_AGENT_URL="${ACCESS_URL}" | ||
exec ./$BINARY_NAME agent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,48 @@ | ||
#!/usr/bin/env sh | ||
set -eux pipefail | ||
trap "echo === Agent script exited with non-zero code. Sleeping 24h to preserve logs... && sleep 86400" EXIT | ||
# Sleep for a good long while before exiting. | ||
# This is to allow folks to exec into a failed workspace and poke around to | ||
# troubleshoot. | ||
waitonexit() { | ||
echo "=== Agent script exited with non-zero code. Sleeping 24h to preserve logs..." | ||
sleep 86400 | ||
} | ||
trap waitonexit EXIT | ||
BINARY_DIR=$(mktemp -d -t coder.XXXXXX) | ||
BINARY_NAME=coder | ||
BINARY_URL=${ACCESS_URL}bin/coder-linux-${ARCH} | ||
cd "$BINARY_DIR" | ||
if command -v curl >/dev/null 2>&1; then | ||
curl -fsSL --compressed "${BINARY_URL}" -o "${BINARY_NAME}" | ||
elif command -v wget >/dev/null 2>&1; then | ||
wget -q "${BINARY_URL}" -O "${BINARY_NAME}" | ||
elif command -v busybox >/dev/null 2>&1; then | ||
busybox wget -q "${BINARY_URL}" -O "${BINARY_NAME}" | ||
else | ||
echo "error: no download tool found, please install curl, wget or busybox wget" | ||
# Attempt to download the coder agent. | ||
# This could fail for a number of reasons, many of which are likely transient. | ||
# So just keep trying! | ||
while :; do | ||
# Try a number of different download tools, as we don't know what we'll | ||
# have available | ||
status="" | ||
if command -v curl >/dev/null 2>&1; then | ||
curl -fsSL --compressed "${BINARY_URL}" -o "${BINARY_NAME}" && break | ||
status=$? | ||
elif command -v wget >/dev/null 2>&1; then | ||
wget -q "${BINARY_URL}" -O "${BINARY_NAME}" && break | ||
status=$? | ||
elif command -v busybox >/dev/null 2>&1; then | ||
busybox wget -q "${BINARY_URL}" -O "${BINARY_NAME}" && break | ||
status=$? | ||
else | ||
echo "error: no download tool found, please install curl, wget or busybox wget" | ||
exit 127 | ||
fi | ||
echo "error: failed to download coder agent" | ||
echo " command returned: ${status}" | ||
echo "Trying again in 30 seconds..." | ||
sleep 30 | ||
done | ||
|
||
if ! chmod +x $BINARY_NAME; then | ||
echo "Failed to make $BINARY_NAME executable" | ||
exit 1 | ||
fi | ||
chmod +x $BINARY_NAME | ||
|
||
export CODER_AGENT_AUTH="${AUTH_TYPE}" | ||
export CODER_AGENT_URL="${ACCESS_URL}" | ||
exec ./$BINARY_NAME agent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL that PS also has
trap