Probe a service by running a command on a schedule. The check passes when the command exits zero.
# Exec health check: run a command periodically to probe a service.
processes:
- name: svc
command: /usr/local/bin/svc
args: ["300"]
on-failure: shutdown
checks:
svc-alive:
exec:
command: /bin/true
args: []
period: 300ms
threshold: 1checks:is a map keyed by check name.svc-aliveis the check.exec.commandruns everyperiod; exit 0 is healthy, non-zero is a failure.thresholdis the number of consecutive failures before the check is marked unhealthy.- A check is purely a probe here. To make a service react, add
on-check-failure: { svc-alive: restart }(orshutdown).
-
gopherd starts
svcand thesvc-alivecheck. -
The check appears in
gopherd statusimmediately, then flips tohealthyafter its first probe. -
The checks section of
statusreports one line per check:checks: svc-alive healthy failures=0 -
A failing exec check (non-zero exit) reaches
unhealthyoncethresholdconsecutive failures accumulate, andfailurescounts up.
Run level. The test substitutes /usr/bin/sleep for the svc placeholder, asserts svc is running, waits a few check periods, and asserts the svc-alive line is healthy (not unhealthy). /bin/true always succeeds, so the probe is deterministic and needs no network.
go test ./documentation/health-check-exec/ -v