Rollbridge
Rollbridge is a Node.js process supervisor and local traffic switcher for zero-downtime deploys.
Nginx points at one stable Rollbridge proxy port. Deploy tooling asks Rollbridge to start a new release, health-check it, and switch new traffic to it. Retirement then continues asynchronously: HTTP/WebSocket connections and retained process generations drain independently after the deploy command returns.
Required jobs-generation contract: a release-scoped background-jobs
runtime is its own background-jobs-main plus worker pool. Rollbridge starts a
complete candidate generation before activation. After activation the retired
main stops schedules, new dispatch, and new worker handoffs, but remains with
its old workers to supervise every handoff it already made until all jobs and
workers settle. Old workers never move to the new main. Generations may overlap
for hours on separate ports, and neither deploy completion nor HTTP drain
completion waits for or kills them. See Background-job worker
deployment and the Velocious deployment
guide.
This is the required architecture, not evidence that every released runtime or
consumer config already implements durable recovery and release-reference
reporting; verify source and config before claiming compliance.
Install
npm install rollbridge
For local development in this repository:
npm install
npm run all-checks
Config
A Rollbridge config is a JavaScript module that export defaults a config
object. It can also export a function (sync or async) that returns the object,
which is handy for computing values from the environment. Write it in your
project's module system — export default for ESM ("type": "module") or
module.exports for CommonJS.
// rollbridge.js
export default {
application: "ticket-server",
control: {
path: "/tmp/rollbridge-ticket-server.sock"
},
statePath: "/var/lib/rollbridge/ticket-server.state.json",
ownerRecovery: {reconnectGraceMs: 30000},
proxy: {
host: "127.0.0.1",
port: 8182,
upstreamHost: "127.0.0.1",
healthPath: "/ping",
healthTimeoutMs: 120000,
drainTimeoutMs: 60000,
forceStopTimeoutMs: 10000
},
processes: [
{
id: "beacon",
policy: "service",
cwd: "{{releasePath}}",
command: "env VELOCIOUS_BEACON_PORT={{port}} npx velocious beacon",
port: 7330
},
{
id: "background-jobs-worker",
policy: "companion",
cwd: "{{releasePath}}",
env: {VELOCIOUS_BACKGROUND_JOBS_PORT: "{{ports.background-jobs-main}}"},
command: "npx velocious background-jobs-worker",
nonBlockingDrain: true,
gracefulStopMs: "indefinite",
outputLines: 200
},
{
id: "background-jobs-main",
policy: "service",
deployStrategy: "handoff",
cwd: "{{releasePath}}",
env: {VELOCIOUS_BACKGROUND_JOBS_LIFECYCLE_SOCKET: "{{releasePath}}/tmp/background-jobs-main.sock"},
command: "env VELOCIOUS_BACKGROUND_JOBS_PORT={{port}} npx velocious background-jobs-main",
lifecycle: {
activateCommand: 'npx velocious background-jobs:activate --generation "$ROLLBRIDGE_RELEASE_ID" --socket "$VELOCIOUS_BACKGROUND_JOBS_LIFECYCLE_SOCKET"',
activateTimeoutMs: 60000,
quietCommand: 'npx velocious background-jobs:retire --generation "$ROLLBRIDGE_RELEASE_ID" --socket "$VELOCIOUS_BACKGROUND_JOBS_LIFECYCLE_SOCKET"'
},
port: {from: 7331, to: 7399}
},
{
id: "web",
policy: "proxied",
cwd: "{{releasePath}}",
command: "npx velocious server --host 127.0.0.1 --port {{port}}",
port: {from: 18182, to: 18299},
health: {path: "/ping", timeoutMs: 30000}
}
]
}
The lifecycle socket path is illustrative; set it to the reviewed release-local
Velocious socket used by jobs-main.
Each process retains its most recent stdout/stderr lines and reports them in
status. Set outputLines (a positive integer, default 50) per process to keep
more or fewer lines for chatty or quiet processes.
Set control.mode to an octal permission string (for example "660") to
chmod the control socket after it binds. This restricts which users can send
control commands — useful when several deploy users share a group. When unset,
the socket keeps the default permissions from the daemon's umask. Pair it with
control.owner and control.group (a numeric id or a user/group name) to
chown the socket to a shared deploy group; names resolve via
/etc/passwd//etc/group, and the daemon must run as a user allowed to chown it.
Set the proxied process's health.startDelayMs (default 0) to wait that long
after the process starts before the first health probe — like a readiness
probe's initial delay, useful for apps with a known boot time. The delay runs
before the health.timeoutMs window begins.
Set a process's restart policy to control automatic restarts after a crash.
restart.maxRestarts caps how many restarts are allowed within restart.windowMs
before Rollbridge gives up and leaves the process failed (maxRestarts: 0
disables restarts entirely), while restart.backoffFactor — with an optional
restart.maxDelayMs cap — backs off the restartDelayMs delay on each successive
restart. With no restart block, a crashed process keeps restarting after
restartDelayMs, as before. See docs/config.md.
restart: {maxRestarts: 5, windowMs: 60000, backoffFactor: 2, maxDelayMs: 30000}
Set a process's memory policy to supervise its resident memory (RSS) and
gracefully restart it when it grows too large. memory.limitBytes is the RSS
limit (measured across the whole process group, not just the wrapper);
memory.warnBytes logs a warning before the limit; memory.checkIntervalMs
(default 5000) sets how often RSS is sampled. A memory restart is reported in
status and recorded in events (a process started with reason: "memory").
See docs/config.md.
memory: {limitBytes: 536870912, warnBytes: 402653184, checkIntervalMs: 5000}
Set a process's stopSignal (default "SIGTERM") to the signal it quiets on.
This is a process-level stop mechanism, not the primary deploy-completion
mechanism for a release-scoped jobs generation. A retired generation may remain
for hours, and its old jobs-main must stay available until its workers finish.
For example, a generic worker that drains on SIGINT:
{id: "worker", policy: "companion", command: "…", stopSignal: "SIGINT", gracefulStopMs: 60000}
Set replicas on a port-less companion to run a pool of identical workers.
Each instance runs as <id>#<index> (worker#0, worker#1, …) — visible in
status and targetable by rollbridge restart (base id for all, worker#0 for
one) — and gets {{replicaIndex}}/{{replicaCount}} and
ROLLBRIDGE_REPLICA_INDEX/_COUNT so each instance can pick a distinct shard or
queue. See docs/config.md.
{id: "worker", policy: "companion", command: "npx velocious background-jobs-worker", replicas: 4}
For generic workers that quiesce or drain via a command, set a lifecycle block —
Rollbridge runs quietCommand, then drains (drainCommand/drainTimeoutMs),
then stopCommand/stopSignal, then SIGKILL after gracefulStopMs when
gracefully stopping the process. Each hook is bounded so it can't wedge a stop.
Set nonBlockingDrain: true on a jobs worker companion so it stops accepting new
handoffs as soon as its release retires, independently of the proxied connection
drain. Its release-scoped handoff jobs-main remains running to supervise existing
handoffs and exits only after the worker pool has drained.
For a coordinator that starts quiescent, give the handoff jobs-main paired
lifecycle.activateCommand and quietCommand hooks. After candidate health,
Rollbridge activates the candidate, commits the active proxy target, and only
then starts the old generation's bounded retirement asynchronously. The durable
transition is
generation-scoped and resumable; failures remain visible and block unrelated
deploys. Post-commit singleton replacement is also journaled and must complete
before an exact retry reports success. If the active coordinator restarts,
Rollbridge restores its active role with the same bounded, generation-scoped
activation command before reporting it running. Set activateTimeoutMs when the
activation acknowledgement can exceed its 30-second default. Omit activateCommand to
preserve the existing hook-free ordering.
See docs/workers.md for the full release-generation
deployment pattern: a handoff background-jobs-main, its companion worker pool,
independent quiescence, and durable supervision while retained generations drain.
Set releaseRetention to bound how many stopped (drained) releases the daemon
keeps in memory and reports in status. keep (default 10) retains the most
recent stopped releases; maxAgeMs (default 0, disabled) also prunes stopped
releases older than that many milliseconds. The active and draining releases are
never pruned. This is Rollbridge's own release records — your deploy tool still
owns cleaning up on-disk release directories.
releaseRetention: {keep: 5, maxAgeMs: 86400000}
Set statePath to have the daemon persist sanitized recovery state to a file
(active/draining releases, process pids, counters, sanitized recent events).
Commands, environment mappings, child command lines, and captured process output
are deliberately excluded; those diagnostics remain available through the live
status/log/event APIs. Without ownerRecovery, the next startup reads any
leftover file and reports managed processes still alive from a daemon that
didn't shut down cleanly — advisory orphan detection. In that mode, after a crash run
rollbridge recover to list those leftovers and rollbridge recover --force to
stop them before restarting the daemon. A clean shutdown removes the file. See
docs/config.md.
statePath: "/var/lib/rollbridge/ticket-server.state.json"
For durable daemon process recovery and atomic owner replacement, opt into
ownerRecovery. Rollbridge
then runs a private local process guardian which remains the OS supervisor for
managed processes if the control daemon exits unexpectedly. A replacement using
the exact same normalized config/runtime reconnects within reconnectGraceMs,
reconstructs active and draining generations and their ports, and fences
concurrent replacements. If no replacement reconnects during that grace, the
guardian restarts the exact accepted daemon command and environment itself; the
recovery definition is kept only in the guardian's private authenticated state
and is refreshed atomically during a package/runtime replacement. A restart
attempt which cannot claim ownership and publish ready listeners within the
accepted startup timeout is terminated with its process group and retried with a
nonzero backoff. ensure-daemon can also prepare a requested
config/control-socket/package/runtime owner, prove it healthy, and atomically
transfer guardian authority while every retained generation keeps its exact
release reference and drains asynchronously. The old statePath is the durable
transaction anchor and cannot change during this handoff. The 0600 state file
contains the guardian capability; protect its directory accordingly.
Prepared transactions fence owner mutations and compare a monotonic guardian
state revision at staging. Existing HTTP/WebSocket connections remain owned by
the retired listener process, while their counts transfer to the new daemon so
later deploys continue to honor the original drain boundary.
If that new daemon itself exits while a retired listener still owns connections,
recovery conservatively retains the last authenticated transferred count until
the configured drain timeout; it never guesses that the older sockets closed.
An intermediate guardian which supports atomic owner replacement but predates
daemon recovery cannot be hot-upgraded because it is the existing processes' OS
supervisor. The upgrade fails before handoff and requires one explicit clean
shutdown followed by ensure-daemon; subsequent package/runtime replacements
remain atomic. A genuinely pre-replacement guardian still uses the separately
documented one-time disruptive compatibility bridge below.
A retained guardian that reports a different rollbridge version from the daemon
runtime is handed to a current-version coordinator through that same bridge, so
a package upgrade does not need a supervisor restart: the coordinator owns the
daemon and every process it starts, the retained guardian keeps the processes it
already owns, and nothing waits for those to drain. status.ownerTransition
reports mode: "guardian-version-handoff". The refusal is the last resort and
names both versions plus the exact shutdown/ensure-daemon commands. The
inventory comparison that gates that bridge, and the tombstone rule for
registrations of releases retention has already retired, are documented in
docs/owner-replacement-inventory.md.
There is one explicit compatibility boundary: the first upgrade from a genuine
pre-owner-replacement Rollbridge guardian and daemon cannot share its listeners
on supported Node 20. The same boundary applies to a retained transition guardian
that supports prepare/stage but predates the retired-owner commit command. After
an explicit capability probe and authentication of the guardian, exact daemon
PID/socket, runtime authority, and durable owned-process state, ensure-daemon
performs a one-time disruptive bridge. Existing proxy/control connections may close,
the retained processes keep their exact PIDs under guardian supervision, and
status.ownerTransition reports mode: "legacy-first-upgrade" with
disruptive: true. The bridge requires the existing config identity unchanged;
apply config/socket changes in a subsequent invocation, which uses the atomic
protocol. Unknown commands, auth/transport failures, malformed responses, and
identity mismatches fail closed without entering this bridge. Every replacement
after this protocol upgrade remains candidate-first and atomic.
statePath: "/var/lib/rollbridge/ticket-server.state.json",
ownerRecovery: {reconnectGraceMs: 30000}
During the first migration from an old supervisor, set legacyTakeover and run
rollbridge predeploy-cleanup --release-path <path> before rollbridge deploy.
Rollbridge will only stop configured legacy processes when no reusable active
Rollbridge release is running.
legacyTakeover: {
screens: ["ticket-server"],
processes: [
{name: "legacy web", includes: ["/home/dev/ticket-server/", "velocious server", "--port 8082"]}
]
}
A function export receives no arguments and lets you build the config at load
time:
// rollbridge.js
export default () => ({
application: process.env.APP_NAME || "ticket-server",
control: {path: `/tmp/rollbridge-${process.env.APP_NAME || "ticket-server"}.sock`},
proxy: {host: "127.0.0.1", port: 8182},
processes: [
{id: "web", policy: "proxied", cwd: "{{releasePath}}", command: "npx velocious server --port {{port}}", port: {from: 18182, to: 18299}}
]
})
Template variables
A process command, cwd, and env values support {{...}} placeholders
rendered when the process starts:
{{releasePath}}, {{releaseId}}, {{revision}}, {{application}}, {{processId}}
{{port}} — the port allocated to this process; {{ports.<id>}} — another process's allocated port
{{proxy.host}}, {{proxy.port}}, {{proxy.upstreamHost}}
{{env.<NAME>}} — a variable from the daemon's own environment, e.g. {{env.HOME}}
Referencing a placeholder with no value (including an unset {{env.<NAME>}})
fails the process start with a clear error, so typos surface immediately.
Docker Compose services
A delivery that also updates Docker Compose services (a Socketduct hub, a gateway
leg, a builder DinD) declares them in compose. Each unit is rolled with the
same handshake a process deploy uses — quiesce, wait for in-flight work, recreate
with the target image, gate on activation, roll back to the retained previous
image on failure — instead of a raw docker compose up -d --force-recreate: