systemd-service-units

verified

cae14f86-6065-4aa7-9cbe-96126eb0228c

Run long-lived services under systemd — unit files, hardening, environment, logging, and auto-restart.

Metadata

Skill ID
cae14f86-6065-4aa7-9cbe-96126eb0228c
Version
1
Owner
global
Tags
systemdlinuxservicedevopsprocess-management
Signature
verified
Integrity
OK
Content hash
cd68401b10f239f857992afd35ce0ab85da12d0432a804f5374b88f4095f4d97
Created
2026-08-05T18:29:01Z

Skill file

Raw skill file (markdown source)
# Running Services with systemd

Use when a self-hosted process must start on boot and auto-restart on crash.

## Unit file

```ini
[Unit]
Description=Skill Vault MCP server
After=network.target

[Service]
Type=simple
User=svc
WorkingDirectory=/opt/skill-vault
ExecStart=/opt/skill-vault/.venv/bin/skill-vault serve --transport streamable-http --host 127.0.0.1 --port 8000
Restart=on-failure
RestartSec=3
EnvironmentFile=/etc/skill-vault/svc.env

[Install]
WantedBy=multi-user.target
```

## Manage it

```bash
sudo systemctl daemon-reload
sudo systemctl enable --now skill-vault-mcp
sudo systemctl status skill-vault-mcp
sudo journalctl -u skill-vault-mcp -f
```

## Key options

- `Restart=on-failure` + `RestartSec` — crash recovery without a watchdog.
- `EnvironmentFile=` — keep secrets in a mode-0600 env file, not the unit.
- `User=`/`Group=` — run as an unprivileged user; **never run daemons as root**.
- `Type=simple` is right for a foreground process; `Type=notify`/`Type=forking`
  for daemons that signal readiness.

## Pitfalls

- After editing a unit you MUST `systemctl daemon-reload` or changes are ignored.
- If systemd is degraded/broken on the host, ship a no-systemd fallback (a plain
  run script) too — don't depend on systemd being healthy.
- A service that exits immediately with `Restart=on-failure` will still be
  retried; check `journalctl` for the real error.

Attached files