Skip to main content

Swamp Worker

@svendowideit/swamp-workerv2026.10.17.2· MIT· 7d agoBEHAVIORSWORKFLOWSACCEPTED WARNINGS
01README

Enlist a host as a swamp worker for one swamp serve orchestrator: install or upgrade it, reconcile its systemd user unit, mint its enrollment token, and report or remove exactly the worker this repo owns. WHAT IT DOES

Turns "make this host a worker for my serve" into repeatable swamp methods — and, for a single host, into one idempotent install-or-upgrade workflow. The model renders the worker's systemd user unit, writes it only when it changed, and starts it with enable --now plus loginctl enable-linger, so the worker survives logout and reboot. It mints a long-duration enrollment token to a 0600 file, and remove decommissions the worker: it revokes the token so it can never re-enrol, then deletes only its own namespaced artifacts. Every artifact is namespaced by identity, so this worker coexists with, and never touches, workers other repos install on the same host. For a set of hosts it also renders per-node provisioning and removal scripts. Prefer it over the built-in daemon, which allows only one worker per host.

INSTALL

swamp extension pull @svendowideit/swamp-worker

DEPENDENCIES

None installed on the host beyond the swamp binary itself and the host's own systemd (systemctl --user, loginctl). The host must have a running systemd user manager — systemctl --user must work (a live logind and user@<uid>.service with /run/user/<uid>) — or the ensure/provision steps fail. A site extension (@figy/swamp-worker) supplies the serve URL, node set and secret handling and drives this model over SSH. Linux only.

RUN

# Install or upgrade this host's worker in one idempotent run. `swampBinPath`
# MUST be the swamp binary on THIS host (token minting execs it) and `identity`
# must match the site's. Re-run to upgrade the binary and reconcile the unit.
swamp workflow run @svendowideit/swamp-worker-upgrade \
  --input serveUrl=wss://swamp.x1yoga.fi.gy \
  --input identity=figy --input swampBinPath=~/.local/bin/swamp

# Or use the methods directly: mint a token, then bring the unit up on this host.
swamp model method run worker mintToken --input duration=30d
swamp model method run worker ensureService \
  --input serveUrl=wss://swamp.x1yoga.fi.gy

# Inspect the desired unit without changing the host, then read its state.
swamp model method run worker renderUnit \
  --input serveUrl=wss://swamp.x1yoga.fi.gy
swamp model method run worker status

# Completely reverse it: `remove` revokes the token (disconnecting the
# worker), then stops, disables and deletes its artifacts.
swamp model method run worker remove

CONFIGURE

Global arguments (set at model creation with --global-arg key=value, or edited later with swamp model edit):

  identity        worker slug that namespaces every artifact   (worker)
  swampBinPath    absolute path to the swamp binary            (/usr/local/bin/swamp)
  repoDir         repo dir for local `swamp worker token`      (.)
  configDir       token/env file dir (0600)                    (~/.config/swamp-worker)
  cacheDirRoot    per-identity cache dir root                  (~/.local/share/swamp-worker)
  unitDir         systemd user unit dir                        (~/.config/systemd/user)
  swampHome       SWAMP_HOME in the unit                       (~/.swamp)
  swampConfigDir  SWAMP_CONFIG_DIR in the unit                (~/.config/swamp)
  concurrency     worker --concurrency                        (auto)
  enableLinger    run `loginctl enable-linger`                (true)
  otelSettingsModel  @svendowideit/otel-settings model to export to  ("" = off)
  otelServiceName    OTEL_SERVICE_NAME the worker reports      (swamp-worker)
  telemetryVault     vault holding the OTLP bearer token       ("")
  authRef            vault key for the bearer token            (OTEL_EXPORTER_OTLP_TOKEN)

swampBinPath is the setting that bites: it is exec'd on the orchestrator to mint and revoke tokens, so it must point at an existing swamp binary there — a per-user install is usually ~/.local/bin/swamp, not the /usr/local/bin/swamp default. It is also the path the provisioning script installs on each node, so on a set of hosts it must be writable and identical.

Telemetry: set otelSettingsModel to the @svendowideit/otel-settings model whose contract this site publishes (e.g. otel) and the worker unit gains the contract's OTEL_EXPORTER_OTLP_* env — so logs, metrics and traces export from every node, attributed to otelServiceName with a per-node host= resource attribute. Set telemetryVault/authRef when the gateway needs a bearer token. Empty (the default) leaves the unit untouched. Per call: renderUnit/ensureService take serveUrl, optional host, labels (KEY=VALUE strings), concurrency and force (ensureService also takes name); renderProvision takes serveUrl, host, labels, concurrency and version; renderRemoval takes nothing; install takes version and force; mintToken takes name (default <identity>-<hostname>), duration and force — one call per node; clearStagedTokens takes names; revokeToken takes name and purgeFile; remove takes name, revokeToken (default true) and purgeData.

UPGRADE

Install and upgrade are the same idempotent workflow: re-run @svendowideit/swamp-worker-upgrade to upgrade this host's swamp binary to version (default latest) and reconcile its unit. It needs no new inputs.

WHAT IT INSTALLS

On the host: a systemd user unit swamp-worker-<identity>.service, the worker's cache dir (holding the enrollment machine-id), and 0600 token and env files under configDir. When otelSettingsModel is set, the unit also carries the contract's OTEL_EXPORTER_OTLP_* env, so the worker exports logs, metrics and traces. It enables user lingering. It installs no cron triggers or webhooks of its own. remove revokes the enrollment token and deletes those artifacts and nothing else — foreign worker units are never enumerated or touched.

02Behaviors1
@svendowideit/swamp-workerv2026.10.17.2swamp_worker.ts

Global Arguments

