Probe a service by opening a TCP connection to its listening port. The check passes when the connection succeeds.
# TCP health check: probe a service by opening a TCP connection to its port.
processes:
- name: svc
command: /bin/sh
args: ["-c", "exec nc -lk 127.0.0.1 PORT"]
on-failure: shutdown
checks:
svc-tcp:
tcp:
host: 127.0.0.1
port: PORT
period: 300ms
threshold: 1tcp.hostandtcp.portare dialed everyperiod; a successful connect is healthy.thresholdis the number of consecutive failures before the check is marked unhealthy.- In a real config,
commandis your service binary andportis the port it listens on. Here the service is annclistener so the example is self-contained.
-
gopherd starts
svc(anncTCP listener) and thesvc-tcpcheck. -
Once the listener binds, the probe connects and the check reports
healthy:checks: svc-tcp healthy failures=0 -
If the port is closed (service down or not yet bound), connects fail and the check trends
unhealthyoncethresholdis reached.
Run level. PORT is substituted with an OS-assigned free port (e.g. 8080). The service is a real nc -lk listener; the test waits for the TCP probe to connect and asserts the svc-tcp line is healthy.
nc here is OpenBSD netcat (Debian); -lk listens and keeps accepting connections.
go test ./documentation/health-check-tcp/ -v