Systemd Service
Generic systemd user service management: idempotently create, start, stop, restart, and remove a persistent user service for any command line — and audit every service model against the live host in one call. WHAT IT DOES
A thin, generic wrapper around systemctl --user and unit-file rendering.
You give it a service name and the exact command line to run, and it stands
up a persistent background service — idempotently, so re-running is safe. It
is the reusable building block other extensions call to keep a long-lived
process (a web service, an API, a queue server) alive: rather than embedding
systemd logic in every extension, they invoke this model's methods. Because
these are user units, startService also enables user lingering so the
service starts at boot, not merely at login. The audit method answers
"what does swamp expect, what actually exists, and what state is it in?" in
one command: every model of this type, its systemd unit state, declared and
live TCP ports, stale reported state, drift, and orphan managed units.
INSTALL
swamp extension pull @svendowideit/systemd-serviceDEPENDENCIES
None. It shells out to systemctl --user, loginctl, and (for audit) ss
and cgroup v2, which ship with systemd; no other extension, package, or
service is required.
RUN
# Create (or update) the unit for feedback-server and start it at boot.
swamp model @svendowideit/systemd-service method run createService feedback-server \
--input 'serviceName=feedback-server' \
--input 'command=~/.swamp/deno/deno run --allow-net scripts/feedback-server.ts' \
--input 'workingDirectory=~/.swamp/pulled-extensions/@svendowideit/news/files'
swamp model @svendowideit/systemd-service method run startService feedback-server \
--input 'serviceName=feedback-server'
# Check it, restart it (e.g. after replacing its executable), stop it, or
# remove it entirely.
swamp model @svendowideit/systemd-service method run status feedback-server
swamp model @svendowideit/systemd-service method run restartService feedback-server \
--input 'serviceName=feedback-server'
swamp model @svendowideit/systemd-service method run stopService feedback-server \
--input 'serviceName=feedback-server'
# Audit every service model against the live host in one call: each
# model, its systemd unit, state, ports, drift, and orphan units.
swamp model @svendowideit/systemd-service method run audit feedback-server
swamp data get feedback-server audit --json
# Or run the bundled workflow, which needs no model name and prints an
# aligned table to the log (default: every model; --input service=… for one).
swamp workflow run @svendowideit/systemd-service-audit
swamp workflow run @svendowideit/systemd-service-audit \
--input service=feedback-serverCONFIGURE
Global arguments (set at model creation with --global-arg):
denoPath Path to the Deno binary for Deno services (default ~/.swamp/deno/deno)
unitDir Directory for systemd user unit files (default ~/.config/systemd/user)
cgroupRoot cgroup v2 mount point used by `audit` (default /sys/fs/cgroup) Per-call overrides on createService: command, description,
workingDirectory, environment, restart, restartSec, after,
wants, and force. startService takes linger (default true) to
control whether user lingering is enabled. restartService restarts a
running (or stopped) unit and verifies it is active — use it after
replacing the service's executable, which enable --now does not restart.
audit takes one optional input, serviceName (default all): all
reports every model of this type, any other value limits the report to the
model whose name or managed unit matches it and errors if none is found.
The bundled workflow exposes this as --input service=….
WHAT IT INSTALLS
A single systemd user unit file per service at <unitDir>/<name>.service.
startService enables the unit and user lingering so it starts at boot.
restartService restarts it in place. removeService deletes the unit
file. Nothing else is installed.
Global Arguments
| Argument | Type | Description |
|---|---|---|
| denoPath | string | Path to the Deno binary used to run Deno services (defaults to swamp's bundled Deno) |
| unitDir | string | Directory where systemd user unit files are written |
| cgroupRoot | string | Mount point of the cgroup v2 hierarchy, used by `audit` to map a unit to its processes |
| Argument | Type | Description |
|---|---|---|
| serviceName | string | systemd user service name (without the .service suffix) |
| command | string | Full command line the service runs (e.g. ~/.swamp/deno/deno run --allow-net scripts/feedback-server.ts) |
| description? | string | Human-readable description for the [Unit] section |
| workingDirectory? | string | Working directory for the service (WorkingDirectory=) |
| environment | array | Environment variables as KEY=VALUE strings (Environment=) |
| restart | string | Restart= policy (e.g. on-failure, always, no) |
| restartSec | string | RestartSec= delay between restarts |
| after | array | After= dependencies |
| wants | array | Wants= dependencies |
| force | boolean | Rewrite the unit file even if it already matches |
| Argument | Type | Description |
|---|---|---|
| serviceName | string | systemd user service name (without the .service suffix) |
| Argument | Type | Description |
|---|---|---|
| serviceName | string | systemd user service name (without the .service suffix) |
| Argument | Type | Description |
|---|---|---|
| serviceName | string | systemd user service name (without the .service suffix) |
| Argument | Type | Description |
|---|---|---|
| serviceName | string | Which service(s) to audit: 'all' (default) reports every model of this type; any other value audits only the model whose name or managed unit matches that service name, and errors if none is found |
Resources
Audit systemd-service models and units, printing an aligned table to the log. Runs @svendowideit/systemd-service `audit` via direct type execution, so no model instance name has to be known or typed. By default it reports every systemd-service model on the host: live systemd unit state, declared and listening TCP ports, stale reported state, drift, and orphan managed units. Set `service` to audit a single model or managed unit instead — the run fails if that service is not found, so a typo is n
Modified 1 behaviors. Added 1 workflows
- 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
- License1/2partial
no SPDX license declared
- Verified public repository2/2earned