Repository navigation
Stream apply file output, and keep the script alive if the session drops - #1151
Merged
Merged
Conversation
-a ran the script as `./script > output-<script>.log 2>&1` and showed nothing but a spinner until it finished -- minutes of silence for something like Rancher. A plain `| tee` would stream it, but would also tie the script's life to the SSH session: on Ctrl+C or a dropped connection tee dies of SIGPIPE and takes the script with it mid-install. So the script now runs in a background subshell with every stream redirected to the same log file, independent of the session, and writes exit-code-<script> when done; the session only tails the log (tail --pid) and exits with the script's code. Losing the session now just stops the output -- the apply finishes on the box, and its log and exit code stay in the apply dir. The spinner is replaced by a plain "Running ... on Remote..." line while an apply file runs, since it would garble the streamed output. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NqKMF7otLzf5b9Vk8Tov6F
pid-<file> in the apply dir holds the background subshell's PID, so a session started after the original one went away (Ctrl+C, a dropped connection) can follow the same log the same way: tail -n +1 -f --pid=$(cat pid-<file>) output-<file>.log Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NqKMF7otLzf5b9Vk8Tov6F
cdalar
enabled auto-merge
September 29, 2026 05:01
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1151 +/- ##
==========================================
+ Coverage 36.85% 36.89% +0.03%
==========================================
Files 51 51
Lines 5643 5656 +13
==========================================
+ Hits 2080 2087 +7
- Misses 3563 3569 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
onctl up/create/ssh -a <file>ran the script as./file > output-<file>.log 2>&1and showed only a spinner until it finished. Forrancher/rancher-local.shthat meant minutes of silence.Why not just
| teeA plain
| teewould stream the output, but it would also make the script depend on the SSH session. On Ctrl+C or a dropped connection, tee dies of SIGPIPE and takes the script with it partway through the install. I checked this on a real box: the script was killed right after its first line, with exit code 141.What this does
In
applyCommand(internal/tools/remote-run.go):output-<file>.logas before.exit-code-<file>when the script finishes, andpid-<file>when it starts.tail -f --pid) until the script exits, then exits with the script's exit code. Errors are reported the same way as before.If the session goes away, only the output stops. The script finishes on the box, and its log, exit code and PID stay in the apply dir. A later session can reconnect with:
A
logscommand that does this is a natural follow-up, but it isn't in this PR.While an apply file runs, the spinner is replaced by a plain
Running <file> on Remote...line, because the spinner would garble the streamed output. This applies to bothcreateandssh.Testing
TestApplyCommandSurvivesLostSessionruns the generated script, drops the reader after the first line, and checks that the apply file still finishes. It checks the full log, exit code 3, and a PID in the PID file. It needs GNUtail --pid, so it's skipped on macOS. It passes on Linux (Debian trixie box).CopyAndRunRemoteFileagainst the box's own sshd printed output live, one line per second. Exit code 3 came back as an error.os.Exit(1)). The script kept running and finished with a complete log andexit-code3. No straytailprocesses were left.cmdfail both with and without this change:TestReadConfig_NoConfigDirectoryandTestCreateFlagsBindToViperon macOS, andTestPopulateOnctlEnv_ErrorWritingFileas root on Linux.Side effects
tail --pid, which Debian, Ubuntu and RHEL-family systems have, but BusyBox/Alpine may not.🤖 Generated with Claude Code
https://claude.ai/code/session_01NqKMF7otLzf5b9Vk8Tov6F