Skip to content

feat(reboot): add Client.Reboot with Windows schtasks and POSIX fallback#345

Draft
kke wants to merge 1 commit into
mainfrom
ENGINE-1383-v2-reboot-winrm-fix
Draft

feat(reboot): add Client.Reboot with Windows schtasks and POSIX fallback#345
kke wants to merge 1 commit into
mainfrom
ENGINE-1383-v2-reboot-winrm-fix

Conversation

@kke
Copy link
Copy Markdown
Contributor

@kke kke commented May 13, 2026

Implement Client.Reboot(ctx) for all supported platforms:

  • 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.

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 shared os.Reboot(ctx, runner) implementation.
  • Implement Windows reboot via one-shot SYSTEM scheduled task (schtasks) and POSIX reboot via reboot with shutdown -r now fallback.
  • Remove the recover() in WinRM command.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.

Comment thread reboot.go Outdated
Comment thread reboot.go Outdated
Comment thread os/reboot.go Outdated
Comment thread os/reboot.go Outdated
Comment thread os/reboot.go Outdated
@kke kke force-pushed the ENGINE-1383-v2-reboot-winrm-fix branch from 0ee4b6b to 9531d24 Compare May 13, 2026 12:30
@kke kke requested a review from Copilot May 13, 2026 12:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread os/reboot.go Outdated
Comment thread os/reboot.go Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

- 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>
@kke kke force-pushed the ENGINE-1383-v2-reboot-winrm-fix branch from 58a9c34 to 09cd337 Compare May 13, 2026 13:45
@kke kke requested a review from Copilot May 13, 2026 13:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Comment thread remotefs/reboot.go
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Comment thread reboot.go
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
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.

2 participants