Skip to content

Commit 3a0d162

Browse files
committed
fix: Add trap to agent startup script to sleep on failure
The Docker Terraform provider removes containers immediately on exit, making it difficult to debug a failed container start with Coder. This will sleep on exit and output a friendly log, which should assist with debugging failures.
1 parent 08a781f commit 3a0d162

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

provisionersdk/agent.go

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Start-Process -FilePath $env:TEMP\sshd.exe -ArgumentList "agent" -PassThru`
1818

1919
linuxScript = `#!/usr/bin/env sh
2020
set -eux pipefail
21+
trap '[ $? -ne 0 ] && echo === Agent script exited with non-zero code. Sleeping infinitely to preserve logs... && sleep infinity' EXIT
2122
BINARY_DIR=$(mktemp -d -t coder.XXXXXX)
2223
BINARY_NAME=coder
2324
BINARY_URL=${ACCESS_URL}bin/coder-linux-${ARCH}
@@ -39,6 +40,7 @@ exec ./$BINARY_NAME agent`
3940

4041
darwinScript = `#!/usr/bin/env sh
4142
set -eux pipefail
43+
trap '[ $? -ne 0 ] && echo === Agent script exited with non-zero code. Sleeping infinitely to preserve logs... && sleep infinity' EXIT
4244
BINARY_DIR=$(mktemp -d -t coder.XXXXXX)
4345
BINARY_NAME=coder
4446
cd $BINARY_DIR

0 commit comments

Comments
 (0)