systemd
systemd is the init system and service manager used by most modern Linux distributions. As PID 1 it starts the system at boot and manages services, logging, timers, and mounts.
Understanding systemd
What Is systemd?
When the kernel finishes booting it starts exactly one process, PID 1, which starts everything else. On Ubuntu, Debian, RHEL, Amazon Linux, and others that process is systemd. It replaced SysV init's sequential shell scripts with declarative unit files, parallel startup, automatic restarts, and structured logs through journald.
How systemd Boots a System
systemd reads unit files, resolves their dependencies (After=, Requires=, Wants=), and starts independent units in parallel until it reaches the default target, usually multi-user.target on servers.
Unit files live in /usr/lib/systemd/system/ (installed by packages) and /etc/systemd/system/ (admin overrides, which take priority).
Common Unit Types
.service a daemon or one-shot task.timer scheduled run (alternative to cron).socket starts a service on first connection.mount a mount point.target a group of units, like a runlevel.path triggers on filesystem changesEssential systemctl Commands
sudo systemctl start nginxsudo systemctl stop nginxsudo systemctl restart nginxsudo systemctl reload nginx # re-read config if the unit supports itsudo systemctl enable --now nginx # start at boot and nowsudo systemctl disable nginx systemctl status nginxsystemctl list-units --type=service --state=failedsudo systemctl daemon-reload # after editing unit filessystemd-analyze blame # slowest boot unitsHow to Read Logs With journalctl
journalctl -u nginx -f # followjournalctl -u nginx -n 50 --no-pagerjournalctl -u nginx --since "1 hour ago"journalctl -u nginx -p err # errors and worsejournalctl -u nginx -xe # explanatory contextTroubleshooting systemd
| Symptom | Command | What to Look For |
|---|---|---|
| Service will not start | journalctl -u name -n 50 |
Last error output |
| Restart loop | systemctl status name |
Exit code, restart count |
| Unit edit ignored | sudo systemctl daemon-reload |
Reload required |
| Slow boot | systemd-analyze blame |
Longest units |
TipStart with
systemctl status name, thenjournalctl -u name -xefor the full story. Status often truncates the useful line.
Common MistakeEditing a packaged unit under
/lib/systemd/system. A package upgrade overwrites it. Usesystemctl edit nameto create a drop-in override instead.
RememberAfter changing any unit file, run
sudo systemctl daemon-reload. Until you do, systemd keeps using the old definition.
Frequently Asked Questions
What did systemd replace and why?
It replaced SysV init, and on some distributions Upstart. Those started services sequentially with shell scripts. systemd starts independent services in parallel, expresses dependencies declaratively, supports socket activation, and handles restarts and resource limits in unit files.
What is the difference between reload and restart?
Restart stops and starts the service, dropping connections. Reload asks the running service to re-read its configuration, typically through a signal such as SIGHUP configured in `ExecReload=`, and only works if the unit defines it.
Can systemd replace cron?
For many jobs, yes. Timer units add journal logging, dependency ordering, and catch-up of missed runs, though cron stays simpler for one-line recurring commands.