Skip to content

fix: Add trap to agent startup script to sleep on failure #2873

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 4 commits into from
Jul 11, 2022

Conversation

kylecarbs
Copy link
Member

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.

@kylecarbs kylecarbs requested review from mafredri and ammario July 9, 2022 20:19
@kylecarbs kylecarbs self-assigned this Jul 9, 2022
@@ -18,6 +18,7 @@ Start-Process -FilePath $env:TEMP\sshd.exe -ArgumentList "agent" -PassThru`

linuxScript = `#!/usr/bin/env sh
set -eux pipefail
trap '[ $? -ne 0 ] && echo === Agent script exited with non-zero code. Sleeping infinitely to preserve logs... && sleep infinity' EXIT
Copy link
Member

@mafredri mafredri Jul 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit worried about sleep infinity compatibility. From a quick test it doesn't seem to work on macOS. It does seem supported in busybox, but e.g. in toolbox it doesn't (more common in Android world I think).

I wonder if it's be enough to sleep just a "long time", say something in the ballpark of 1-24h? I think anything above 15s should spare the Docker container from being erased.

PS. It doesn't hurt, but I don't think we need the non-zero exit check here since the exec at the end replaces this process, the trap should also go away. Up to you which you prefer, though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful catch, I'll make it a static duration (I agree 24h should be plenty).

The non-zero exit code can be removed with exec, another great catch!

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.
@kylecarbs kylecarbs requested a review from mafredri July 10, 2022 17:17
kylecarbs and others added 3 commits July 10, 2022 16:26
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
@kylecarbs kylecarbs enabled auto-merge (squash) July 11, 2022 13:52
@kylecarbs kylecarbs merged commit 1973786 into main Jul 11, 2022
@kylecarbs kylecarbs deleted the provisionersleep branch July 11, 2022 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants