| name | systemd-manager |
| description | Create and manage systemd services, timers, and socket units. Use when creating background services or daemons, setting up scheduled timers, debugging failed units, viewing unit logs, or managing service dependencies. |
| category | system |
| maturity | stable |
| tags | ["systemd","timers","journalctl","unit-files","daemons"] |
Systemd Manager Skill
Create and manage systemd services, timers, and socket units.
Use When
- Creating background services or daemons
- Setting up scheduled timers (modern cron alternative)
- Debugging failed units or viewing logs
- Managing service dependencies and ordering
Quick Reference
Service Management
sudo systemctl start myapp
sudo systemctl stop myapp
sudo systemctl restart myapp
sudo systemctl reload myapp
sudo systemctl enable myapp
sudo systemctl enable --now myapp
systemctl status myapp
systemctl is-active myapp
systemctl is-enabled myapp
systemctl list-units --type=service
systemctl list-units --type=service --state=failed
systemctl cat myapp
sudo systemctl daemon-reload
Journalctl (Logs)
journalctl -u myapp
journalctl -u myapp -f
journalctl -u myapp -n 100
journalctl -u myapp --since "1 hour ago"
journalctl -u myapp --since "2024-01-15 09:00"
journalctl -u myapp -p err
journalctl --disk-usage
sudo journalctl --vacuum-size=500M
journalctl -b
journalctl -b -1
journalctl -k
Timers (Cron Replacement)
systemctl list-timers --all
systemd-analyze calendar "Mon *-*-* 09:00:00"
systemd-analyze calendar "*:0/15"
Debugging
systemctl status myapp
journalctl -u myapp -n 50 --no-pager
systemctl list-dependencies myapp
systemd-analyze blame
systemd-analyze critical-chain myapp.service
systemd-analyze verify /etc/systemd/system/myapp.service
systemctl show myapp
Helper Scripts
Generate service unit file
bash scripts/gen-service.sh <name> <exec-start> [--user <user>] [--workdir <dir>] [--env "KEY=VAL"]
Generate timer unit
bash scripts/gen-timer.sh <name> <calendar-expr> [--description "desc"]
Check service status summary
bash scripts/status-check.sh [service-name|--failed]
Unit File Patterns
Simple Service
[Unit]
Description=My Application
After=network.target
[Service]
Type=simple
User=myuser
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/node index.js
Restart=on-failure
RestartSec=5
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
Service with Environment File
[Service]
EnvironmentFile=/etc/myapp/env
ExecStart=/opt/myapp/bin/server
Oneshot (run once, e.g. for timers)
[Service]
Type=oneshot
ExecStart=/opt/scripts/backup.sh
Timer + Service Pair
[Unit]
Description=Run backup daily
[Timer]
OnCalendar=daily
Persistent=true
RandomizedDelaySec=300
[Install]
WantedBy=timers.target
[Unit]
Description=Backup job
[Service]
Type=oneshot
ExecStart=/opt/scripts/backup.sh
Hardened Service
[Service]
ProtectSystem=strict
ProtectHome=true
NoNewPrivileges=true
PrivateTmp=true
ReadWritePaths=/var/lib/myapp
CapabilityBoundingSet=
SystemCallFilter=@system-service
Common Options
| Option | Values | Purpose |
|---|
| Type | simple, forking, oneshot, notify | Process type |
| Restart | no, on-failure, always, on-abnormal | When to restart |
| RestartSec | 5 | Delay between restarts |
| WantedBy | multi-user.target, timers.target | Install target |
| After | network.target, postgresql.service | Ordering |
| Requires | postgresql.service | Hard dependency |
| Wants | redis.service | Soft dependency |