feat(reboot): add Client.Reboot with Windows schtasks and POSIX fallback#345
Draft
kke wants to merge 1 commit into
Draft
feat(reboot): add Client.Reboot with Windows schtasks and POSIX fallback#345kke wants to merge 1 commit into
kke wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a first-class reboot capability to Rig v2 clients, with platform-specific behavior to reliably trigger reboots over remote transports (WinRM/SSH), and removes a panic-swallowing recover() from WinRM command waiting.
Changes:
- Introduce
Client.Reboot(ctx)and a sharedos.Reboot(ctx, runner)implementation. - Implement Windows reboot via one-shot SYSTEM scheduled task (
schtasks) and POSIX reboot viarebootwithshutdown -r nowfallback. - Remove the
recover()in WinRMcommand.Wait()and adjust the command struct accordingly.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| reboot.go | Adds Client.Reboot(ctx) and exports an ErrRebootUnsupported alias. |
| protocol/winrm/connection.go | Removes recover() from command.Wait() and drops the per-command logger field. |
| os/reboot.go | Adds platform-specific reboot logic plus transport-close detection helper. |
| os/reboot_test.go | Adds unit tests for transport-close detection and reboot command sequencing/fallbacks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0ee4b6b to
9531d24
Compare
- Windows: uses a SYSTEM-context one-shot scheduled task (schtasks /create … /ru SYSTEM + schtasks /run) to bypass the filtered WinRM token that lacks SeShutdownPrivilege on hosts such as AWS EC2, where direct shutdown /r is silently ignored. Best-effort schtasks /delete on every exit path prevents a delayed fallback fire if /run never triggered the shutdown. - POSIX (Linux/macOS): runs "reboot", falls back to "shutdown -r now" on a logical error; transport-level errors from either are treated as success since the kernel is already going down. Also remove the vestigial recover() in protocol/winrm command.Wait() that silently swallowed "close of closed channel" panics; v2 does not have the explicit Stdout/Stderr Close() goroutines that triggered it, so the recover was only hiding future real panics. Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
58a9c34 to
09cd337
Compare
Comment on lines
+17
to
+24
| func (c *Client) Reboot(ctx context.Context) error { | ||
| if c.connection == nil { | ||
| return fmt.Errorf("%w: connection not properly initialized", protocol.ErrNonRetryable) | ||
| } | ||
| if err := c.FS().Reboot(ctx); err != nil { | ||
| return fmt.Errorf("reboot: %w", err) | ||
| } | ||
| return nil |
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.
Implement Client.Reboot(ctx) for all supported platforms:
Transport-close detection (isTransportClosed) helper is protocol-agnostic since SSH and WinRM sessions both tear down the same way during a reboot.
Also remove the vestigial recover() in protocol/winrm command.Wait() that silently swallowed "close of closed channel" panics; v2 does not have the explicit Stdout/Stderr Close() goroutines that triggered it, so the recover was only hiding future real panics.
Rig v2 is not released yet so breaking API is not a concern.