From 31a4947affa0d09179d679f10883bf845ae70381 Mon Sep 17 00:00:00 2001 From: atlas Date: Fri, 19 Jun 2026 12:04:35 +0200 Subject: [PATCH] hivectl: add hive-wide restart verb (stop then start) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `hivectl restart [scope]` cycles the scoped containers — composes the existing stop + start daemon ops client-side (reusing the merged Stop/Start wire ops + global --socket), so no new wire/c0re surface. Same scope model as stop/start (--agents/--agent/--ci/--forge/--gateway/--matrix), and --graceful on the stop half. If the stop phase reports a failure the start phase is skipped so a half-stopped hive isn't blindly started over. Regenerated docs/tools/hivectl-cli.md. --- docs/tools/hivectl-cli.md | 20 ++++++++++++++++++++ hive-c0re/src/bin/hivectl.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/docs/tools/hivectl-cli.md b/docs/tools/hivectl-cli.md index 7aeacc30..8245acc7 100644 --- a/docs/tools/hivectl-cli.md +++ b/docs/tools/hivectl-cli.md @@ -23,6 +23,7 @@ This document contains the help content for the `hivectl` command-line program. * [`hivectl choom`↴](#hivectl-choom) * [`hivectl stop`↴](#hivectl-stop) * [`hivectl start`↴](#hivectl-start) +* [`hivectl restart`↴](#hivectl-restart) ## `hivectl` @@ -39,6 +40,7 @@ Sibling to the `hive-c0re` daemon binary. Covers host-side admin operations that * `choom` — Open an interactive Claude session inside an agent container * `stop` — Stop containers hive-wide in one operator action. Bare `hivectl stop` stops **everything** — all sub-agents plus the ci, forge, gateway, and matrix infra containers. Narrow it with scope flags: `--agents` (all sub-agents), `--ci` / `--forge` / `--gateway` / `--matrix` (named infra), and `--agent ` (repeatable) for specific sub-agents. Flags are additive (e.g. `--agents --matrix`). Requires the hive-c0re daemon (connects to the host admin socket). hive-c0re itself is never stopped — it services the request * `start` — Start containers hive-wide — the inverse of `hivectl stop`. Bare `hivectl start` starts everything back up; the same scope flags as `stop` narrow it (`--agents`, `--ci`, `--forge`, `--gateway`, `--matrix`, `--agent `). Requires the hive-c0re daemon +* `restart` — Restart containers hive-wide — `stop` then `start` over the same scope. Bare `hivectl restart` restarts **everything** (all sub-agents plus the ci/forge/gateway/matrix infra containers); the same scope flags as `stop`/`start` narrow it (`--agents`, `--ci`, `--forge`, `--gateway`, `--matrix`, `--agent `). If the stop phase reports a failure the start phase is skipped so the operator can investigate. Requires the hive-c0re daemon ###### **Options:** @@ -330,6 +332,24 @@ Start containers hive-wide — the inverse of `hivectl stop`. Bare `hivectl star +## `hivectl restart` + +Restart containers hive-wide — `stop` then `start` over the same scope. Bare `hivectl restart` restarts **everything** (all sub-agents plus the ci/forge/gateway/matrix infra containers); the same scope flags as `stop`/`start` narrow it (`--agents`, `--ci`, `--forge`, `--gateway`, `--matrix`, `--agent `). If the stop phase reports a failure the start phase is skipped so the operator can investigate. Requires the hive-c0re daemon + +**Usage:** `hivectl restart [OPTIONS]` + +###### **Options:** + +* `--agents` — All sub-agent containers +* `--agent ` — A specific sub-agent by name. Repeatable: `--agent a --agent b` +* `--ci` — The CI runner container (`hive-ci`) +* `--forge` — The forge container (`hive-forge`) +* `--gateway` — The gateway container (`hive-gateway`) +* `--matrix` — The matrix container (`hive-matrix`) +* `--graceful` — Gracefully quiesce each agent on the stop half (see `stop --graceful`). NOTE: not yet effective — falls through to a hard stop until the per-agent quiesce lands + + +
diff --git a/hive-c0re/src/bin/hivectl.rs b/hive-c0re/src/bin/hivectl.rs index 8f0529a9..50d72e50 100644 --- a/hive-c0re/src/bin/hivectl.rs +++ b/hive-c0re/src/bin/hivectl.rs @@ -133,6 +133,22 @@ enum Cmd { #[command(flatten)] scope: ScopeArgs, }, + /// Restart containers hive-wide — `stop` then `start` over the same + /// scope. Bare `hivectl restart` restarts **everything** (all sub-agents + /// plus the ci/forge/gateway/matrix infra containers); the same scope + /// flags as `stop`/`start` narrow it (`--agents`, `--ci`, `--forge`, + /// `--gateway`, `--matrix`, `--agent `). If the stop phase reports + /// a failure the start phase is skipped so the operator can investigate. + /// Requires the hive-c0re daemon. + Restart { + #[command(flatten)] + scope: ScopeArgs, + /// Gracefully quiesce each agent on the stop half (see + /// `stop --graceful`). NOTE: not yet effective — falls through to a + /// hard stop until the per-agent quiesce lands. + #[arg(long)] + graceful: bool, + }, /// Emit the full CLI reference as `CommonMark` to stdout. /// /// Hidden tooling command (not part of day-to-day operator admin): @@ -420,6 +436,7 @@ async fn main() -> Result<()> { }, Cmd::Stop { scope, graceful } => stop(&socket, scope.to_scope(), graceful).await, Cmd::Start { scope } => start(&socket, scope.to_scope()).await, + Cmd::Restart { scope, graceful } => restart(&socket, scope.to_scope(), graceful).await, Cmd::Choom { name, fresh } => choom(&name, fresh), Cmd::MarkdownDocs => { print!("{}", clap_markdown::help_markdown::()); @@ -891,6 +908,16 @@ async fn start(socket: &Path, scope: hive_sh4re::LifecycleScope) -> Result<()> { render_lifecycle(&resp, "started") } +/// Restart = `stop` then `start` over the same scope, composed client-side +/// from the two daemon ops (no dedicated wire op). The stop phase honours +/// `--graceful`; if it reports a failure (`stop` returns `Err`) the `?` +/// short-circuits before the start phase, so a half-stopped hive isn't +/// blindly started over — the operator sees the stop errors and can recover. +async fn restart(socket: &Path, scope: hive_sh4re::LifecycleScope, graceful: bool) -> Result<()> { + stop(socket, scope.clone(), graceful).await?; + start(socket, scope).await +} + /// Render a hive-wide stop/start response: one `: ` line per /// touched container, then surface any aggregated per-target failure as a /// non-zero exit. `verb` is the past-tense word printed per item