Skilllibrary systemd-services
install
source · Clone the upstream repo
git clone https://github.com/merceralex397-collab/skilllibrary
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/merceralex397-collab/skilllibrary "$T" && mkdir -p ~/.claude/skills && cp -r "$T/10-cli-systems-and-ops/systemd-services" ~/.claude/skills/merceralex397-collab-skilllibrary-systemd-services && rm -rf "$T"
manifest:
10-cli-systems-and-ops/systemd-services/SKILL.mdsource content
Purpose
Write correct systemd unit files for services, timers, and socket activation with sandboxing and restart policies.
When to use this skill
- creating a
unit for a daemon or long-running process.service - replacing cron with a systemd
unit.timer - setting up socket activation for on-demand services
- hardening with
,ProtectSystem
, sandboxing directivesDynamicUser
Do not use this skill when
- doing general Linux admin — prefer
linux-ubuntu-ops - writing the application code itself — this is for the unit file
- managing Docker/Podman containers — they have their own process management
Procedure
- Create unit file —
(system) or/etc/systemd/system/myapp.service
(user).~/.config/systemd/user/ - Set ExecStart — full paths:
.ExecStart=/usr/local/bin/myapp --config /etc/myapp/config.toml - Configure restart —
,Restart=on-failure
,RestartSec=5
.StartLimitBurst=3 - Add sandboxing —
,ProtectSystem=strict
,ProtectHome=yes
,NoNewPrivileges=yes
.ReadWritePaths=/var/lib/myapp - Set user —
for stateless;DynamicUser=yes
with dedicated account for stateful.User=myapp - Timer (optional) —
withmyapp.timer
for scheduled runs.OnCalendar=*-*-* 02:00:00 - Enable —
.sudo systemctl daemon-reload && sudo systemctl enable --now myapp.service - Verify —
,systemctl status myapp
.journalctl -u myapp -f --no-pager
Service unit template
[Unit] Description=MyApp service After=network-online.target Wants=network-online.target [Service] Type=notify ExecStart=/usr/local/bin/myapp serve Restart=on-failure RestartSec=5 DynamicUser=yes StateDirectory=myapp ProtectSystem=strict ProtectHome=yes NoNewPrivileges=yes PrivateTmp=yes [Install] WantedBy=multi-user.target
Timer unit template
[Unit] Description=Run myapp backup daily [Timer] OnCalendar=*-*-* 02:00:00 Persistent=true RandomizedDelaySec=300 [Install] WantedBy=timers.target
Decision rules
if the service supportsType=notify
; otherwisesd_notify
.Type=simple- Always
for production — never leave defaultRestart=on-failure
.no
when no persistent UID is needed.DynamicUser=yes
makesProtectSystem=strict
read-only — allowlist with/
.ReadWritePaths=
auto-createsStateDirectory=myapp
with correct permissions./var/lib/myapp
References
- https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html
- https://www.freedesktop.org/software/systemd/man/latest/systemd.timer.html
Related skills
— managing the service after deploymentlinux-ubuntu-ops
— ExecStartPre scriptsbash
— application config file pathsconfig-files-xdg