Service: harden for unattended running (auto-restart, findable logs, resume)

Local checkpoint - NOT for public release. A "what else does a service need" pass.

- AUTO-RESTART ON CRASH: DoInstall now sets sc failure actions (restart 5s/10s/then 60s,
  reset daily). Without this a crashed service stays dead until reboot - fatal for an
  always-on streamer.
- FINDABLE LOGS: --run-service redirects the service's data dir to the machine-wide
  ProgramData\RemSound\service location, so its log sits next to its profile instead of
  buried in the SYSTEM account's AppData.
- POWER RESUME: the service handles OnPowerEvent and re-opens capture on wake (audio
  devices re-initialise after sleep; the device-change watcher usually catches it, but a
  resume doesn't always fire an endpoint change, so we re-open explicitly).
- Start/stop already auto-log to the Windows Event Log via ServiceBase.

Test: "Service registration args" now also checks the audio-service dependency and the
auto-restart failure args. Gate 27/27.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Ednunp
2026-07-13 08:43:33 +01:00
co-authored by Claude Opus 4.8
parent 4f5265d8b0
commit 92ed477ddf
5 changed files with 49 additions and 2 deletions
+7 -1
View File
@@ -676,7 +676,13 @@ internal static class SelfTest
Check(args.Contains("\\\"" + exe + "\\\" " + ServiceControl.RunVerb),
$"exe path must be escaped-quoted with the run verb (got: {args})");
Check(args.Contains($"DisplayName= \"{ServiceControl.DisplayName}\""), "must set the display name");
return "sc create args quoted correctly for a spaced path";
Check(args.Contains("depend= Audiosrv"), "must depend on the audio service so it starts after audio is up");
// Auto-restart-on-crash failure actions.
var fail = ServiceControl.BuildFailureArgs();
Check(fail.StartsWith($"failure {ServiceControl.ServiceName} ") && fail.Contains("actions= restart/"),
$"failure args must configure auto-restart (got: {fail})");
return "sc create + failure args are well-formed";
}
/// <summary>The service profile is fully isolated from the normal profile machinery: it lives in a