Environment
- rig/v2 v2.1.0
- Windows target (
WinSCM init system)
Summary
Starting a Windows service that does not become Running instantaneously fails, even though the service starts successfully. The returned error is:
failed to start service <name>: command wrote output to stderr (#Waiting for service '<display name>' to start...)
Root cause
WinSCM.StartService runs Start-Service without suppressing the warning stream and without AllowWinStderr:
func (c WinSCM) StartService(ctx context.Context, h cmd.ContextRunner, s string) error {
if err := h.ExecContext(ctx, "$ErrorActionPreference='Stop'\nStart-Service "+ps.SingleQuote(s)+" -ErrorAction Stop", cmd.PS()); err != nil {
return fmt.Errorf("failed to start service %s: %w", s, err)
}
return nil
}
When the target service stays in StartPending for more than a moment (common on a cold first start — the service does real initialization work), PowerShell's Start-Service emits a non-terminating warning to the warning stream:
WARNING: Waiting for service '<display> (<name>)' to start...
Run as a subprocess, the warning stream is written to stderr. rig treats any stderr output from a Windows command as a failure (cmd.ErrWroteStderr, "command wrote output to stderr") unless AllowWinStderr is set. So a successful-but-slow start is reported as an error. StopService/RestartService have the same shape (StopPending warning).
The command exits 0 and the service does reach Running; only the benign warning on stderr causes the false failure.
Proposed fix
Add -WarningAction SilentlyContinue to the Start-Service/Stop-Service/Restart-Service commands in WinSCM (and/or set AllowWinStderr on these ExecContext calls). Genuine failures still surface via -ErrorAction Stop (terminating error → non-zero exit), so error detection is preserved; only the benign progress warning is silenced.
"$ErrorActionPreference='Stop'\nStart-Service "+ps.SingleQuote(s)+" -ErrorAction Stop -WarningAction SilentlyContinue"
Happy to open a PR.
Environment
WinSCMinit system)Summary
Starting a Windows service that does not become
Runninginstantaneously fails, even though the service starts successfully. The returned error is:Root cause
WinSCM.StartServicerunsStart-Servicewithout suppressing the warning stream and withoutAllowWinStderr:When the target service stays in
StartPendingfor more than a moment (common on a cold first start — the service does real initialization work), PowerShell'sStart-Serviceemits a non-terminating warning to the warning stream:Run as a subprocess, the warning stream is written to stderr. rig treats any stderr output from a Windows command as a failure (
cmd.ErrWroteStderr, "command wrote output to stderr") unlessAllowWinStderris set. So a successful-but-slow start is reported as an error.StopService/RestartServicehave the same shape (StopPending warning).The command exits 0 and the service does reach
Running; only the benign warning on stderr causes the false failure.Proposed fix
Add
-WarningAction SilentlyContinueto theStart-Service/Stop-Service/Restart-Servicecommands inWinSCM(and/or setAllowWinStderron theseExecContextcalls). Genuine failures still surface via-ErrorAction Stop(terminating error → non-zero exit), so error detection is preserved; only the benign progress warning is silenced.Happy to open a PR.