Refactor CLI: birdc-style help, collapsed nouns, ReloadConfig, bug fixes
maglevc - Rewrite '?' handler (birdc-style): show full command paths from current position to every leaf, right-aligned help column, dynamic slot values displayed as an indented block when cursor is at a slot position. - Collapse show frontends/frontend, backends/backend, healthchecks/healthcheck into single plural-noun nodes with an optional <name> slot. Allows 'sh ba' (list all) and 'sh ba nginx0' (show one) without ambiguity. - Add 'config reload' command. - Fix tabwriter ANSI alignment: continuation lines in transition output now carry the same label() byte overhead as the header line. - Fix broken Walk for 'set frontend' command: setFrontendPoolName and setWeightValue were fixed-word nodes that couldn't capture user input; mark them as slot nodes with dynNone. - Add tree_test.go covering expandPaths, cycle detection, prefix matching, and the full weight-command walk. gRPC / proto - Add ReloadConfig RPC: checks config then applies it to the running checker, returning ok/parse_error/semantic_error/reload_error. - Add logging to CheckConfig (config-check-start/config-check-done at INFO level). maglevd - SIGHUP handler now calls maglevServer.TriggerReload(), sharing the same code path as the gRPC ReloadConfig RPC. docs - Collapse show command documentation to use [<name>] optional syntax. - Remove developer-facing 'Command tree and parser' section. - Document 'config reload'.
This commit is contained in:
@@ -24,7 +24,7 @@ are used for anything not set.
|
||||
|
||||
| Signal | Effect |
|
||||
|---|---|
|
||||
| `SIGHUP` | Reload the configuration file. The file is checked before applying; if there is a parse or semantic error the reload is aborted and the error is logged (the daemon continues running with its current config). New backends are started, removed backends are stopped, backends whose health-check config is unchanged continue probing without interruption. |
|
||||
| `SIGHUP` | Reload the configuration file (same code path as `config reload` in `maglevc`). The file is checked before applying; if there is a parse or semantic error the reload is aborted and the error is logged (the daemon continues running with its current config). New backends are started, removed backends are stopped, backends whose health-check config is unchanged continue probing without interruption. |
|
||||
| `SIGTERM` / `SIGINT` | Graceful shutdown. Active gRPC streams are closed, the server drains, then the process exits. |
|
||||
|
||||
### Capabilities
|
||||
@@ -69,33 +69,33 @@ build version is printed on entry.
|
||||
```
|
||||
show version Print build version, commit hash, and build date.
|
||||
|
||||
show frontends List all frontend names.
|
||||
show frontend <name> Show address, protocol, port, description, and pools.
|
||||
Each pool lists its backends with weights (if != 100)
|
||||
and marks disabled backends with [disabled].
|
||||
show frontends [<name>] Without name: list all frontend names.
|
||||
With name: show address, protocol, port, description,
|
||||
and pools. Each pool lists its backends with weights
|
||||
(if != 100) and marks disabled backends with [disabled].
|
||||
|
||||
show backends List all backend names.
|
||||
show backend <name> Show address, current state (with duration in that state),
|
||||
show backends [<name>] Without name: list all backend names.
|
||||
With name: show address, current state (with duration),
|
||||
enabled flag, health check, and recent state transitions
|
||||
with timestamps and how long ago each occurred.
|
||||
|
||||
show healthchecks List all health-check names.
|
||||
show healthcheck <name> Show full health-check configuration.
|
||||
show healthchecks [<name>] Without name: list all health-check names.
|
||||
With name: show full health-check configuration.
|
||||
|
||||
set backend <name> pause Suspend health checking for a backend, freezing its state.
|
||||
set backend <name> resume Resume health checking; backend re-enters unknown state
|
||||
and is probed immediately.
|
||||
set frontend <name> pool <pool> backend <name> weight <0-100>
|
||||
Set the weight of a backend within a pool. Weight 0 keeps
|
||||
the backend in the pool but assigns it no traffic.
|
||||
Takes effect immediately without reloading configuration.
|
||||
|
||||
set backend <name> disable Stop probing entirely and remove the backend from rotation.
|
||||
The backend remains visible (state: removed) and can be
|
||||
re-enabled without reloading configuration.
|
||||
set backend <name> enable Re-enable a disabled backend. A fresh probe goroutine is
|
||||
started and the backend re-enters unknown state.
|
||||
|
||||
set frontend <name> pool <pool> backend <name> weight <0-100>
|
||||
Set the weight of a backend within a pool. Weight 0 keeps
|
||||
the backend in the pool but assigns it no traffic.
|
||||
Takes effect immediately without reloading configuration.
|
||||
|
||||
watch events Stream all events (log, backend transitions, frontend)
|
||||
[num <n>] Stop after receiving n events.
|
||||
[log [level <level>]] Include log events. level is debug|info|warn|error
|
||||
@@ -115,6 +115,10 @@ watch events Stream all events (log, backend transitions, fr
|
||||
config check Ask maglevd to read and validate its current config file.
|
||||
Prints "config ok" on success, or the error (parse or
|
||||
semantic) returned by the daemon.
|
||||
config reload Check and reload the configuration file. Equivalent to
|
||||
sending SIGHUP to maglevd. Prints "config reloaded" on
|
||||
success, or the specific error (parse, semantic, or
|
||||
reload) that prevented the reload.
|
||||
|
||||
quit / exit Leave the interactive shell.
|
||||
```
|
||||
@@ -134,32 +138,5 @@ restored.
|
||||
completions for the current position, with a short description next to each
|
||||
keyword. The `?` character is not added to the input line.
|
||||
|
||||
Commands and keywords support **prefix matching**: typing `sh b` is equivalent
|
||||
to `show backend` provided the prefix is unambiguous. Exact matches always take
|
||||
priority over prefix matches, so `show backend` and `show backends` are
|
||||
unambiguous even though one is a prefix of the other.
|
||||
|
||||
### Command tree and parser
|
||||
|
||||
Commands form a tree of `Node` values. Each node has a fixed `Word` (a keyword)
|
||||
or is a *slot node* (marked by a `Dynamic` function that enumerates valid
|
||||
values at completion time). The parser (`Walk`) descends the tree token by
|
||||
token:
|
||||
|
||||
1. Try to match the current token against the fixed-keyword children of the
|
||||
current node (exact match first, then unique prefix match).
|
||||
2. If no fixed child matches, try a slot child — any token is accepted and
|
||||
stored as an argument.
|
||||
3. Stop when tokens are exhausted or no match is found.
|
||||
|
||||
The leaf node reached by `Walk` must have a `Run` function; otherwise the
|
||||
available sub-commands at that position are printed as help. Arguments
|
||||
collected from slot nodes are passed to `Run` as a slice.
|
||||
|
||||
Example walk for `set backend nginx0-ams pause`:
|
||||
|
||||
```
|
||||
root → set → backend → <name>(nginx0-ams collected as arg) → pause
|
||||
```
|
||||
|
||||
`pause.Run` is called with `args = ["nginx0-ams"]`.
|
||||
Commands and keywords support **prefix matching**: typing `sh ba` is equivalent
|
||||
to `show backends`, and `sh ba nginx0` is equivalent to `show backends nginx0`.
|
||||
|
||||
Reference in New Issue
Block a user