A startup refusal under the Windows service reaches the event log and the Service Control Manager #336

Closed
opened 2026-11-05 21:23:38 -05:00 by claude · 0 comments
Owner
  • Kind: bug
  • Area: windows
  • Priority: medium (a Windows service that refuses to start leaves no trace of why)
  • Milestone: Post-release fixes
  • Agent: coder
  • Depends on: none
  • Decisions: none

Why

Every deliberate startup refusal in Program.cs (the catch (DatabaseStartupRefusedException ...) handlers: the key-ring certificate checks added by #42 and the database migration refusals) logs through a throwaway LoggerFactory.Create(logging => logging.AddConsole()), then sets Environment.ExitCode = 78 and returns. Under the Windows service (UseWindowsService) there is no console. Observed on Lofnheim (Windows 10.0.26200) on 2026-11-05 with a wrong NINLIL_DATA_PROTECTION_CERTIFICATE_PASSWORD:

  • Start-Service Ninlil returns, and the service goes to Stopped.
  • sc.exe query Ninlil reports WIN32_EXIT_CODE 0 and SERVICE_EXIT_CODE 0, not 78.
  • No entry appears in the Application event log under Ninlil.Web, though the source is registered.

The same executable run from a console prints crit: ... Startup refused: DataProtection:CertificatePath names the file ... check DataProtection:CertificatePassword and exits with 78, so the refusal logic is right; only its reporting under the service is missing.

What changes

  • When the process runs as a Windows service (WindowsServiceHelpers.IsWindowsService()), each refusal handler also writes the message to the Application event log under Ninlil.Web (the source the README's install steps register), as an error. If the source is not registered, fall back without throwing.
  • The Service Control Manager sees a non-zero exit: report the refusal as a service-specific error (SERVICE_EXIT_CODE 78, WIN32_EXIT_CODE 1066) if the refusal happens after the service registered with the SCM, or otherwise make sure the process exit code is 78 and document what sc.exe query shows.
  • One shared helper for the three or more handlers instead of a copy each.
  • README Windows section: where a refused start is reported (event log entry, exit code) and the Get-WinEvent command to read it.

Acceptance

  • On Lofnheim, with a wrong key-ring certificate password and with a refused database (for example a database a newer version upgraded), Start-Service Ninlil leaves an error event under Ninlil.Web that names the setting, without the password; sc.exe query Ninlil shows the exit as described in the README.
  • Console runs on Linux and Windows still print the message and exit with 78.
  • Every item in Before you finish that applies is done.

Source

Windows acceptance of #42 on Lofnheim, 2026-11-05.

Refs #42

- **Kind:** bug - **Area:** windows - **Priority:** medium (a Windows service that refuses to start leaves no trace of why) - **Milestone:** Post-release fixes - **Agent:** coder - **Depends on:** none - **Decisions:** none ### Why Every deliberate startup refusal in `Program.cs` (the `catch (DatabaseStartupRefusedException ...)` handlers: the key-ring certificate checks added by #42 and the database migration refusals) logs through a throwaway `LoggerFactory.Create(logging => logging.AddConsole())`, then sets `Environment.ExitCode = 78` and returns. Under the Windows service (`UseWindowsService`) there is no console. Observed on Lofnheim (Windows 10.0.26200) on 2026-11-05 with a wrong `NINLIL_DATA_PROTECTION_CERTIFICATE_PASSWORD`: - `Start-Service Ninlil` returns, and the service goes to `Stopped`. - `sc.exe query Ninlil` reports `WIN32_EXIT_CODE 0` and `SERVICE_EXIT_CODE 0`, not 78. - No entry appears in the Application event log under `Ninlil.Web`, though the source is registered. The same executable run from a console prints `crit: ... Startup refused: DataProtection:CertificatePath names the file ... check DataProtection:CertificatePassword` and exits with 78, so the refusal logic is right; only its reporting under the service is missing. ### What changes - When the process runs as a Windows service (`WindowsServiceHelpers.IsWindowsService()`), each refusal handler also writes the message to the Application event log under `Ninlil.Web` (the source the README's install steps register), as an error. If the source is not registered, fall back without throwing. - The Service Control Manager sees a non-zero exit: report the refusal as a service-specific error (`SERVICE_EXIT_CODE` 78, `WIN32_EXIT_CODE` 1066) if the refusal happens after the service registered with the SCM, or otherwise make sure the process exit code is 78 and document what `sc.exe query` shows. - One shared helper for the three or more handlers instead of a copy each. - README Windows section: where a refused start is reported (event log entry, exit code) and the `Get-WinEvent` command to read it. ### Acceptance - [ ] On Lofnheim, with a wrong key-ring certificate password and with a refused database (for example a database a newer version upgraded), `Start-Service Ninlil` leaves an error event under `Ninlil.Web` that names the setting, without the password; `sc.exe query Ninlil` shows the exit as described in the README. - [ ] Console runs on Linux and Windows still print the message and exit with 78. - [ ] Every item in [Before you finish](https://git.lantea.one/lantea-one/ninlil/src/branch/main/AGENTS.md#before-you-finish) that applies is done. ### Source Windows acceptance of #42 on Lofnheim, 2026-11-05. Refs #42
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lantea-one/ninlil#336
No description provided.