ArgumentTypeDescription
identity?stringWorker identity slug. Namespaces every artifact (unit name, cache dir,
unitName?stringSystemd user unit name (without .service). Defaults to
swampBinPath?stringAbsolute path to the swamp binary the worker unit executes.
repoDir?stringRepository directory used for local `swamp worker token` calls.
configDir?stringDirectory holding the identity's token and env files (0600).
cacheDirRoot?stringRoot for per-identity worker cache dirs (each holds the machine-id the
stagingDir?stringOrchestrator-side dir where `mintToken` writes each node's token plaintext
unitDir?stringDirectory where systemd user unit files are written.
swampHome?stringSWAMP_HOME exported into the worker unit.
swampConfigDir?stringSWAMP_CONFIG_DIR exported into the worker unit.
releaseBaseUrl?stringBase URL for swamp release downloads when the binary is absent.
concurrency?stringWorker `--concurrency` ('auto' = CPU count, min 1).
enableLinger?booleanRun `loginctl enable-linger` so the user service survives logout/reboot.
otelSettingsModel?stringName of the @svendowideit/otel-settings model whose contract the worker
otelServiceName?stringOTEL_SERVICE_NAME the worker reports; the resource `service.name` is set
telemetryVault?stringVault holding the gateway OTLP bearer token (empty = unauthenticated).
authRef?stringVault key holding the gateway bearer token (a reference, never the secret).
fn renderUnit(serveUrl: string, host?: string, labels?: array, concurrency?: string, write?: boolean)
Render the worker's systemd user unit from the desired state and
ArgumentTypeDescription
serveUrlstringServe URL the worker dials.
host?stringHost label value. Defaults to this machine's hostname.
labels?arrayExtra scheduling labels as KEY=VALUE strings.
concurrency?stringOverride the global concurrency for this render.
write?booleanAlso write the unit file to disk (without reloading systemd).
fn renderProvision(serveUrl: string, host?: string, labels?: array, concurrency?: string, version?: string)
Render the per-node provisioning script (install the binary, lock the
ArgumentTypeDescription
serveUrlstringServe URL the worker dials.
host?stringHost label value. Empty fills each node's own hostname at install time, so
labels?arrayExtra scheduling labels as KEY=VALUE strings.
concurrency?stringOverride concurrency.
version?stringswamp release tag to install on the node; empty = latest.
fn renderRemoval()
Render the per-node removal script (stop, disable and delete the unit
fn install(version?: string, force?: boolean)
Ensure the swamp binary is installed at swampBinPath, downloading the
ArgumentTypeDescription
version?stringswamp release tag to install (empty = latest).
force?booleanReinstall even when the binary is already present.
fn clearStagedTokens(names?: array)
Delete the orchestrator-side staged token files for the given token
ArgumentTypeDescription
names?arrayEnrollment token names whose orchestrator-side staging files
fn mintToken(name?: string, duration?: string, force?: boolean)
Mint one enrollment token on the orchestrator and stage its plaintext
ArgumentTypeDescription
name?stringEnrollment token name — also names the 0600 orchestrator-side staging file
duration?stringToken lifetime (hard deadline), e.g. 24h, 7d, 30d.
force?booleanMint a fresh token even when one is already staged for this name. The old
fn revokeToken(name?: string, allGenerations?: boolean, purgeFile?: boolean)
Revoke this target's enrollment token(s) on the orchestrator (any
ArgumentTypeDescription
name?stringEnrollment token name to revoke (the target's base name, or an exact
allGenerations?booleanAlso revoke every rotation generation of this name (`<name>-g<gen>`), so a
purgeFile?booleanAlso delete the local token file, so the revoked token cannot be reused.
fn ensureService(serveUrl: string, host?: string, labels?: array, concurrency?: string, name?: string, force?: boolean)
Reconcile this host onto the desired worker state: install a pending
ArgumentTypeDescription
serveUrlstringServe URL the worker dials.
host?stringHost label value. Defaults to this machine's hostname.
labels?arrayExtra scheduling labels as KEY=VALUE strings.
concurrency?stringOverride concurrency.
name?stringEnrollment token name whose staged plaintext to install before starting
force?booleanRestart the unit even when nothing changed.
fn status()
Report live unit state and whether this identity's workers are
fn remove(name?: string, revokeToken?: boolean, purgeData?: boolean)
Completely decommission this identity's worker: revoke its enrollment
ArgumentTypeDescription
name?stringEnrollment token name to revoke and whose staged file to drop. Defaults to
revokeToken?booleanAlso revoke the enrollment token on the orchestrator (a complete
purgeData?booleanAlso delete the identity's cache dir and token/env files.
fn guidance()
Print every global option with its current value, so a setting can

Resources

unit(infinite)— Rendered swarm worker systemd user unit (desired state).
install(infinite)— swamp binary presence and install outcome.
token(infinite)— Enrollment token metadata, keyed by token name (never the secret
provision(infinite)— The rendered per-node provisioning script a site workflow ships to each
removal(infinite)— The rendered per-node removal script a site teardown ships to each node
worker(infinite)— Result of reconciling the worker unit on this host.
status(infinite)— Live systemd + enrollment status for this identity.
03Workflows1
@svendowideit/swamp-worker-upgrade976dbca6-caf8-4b0d-a27b-bc05de09d035

Install or upgrade this host's swamp worker in one idempotent run — the same command whether the worker is absent or already present. On a fresh host it mints a token, installs the swamp binary, writes the systemd user unit and starts it. On a host that already runs the worker it upgrades the swamp binary to the requested release and reconciles the unit, restarting only when the unit or token changed. Every step is idempotent, so re-running is always safe and changes only what differs. The `id

install-or-upgradeMint if needed, install/upgrade the binary, reconcile the unit, report.
1.token— Ensure an enrollment token exists for this identity and host. Reuses an already-staged token, so re-running never mints a second one.
2.install— Install the swamp binary when it is absent, or upgrade it to the requested release when it is present and differs.
3.reconcile— Install the staged token, write the unit only if it changed, enable it with linger, and restart only when the unit or the token changed.
4.status— Report the live unit state and whether this identity's worker is enrolled, so the run ends on verified reality rather than intent.
04Previous Versions1
2026.10.17.1MIT

Added 1 workflows

05Stats
A
100 / 100
Downloads
5
Archive size
55.9 KB
  • Has README or module doc2/2earned
  • README has a code example1/1earned
  • README is substantive1/1earned
  • Most symbols documented1/1earned
  • No slow types (deprecated)1/1earned
  • Dependencies pass trust audit2/2earned
  • Has description1/1earned
  • Platform support declared (or universal)2/2earned
  • License2/2earned
  • Verified public repository2/2earned

07Platforms