Linux systemd: Beyond Basic Service Files
systemd manages more than services. Timers, socket activation, and resource control are powerful once you know them.
Key Insights
- systemd timers replace cron with better logging, dependency management, and randomized delays
- Socket activation starts services on-demand, reducing boot time and memory usage
- Resource control via cgroups lets you limit CPU, memory, and I/O per service
Timers Instead of Cron
# /etc/systemd/system/backup.timer
[Unit]
Description=Daily backup
[Timer]
OnCalendar=daily
RandomizedDelaySec=1h
Persistent=true
[Install]
WantedBy=timers.target
Socket Activation
# /etc/systemd/system/myapp.socket
[Unit]
Description=My App Socket
[Socket]
ListenStream=8080
[Install]
WantedBy=sockets.target
Resource Limits
[Service]
MemoryMax=512M
CPUQuota=50%
IOWeight=100
TasksMax=64