systemd units and systemctl
A systemd unit is a configuration object that systemd, the init system of most Linux distributions, manages: services, sockets, timers, mounts and more. Units are described by unit files such as /etc/systemd/system/<name>.service and controlled with the systemctl command.
1Unit types
.service runs a program, .socket starts a service when a connection arrives, .timer runs a unit on a schedule, .mount and .automount handle file systems, .target groups units into states such as multi-user.target.
2Where unit files live
Packages install units in /usr/lib/systemd/system (or /lib/systemd/system). Local changes belong in /etc/systemd/system, which takes precedence. systemctl edit <unit> creates a drop-in override instead of changing the packaged file.
3Everyday commands
systemctl status <unit> shows state and the last log lines. 'start', 'stop' and 'restart' act now; 'enable' and 'disable' control starting at boot; 'enable --now' does both. systemctl --failed lists failed units, and systemctl daemon-reload rereads unit files after changes.
How to check a failing service
- List failed units:
systemctl --failed - Show the state and recent messages:
systemctl status <unit> - Read the full log of this boot:
journalctl -u <unit> -b - After fixing the configuration:
sudo systemctl restart <unit>
Cautions
- Change packaged units with
systemctl edit, not by editing files in/usr/lib/systemd/system: updates overwrite them. - Do not disable units you do not know, such as systemd-journald or dbus.
Related articles
- journalctl and the systemd journalHow to read logs with journalctl, check how much space the journal uses and shrink it safely with --vacuum options.
- cron and crontabHow cron runs scheduled jobs, the five crontab time fields, where system cron files live and how systemd timers compare.
- logrotateWhat logrotate does, how its configuration in /etc/logrotate.conf and /etc/logrotate.d works, and how to test a rule safely.
Sources
- systemctl(1) man7.org
- systemd.unit(5) man7.org
- systemd.timer(5) man7.org
Last reviewed: