What is systemd?
systemd is the modern init system and service manager used in Linux systems such as Fedora, Ubuntu, RHEL, Arch, Debian, etc.
Problems before systemd (SysVinit)
- Slow sequential boot
- No proper dependency management
- No unified logging
- Hard to supervise daemons
- Poor service recovery
Why systemd?
- Faster parallel boot
- Dependency control
- Integrated logging
- Easy service supervision
- Resource control with cgroups
- Socket & timer activation
What systemd does
- Acts as PID 1
- Starts services
- Manages dependencies
- Controls startup targets
- Handles system logging
- Manages resources
- Starts services on-demand
- Replaces cron for many tasks
Boot flow
- Kernel boots
- Kernel executes /sbin/init → systemd
- systemd loads default target
- Resolves dependencies
- Starts services in parallel
- System becomes usable
Systemd Units
Everything in systemd is a “unit”.
Types of units:
- .service → services
- .socket → socket activation
- .target → runlevel groups
- .timer → scheduled jobs
- .mount → mount points
- .swap → swap devices
- .device → hardware devices
- .path → filesystem event watches
Targets (Runlevel equivalents)
Runlevel mapping:
0 → poweroff.target
1 → rescue.target
3 → multi-user.target
5 → graphical.target
6 → reboot.target
Check default target:
systemctl get-defaultSet default target:
sudo systemctl set-default graphical.targetsystemctl (service control command)
Start / stop / restart services
sudo systemctl start SERVICE
sudo systemctl stop SERVICE
sudo systemctl restart SERVICE
sudo systemctl reload SERVICEStart and enable at boot:
sudo systemctl enable --now SERVICEDisable autostart:
sudo systemctl disable SERVICECompletely block service:
sudo systemctl mask SERVICEUnmask:
sudo systemctl unmask SERVICEService status and listing
Show status:
systemctl status SERVICEList running services:
systemctl list-units --type=serviceList installed service files:
systemctl list-unit-files --type=serviceList failed units:
systemctl --failedKill service processes:
sudo systemctl kill SERVICEForce kill:
sudo systemctl kill -s SIGKILL SERVICEService files locations
/usr/lib/systemd/system/ → package installed
/etc/systemd/system/ → admin installed
~/.config/systemd/user/ → per-user services
Example custom service
File:
/etc/systemd/system/myapp.service
Content:
[Unit]
Description=My App
After=network.target
[Service]
ExecStart=/usr/bin/python3 /opt/app/app.py
Restart=always
User=myuser
[Install]
WantedBy=multi-user.targetReload and enable:
sudo systemctl daemon-reload
sudo systemctl enable --now myappCgroups with systemd
Used for:
- resource limits
- isolation
- CPU control
- memory control
Commands:
systemd-cgls
systemd-cgtopSystemd timers (cron alternative)
List timers:
systemctl list-timersCreate timer unit:
/etc/systemd/system/backup.timer
Content:
[Unit]
Description=Run backup daily
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.targetCreate related service:
/etc/systemd/system/backup.service
Enable:
sudo systemctl enable --now backup.timerjournald and journalctl
journald = system logging system used by systemd
Log storage:
/var/log/journal/
journalctl usage
Show all logs:
journalctlFollow logs live:
journalctl -fLogs for current boot:
journalctl -bPrevious boot:
journalctl -b -1Logs for specific service:
journalctl -u nginxFollow service logs:
journalctl -u nginx -fLogs since specific time:
journalctl --since "2 hours ago"
journalctl --since yesterday
journalctl --since "2026-01-03" --until "2026-01-04"Logs by PID:
journalctl _PID=1234Logs by priority:
journalctl -p errPriority level meanings:
0 emerg
1 alert
2 crit
3 err
4 warning
5 notice
6 info
7 debug
Enable persistent logging
sudo mkdir -p /var/log/journal
sudo systemctl restart systemd-journaldDebugging with systemd
systemctl status SERVICE
journalctl -xe
journalctl -u SERVICESummary table
systemd → init and service manager
systemctl → command to control systemd
journald → logging service
journalctl → tool to read logs
Practical real-world uses
- debugging boot failures
- monitoring services
- log investigation
- running background applications
- replacing cron jobs
- server administration