Skip to content

Commit 3b92d73

Browse files
committed
docs: document conchd status API, global --quiet flag, --json, and --min-rev options
1 parent f61fd1c commit 3b92d73

4 files changed

Lines changed: 83 additions & 2 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ CONCH_TTL lease TTL (default: 10s)
3535

3636
Can also be passed as flags.
3737

38+
Other global flags:
39+
- `--quiet`: suppress log output below `WARN` level.
40+
3841
---
3942

4043
## elect
@@ -54,6 +57,8 @@ conch elect <office> [flags] -- <cmd...>
5457
| `--on-acquire` || shell command run on winning the office |
5558
| `--on-lose` || shell command run on losing the office |
5659
| `--hook-timeout` | 30s | timeout for hook commands |
60+
| `--json` | off | print output as JSON (for `--who`, `--watch`, `--assert`) |
61+
| `--min-rev` | 0 | minimum create-revision for `--assert` |
5762

5863
```bash
5964
# Run a daemon, restart on failure
@@ -64,10 +69,15 @@ conch elect db-primary --on-acquire "pg_ctl promote" --on-lose "pg_ctl demote" -
6469

6570
# Check who holds the office
6671
conch elect api-leader --who
72+
conch elect api-leader --who --json
73+
74+
# Watch leadership changes
6775
conch elect api-leader --watch
76+
conch elect api-leader --watch --json
6877

6978
# Assert this host holds the office (exit 0 yes, 1 no, 69 etcd unreachable)
7079
conch elect api-leader --assert
80+
conch elect api-leader --assert --min-rev 100 --json
7181
```
7282

7383
---
@@ -86,6 +96,8 @@ conch sema <name> --max N [flags] -- <cmd...>
8696
| `--spread` | off | at most 1 slot per hostname |
8797
| `--wait` | forever | give up after this duration |
8898
| `--nonblock` | off | exit 75 immediately if no slot available |
99+
| `--kill-after` | 5s | grace period before SIGKILL |
100+
| `--json` | off | print output as JSON (for `--who`) |
89101

90102
```bash
91103
# At most 3 nodes run this at once
@@ -96,6 +108,7 @@ conch sema ingest --max 5 --spread -- /usr/local/bin/ingest
96108

97109
# Check who holds slots
98110
conch sema heavy-jobs --max 3 --who
111+
conch sema heavy-jobs --max 3 --who --json
99112
```
100113

101114
---
@@ -118,6 +131,9 @@ conch cron ls [--last] [--json]
118131
```bash
119132
# Run conchd on each cluster node to execute scheduled jobs
120133
conch conchd
134+
135+
# Run conchd status HTTP API server on port 9191 (can also use CONCH_STATUS_ADDR env var)
136+
conch conchd --status-addr :9191
121137
```
122138

123139
---

docs/02_core.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
Everything every tool inherits. This file is authoritative; `00_design.md` sketches.
44

5-
## 1. Connection
5+
## 1. Connection & Logging
66

77
| Flag | Env | Default |
88
| :--- | :--- | :--- |
99
| `--endpoints` | `CONCH_ENDPOINTS` | `localhost:2379` |
1010
| `--dial-timeout` | `CONCH_DIAL_TIMEOUT` | `5s` |
11+
| `--quiet` || `false` |
1112

1213
Plain HTTP (matches the cluster's etcd; no TLS until etcd itself grows it). If no
1314
endpoint is reachable within the dial timeout: exit **69** without side effects.

docs/05_cron.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Distributed cron: a schedule executed by exactly one node per tick. Anyone sched
88
conch cron add <name> --schedule '<cron expr>' [--run-ttl 10m] [--quiet] -- <cmd...>
99
conch cron ls [--last] [--json]
1010
conch cron rm <name>
11-
conch conchd # the per-node daemon (systemd unit; identical on every node)
11+
conch conchd [--status-addr :9191] # the per-node daemon (systemd unit; identical on every node)
1212
```
1313

1414
## Job spec
@@ -76,6 +76,63 @@ output goes to the journal of the node that ran it (conchd logs child stdout/std
7676
slog). Keeping output out of etcd is deliberate: etcd is a coordination store, not a
7777
log pipeline.
7878

79+
## `conchd` Status HTTP API
80+
81+
When starting `conchd`, you can enable a local/cluster HTTP status server by passing the `--status-addr` flag or setting the `CONCH_STATUS_ADDR` environment variable:
82+
83+
```sh
84+
conch conchd --status-addr :9191
85+
```
86+
87+
The daemon will run an HTTP server exposing status endpoints in JSON format:
88+
89+
* **`GET /cron`**: Lists all registered cron jobs with their current status, schedules, last execution details (including duration, exit code, and node), and the next scheduled execution time:
90+
```json
91+
[
92+
{
93+
"name": "db-backup",
94+
"schedule": "*/15 * * * *",
95+
"next_tick": "2026-06-12T11:00:00Z",
96+
"last_tick": "2026-06-12T10:45:00Z",
97+
"node": "node3",
98+
"exit": 0,
99+
"duration": "4.2s"
100+
}
101+
]
102+
```
103+
* **`GET /elect`**: Lists all active leader election offices, showing who currently holds the primary lease, the PID and start time of the supervised process:
104+
```json
105+
[
106+
{
107+
"office": "db-primary",
108+
"leader": "node1",
109+
"pid": 12053,
110+
"started": "2026-06-12T08:00:00Z",
111+
"cmd": "postgres",
112+
"create_revision": 4512
113+
}
114+
]
115+
```
116+
* **`GET /sema`**: Lists all semaphores, indicating maximum capacities along with holders and queued nodes currently waiting on slot availability:
117+
```json
118+
[
119+
{
120+
"name": "heavy-jobs",
121+
"max": 2,
122+
"holders": [
123+
{
124+
"host": "node2",
125+
"pid": 9912,
126+
"started": "2026-06-12T10:15:00Z",
127+
"cmd": "/usr/local/bin/run-job.sh",
128+
"create_revision": 8812
129+
}
130+
],
131+
"waitlist": []
132+
}
133+
]
134+
```
135+
79136
## Failure behavior
80137

81138
* **Clock skew**: a fast node claims tick `T` early by (skew − jitter); a slow node

docs/07_deployment.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ When deploying upgrades to the `conch` binary or `conchd`:
7777
```sh
7878
conch elect monitor-probe --assert
7979
```
80+
* **Status HTTP API**: If `conchd` has `--status-addr` enabled, query status or health directly via HTTP:
81+
```sh
82+
# Query cron, election, or semaphore statuses
83+
curl -fsS http://localhost:9191/cron
84+
curl -fsS http://localhost:9191/elect
85+
curl -fsS http://localhost:9191/sema
86+
```
8087
* **Dead Man's Snitch**: Register a simple heartbeat cron job to ping an external monitoring endpoint:
8188
```sh
8289
conch cron add heartbeat --schedule '@every 5m' -- curl -fsS https://hchk.io/your-uuid

0 commit comments

Comments
 (0)