Appearance
Start / stop / restart
Bringing a Host up cleanly and down cleanly are not symmetric — start has to spawn NATS first, stop has to wait for NATS to actually exit before returning. This page documents both.
On a .deb-managed Host (systemd)
systemd is the supervisor. Use systemctl directly:
bash
sudo systemctl start hivecast-nats.service hivecast-host.service
sudo systemctl stop hivecast-host.service hivecast-nats.service
sudo systemctl restart hivecast-host.service # restarts host-service only, NATS stays up
sudo systemctl status hivecast-host.service hivecast-nats.serviceThe unit file's Requires=hivecast-nats.service enforces the start ordering — systemd refuses to start hivecast-host if NATS isn't up. The reverse (stopping host-service while NATS keeps running) is the whole point of splitting them: short host-service restarts don't blow away the bus.
A full restart of both:
bash
sudo systemctl restart hivecast-nats.service hivecast-host.serviceThe journald rate-limit (200 msgs / 10s, capped at 2 GB total) is from the postinst — see Service install.
On a source-checkout / npm-style install
Use the wrapper.
Start
bash
hivecast start --home /tmp/matrix-homeWhat runs (startHostProduct at hivecast.mjs:1464-1509):
- Existing-Host short-circuit: if
host.status.jsonshowsstatus: "running"and the recorded pid is alive, the function returns that status and re-runsbootstrapDefaultHostRuntimes(idempotent — already-running runtimes are skipped). It does NOT spawn a new Host. - Start NATS sibling:
startNatsSibling(hivecast.mjs:654-685). If the pidfile already shows a live NATS, return as{ alreadyRunning: true, pid }. Otherwise spawnnats-server -c <conf>detached +unref+windowsHide, write the pidfile, wait up to 10s for the configured TCP port to accept connections. - Spawn the host-service supervisor: detached, stdio to
<MATRIX_HOME>/logs/host.{stdout,stderr}.log.MATRIX_HOST_HOMEis set in the child env. - Wait for
host.status.json: up to 15s. If the supervisor exits before writing it, throw"Matrix Host Service exited before writing running status". - Wait for the CLI to be ready: probe
host-service statusuntil it succeeds, up to 30s. - Bootstrap default runtimes: unless
HIVECAST_SKIP_DEFAULT_RUNTIMES=1or--no-default-runtimes.
Total cold-start budget: up to ~45s in the worst case. Typical is under 5s.
Stop
bash
hivecast stop --home /tmp/matrix-homeWhat runs (stopHostProduct at hivecast.mjs:1541-1593):
- Spawn
host-service stop --home <MATRIX_HOME>and wait for it to exit. Capture exit code; do not throw yet on failure. - Always run
stopNatsSibling(<MATRIX_HOME>)(hivecast.mjs:687-723) regardless of step 1's outcome. stopNatsSiblingreads the pidfile, sendsSIGTERM, waits up to 3s for the process to exit, escalates toSIGKILLif needed, removes the pidfile.- If host-service stop failed but NATS was successfully cleaned up, surface the host failure to stderr with NATS pid info.
The reason NATS is cleaned up unconditionally: even if the Host crashed, NATS is its own process with its own pidfile — it must come down for the next start to bind cleanly.
Source:
CLAUDE.mdmentions: "After commit4f733013(P1.30),stopcorrectly tears down the NATS sibling — earlier versions leaked it." Theawait stopNatsSiblingis what made stop reliable.
Restart
There is no hivecast restart. Use:
bash
hivecast stop --home /tmp/matrix-home
hivecast start --home /tmp/matrix-homeThe hivecast stop waits for NATS to actually exit before returning, so the immediate hivecast start will bind a clean port. Without that wait, you'd race a half-shutdown NATS still binding 4222 — see the comment block at hivecast.mjs:700-708.
If you only need to restart a runtime (not the whole Host), use:
bash
hivecast down <runtime-id> --home /tmp/matrix-home
hivecast up <package> --runtime-id <runtime-id> --startup auto --restart always --home /tmp/matrix-home…or invoke host.control directly to issue a runtime restart (target state — surfacing this through hivecast CLI is filed under launch readiness).
Behaviour on system reboot
.debinstall:hivecast-{nats,host}.serviceareWantedBy=multi-user.target; the postinstsystemctl enables them. The Host comes up automatically on reboot. Thehivecast-host-service-runshim runsbootstrap-default-runtimesafter the supervisor is healthy, bringing allstartup: autoruntimes back up.- Source-checkout install (no systemd): the Host does NOT auto-start. Run
hivecast start --home <MATRIX_HOME>after login. Wire it into your shell's startup if needed.
Behaviour on crash
If the host-service process crashes:
.debinstall: systemd seesRestart=on-failureand restarts it after 5s (RestartSec=5s). After 5 failures within 60s (StartLimitBurst=5,StartLimitIntervalSec=60), systemd stops trying.- Source-checkout install: nothing restarts it. You'll see stale
host.status.jsonandhost.pidfiles. Runhivecast startagain — the start path detects the stale pid and proceeds.
If a runtime crashes:
restart: alwaysruntimes are auto-restarted byhost-controlafter a brief backoff.restart: on-failureruntimes are restarted only if exit code != 0.restart: neverruntimes go tostatus: failedand stay there.
The runtimeRecordStaleReason function (hivecast.mjs:1200-1230) cross-checks: if a record says running but the pid is dead OR the pid belongs to a different process (different cmdline/cwd), the record is stale and the runtime is treated as failed.
See also
- Host install — what
hivecast installlays out before you can start anything. - Service install — the systemd unit detail.
- Logs — what to look at when start/stop hangs.
- Troubleshooting → Host not running — symptom-driven recipes.
Source:
projects/matrix-3/packages/hivecast/bin/hivecast.mjslines 1464-1509 (startHostProduct), 1541-1593 (stopHostProduct), 654-685 (startNatsSibling), 687-723 (stopNatsSibling), 1200-1230 (runtimeRecordStaleReason).