Skip to main content

Systemd Service

@svendowideit/systemd-servicev2026.10.02.1· 24d agoBEHAVIORSWORKFLOWS
01README

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-service

DEPENDENCIES

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-server

CONFIGURE

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.

02Behaviors1
@svendowideit/systemd-servicev2026.10.02.1systemd_service.ts

Global Arguments

ArgumentTypeDescription
denoPathstringPath to the Deno binary used to run Deno services (defaults to swamp's bundled Deno)
unitDirstringDirectory where systemd user unit files are written
cgroupRootstringMount point of the cgroup v2 hierarchy, used by `audit` to map a unit to its processes
fn createService(serviceName: string, command: string, description?: string, workingDirectory?: string, environment: array, restart: string, restartSec: string, after: array, wants: array, force: boolean)
Idempotently write (or update) a systemd user service unit and daemon-reload
ArgumentTypeDescription
serviceNamestringsystemd user service name (without the .service suffix)
commandstringFull command line the service runs (e.g. ~/.swamp/deno/deno run --allow-net scripts/feedback-server.ts)
description?stringHuman-readable description for the [Unit] section
workingDirectory?stringWorking directory for the service (WorkingDirectory=)
environmentarrayEnvironment variables as KEY=VALUE strings (Environment=)
restartstringRestart= policy (e.g. on-failure, always, no)
restartSecstringRestartSec= delay between restarts
afterarrayAfter= dependencies
wantsarrayWants= dependencies
forcebooleanRewrite the unit file even if it already matches
fn startService()
Start and enable a systemd user service, enable user lingering so it runs at boot, and verify it is active
fn stopService(serviceName: string)
Stop a systemd user service
ArgumentTypeDescription
serviceNamestringsystemd user service name (without the .service suffix)
fn restartService(serviceName: string)
Restart a systemd user service so it picks up a replaced executable or an updated unit, and verify it is active
ArgumentTypeDescription
serviceNamestringsystemd user service name (without the .service suffix)
fn removeService(serviceName: string)
Stop, disable, delete the unit file, and daemon-reload for a systemd user service
ArgumentTypeDescription
serviceNamestringsystemd user service name (without the .service suffix)
fn status()
Report active/enabled state of a systemd user service
fn audit(serviceName: string)
List every systemd-service model alongside its live systemd unit state and listening ports, from one call
ArgumentTypeDescription
serviceNamestringWhich 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

service(infinite)— systemd user service status
create(infinite)— Last createService result
audit(infinite)— Every model of this type, its systemd unit, state, and ports
03Workflows1
@svendowideit/systemd-service-audite4dd31e9-f80f-4546-b2c1-c77d6249d2c6

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

mainAudit systemd-service models/units and log a table.
1.audit— Run audit on an auto-managed "systemd-service-audit" instance and print the table to the log.
04Previous Versions4
2026.10.02.1

Modified 1 behaviors. Added 1 workflows

2026.09.24.1
2026.09.11.1
2026.09.10.1
05Stats
A
93 / 100
Downloads
49
Archive size
29.6 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
  • License1/2partial

    no SPDX license declared

  • Verified public repository2/2earned
06Platforms