hub

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 17 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.

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 .bones/ 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 FossilURL added in v0.4.1

func FossilURL(root string) string

FossilURL returns the hub Fossil HTTP URL recorded for the workspace at root, or "" if no hub is currently running there.

Consumers (`bones up`, `swarm join/commit/close`, `tasks status`, etc.) read this rather than hardcoding 127.0.0.1:8765 so two bones workspaces can run concurrently with port allocations of their own.

func HubFossilPath added in v0.6.0

func HubFossilPath(root string) string

HubFossilPath returns the on-disk path of the hub fossil for the given workspace root. Use this rather than building the path literally in cli/ so verbs survive future layout changes.

func NATSURL added in v0.4.1

func NATSURL(root string) string

NATSURL returns the hub NATS URL recorded for the workspace at root, or "" if no hub is running.

func Start

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

Start brings up the orchestrator hub: a Fossil repository at .bones/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) (err 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 pins the Fossil HTTP port. Zero means "let the hub allocate per-workspace" (default behavior).

func WithNATSPort

func WithNATSPort(p int) Option

WithNATSPort pins the NATS client port. Zero means "let the hub allocate per-workspace" (default behavior).

Jump to

Keyboard shortcuts

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