hub

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package hub starts and stops the embedded Fossil hub repo and the embedded NATS JetStream server that together form the orchestrator substrate documented in ADR 0023 and ADR 0024.

The package replaces the previous bash hub-bootstrap.sh / hub-shutdown.sh scripts. Callers no longer need `fossil` or `nats-server` on PATH; the servers run in-process via libfossil and nats-server/v2/server.

Two entry points:

Start(ctx, root, opts...) — idempotent. Creates .orchestrator/ if missing,
  seeds the hub from git-tracked files on first run, starts both servers,
  and writes pid files. With WithDetach(true) returns once both servers
  are accepting connections; otherwise blocks until ctx is canceled.
Stop(root) — sends SIGTERM to the pids written by Start and removes the
  pid files. Idempotent: missing or stale pid files are not an error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start

func Start(ctx context.Context, root string, options ...Option) error

Start brings up the orchestrator hub: a Fossil repository at .orchestrator/hub.fossil seeded from git-tracked files, a Fossil HTTP server on the chosen port, and an embedded NATS JetStream server.

Idempotent: if both pid files exist and the recorded processes are alive, Start returns nil immediately.

With WithDetach(true) the calling process fork-execs itself in "foreground" mode, waits for both servers to become reachable, and returns. The child outlives the caller and owns the servers; pid files reference the child. This is what `bones hub start --detach` uses so a shell can fire-and-forget the hub.

Without detach, Start blocks on ctx.Done(): the calling process is the hub. Pid files reference the calling process. On cancellation, both servers shut down cleanly and pid files are removed.

func Stop

func Stop(root string) error

Stop sends SIGTERM to the processes recorded in the pid files written by Start and removes those pid files. Missing pid files or stale pids are not an error: Stop is idempotent so callers can shut down without first checking whether Start has run.

As a safety, Stop will not signal the calling process. If the recorded pid is the same as os.Getpid(), Stop only removes the pid file. The foreground Start has its own ctx-cancellation path; signaling self would terminate the caller before it could clean up.

Types

type Option

type Option func(*opts)

Option configures Start.

func WithDetach

func WithDetach(d bool) Option

WithDetach controls Start's blocking behavior. When true, Start returns as soon as both readiness probes succeed; the servers continue running in goroutines until the process exits or Stop is called. When false (the default), Start blocks on ctx.Done() and shuts both servers down cleanly when ctx is canceled.

func WithFossilPort

func WithFossilPort(p int) Option

WithFossilPort overrides the Fossil HTTP port. The default is 8765.

func WithNATSPort

func WithNATSPort(p int) Option

WithNATSPort overrides the NATS client port. The default is 4222.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL