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
+11
View File
@@ -22,6 +22,17 @@ public sealed class RemSoundService : ServiceBase
CanStop = true;
CanShutdown = true;
CanPauseAndContinue = false;
CanHandlePowerEvent = true; // so we can re-open capture after the machine wakes from sleep
}
protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
{
if (powerStatus is PowerBroadcastStatus.ResumeSuspend or PowerBroadcastStatus.ResumeAutomatic or PowerBroadcastStatus.ResumeCritical)
{
log?.Event("service: power resume — re-opening capture");
try { host?.ReopenAfterResume(); } catch (Exception ex) { log?.Event($"service: resume re-open failed {ex.GetType().Name}: {ex.Message}"); }
}
return true;
}
protected override void OnStart(string[] args)