Skip to content

feat(tamanu): expected-services model + robust pm2 discovery on Windows#336

Merged
passcod merged 8 commits into
mainfrom
feat/tamanu-services
May 23, 2026
Merged

feat(tamanu): expected-services model + robust pm2 discovery on Windows#336
passcod merged 8 commits into
mainfrom
feat/tamanu-services

Conversation

@passcod
Copy link
Copy Markdown
Member

@passcod passcod commented May 22, 2026

Summary

Replaces the doctor's tamanu_service healthcheck with a declarative
expected-services model and adds a robust pm2 discovery path for Windows.

Expected-services model

  • New tamanu::services module: Supervisor, ServerKind (from ApiServerKind), Expectation, Instances (Single / NumericAtLeast(n) / Named(&[…])), ExpectedState (Up/Down), plus an expected(supervisor, kind, &config) function.
  • Encodes the current ruleset: tasks singleton; frontend@a/@b and forbidden tamanu-facility singleton on systemd; api ≥2; Central fhir-resolve/fhir-refresh when fhir.worker.enabled; Facility sync singleton.
  • New fhir.worker.enabled field on TamanuConfig.

Doctor check

  • Discovers tamanu-* units/processes, matches each expectation, diagnoses missing / shortfall / forbidden / not-running. Unrelated tamanu-* services are recorded as informational extras rather than counted against the check.
  • Probes systemctl is-enabled for any forbidden unit that didn't show up loaded.
  • Exposes structured details: per-expectation outcome, raw services, extras, and (for pm2) the discovery source.

pm2 discovery on Windows

  • New tamanu::pm2 module. The doctor no longer calls Command::new("pm2") directly.
  • CLI lookup tries BESTOOL_PM2_COMMAND, then pm2.cmd/pm2.bat, then common npm-global install paths and C:\pm2\pm2.cmd.
  • If the CLI isn't reachable, falls back to reading PM2_HOME/dump.pm2 directly and checking PM2_HOME/pids/<name>-<id>.pid against the OS process list (via sysinfo). Candidate PM2_HOME locations: env var, C:\pm2, ~/.pm2.
  • Source (cli / dump) surfaces in the check details.

Tests cover the expected() matrix, the matching logic with synthetic discovered lists, and pm2 dump+pid parsing with tempdir fixtures.

@passcod passcod force-pushed the feat/tamanu-services branch from 709a882 to 0400646 Compare May 22, 2026 23:35
@passcod passcod enabled auto-merge May 22, 2026 23:48
@passcod passcod added this pull request to the merge queue May 22, 2026
Merged via the queue into main with commit d0039ec May 23, 2026
8 checks passed
@passcod passcod deleted the feat/tamanu-services branch May 23, 2026 00:11
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.

1 participant