systemd services: systemctl and journalctl basics
systemd starts and supervises services on most Linux servers. systemctl starts, stops and enables them; journalctl shows their logs.
Not checked by a trusted editor yet Last edited Outdated?
On Debian, Ubuntu, RHEL, Rocky Linux, AlmaLinux and most other current distributions, the first process the kernel starts is systemd. It starts everything else: the network, the SSH server, the web server, scheduled jobs. It also keeps watching those programs, restarts them if you tell it to, and collects their output in one log called the journal.
You talk to systemd with two commands: systemctl to control things and journalctl to read the logs.
Units: what systemd manages
Everything systemd manages is a unit, described by a small text file. The suffix tells you the type:
nginx.service: a program that runs, usually in the background (a daemon).backup.timer: a schedule that starts a service, like a cron entry.srv-data.mount: a mounted filesystem.multi-user.target: a group of units, roughly “the normal server state”.
Packages install their unit files under /usr/lib/systemd/system/ (on older Debian layouts also /lib/systemd/system/). Your own units and overrides belong in /etc/systemd/system/, which takes precedence.
Is it running? Start, stop, restart
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
systemctl status nginx # state, main PID, last log lines
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx # stop + start
sudo systemctl reload nginx # ask the program to re-read its config
systemctl is-active nginx # prints active / inactive / failed
systemctl --failed # every unit that is in the failed state
reload asks the service itself to re-read its configuration without stopping; not every service supports it. It does not re-read the unit file. That is a different command, shown below.
Start at boot: enable and disable
Starting a service and starting it at boot are separate things. enable creates the links that make the unit start at boot; it does not start it now unless you add --now.
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
sudo systemctl enable --now nginx # start now and at every boot
sudo systemctl disable nginx # no longer at boot (still running now)
systemctl is-enabled nginx
sudo systemctl mask nginx # make it impossible to start
sudo systemctl unmask nginx
Looking at and changing unit files
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
systemctl cat nginx # the unit file plus any drop-in overrides
sudo systemctl edit nginx # create a drop-in override (override.conf)
sudo systemctl daemon-reload # re-read unit files after editing them by hand
systemctl list-unit-files --type=service
Prefer systemctl edit over editing a packaged unit file directly: the override survives package updates. After editing any unit file by hand, run daemon-reload, or systemd keeps using the old version.
Reading logs with journalctl
Anything a service prints to stdout or stderr ends up in the journal, tagged with the unit name, so you rarely need to hunt for log files.
journalctl -u nginx # all logs for one unit
journalctl -u nginx -f # follow live, Ctrl-C to stop
journalctl -u nginx -n 50 # last 50 lines
journalctl -u nginx --since "1 hour ago"
journalctl -u nginx --since "2026-01-15 08:00" --until "2026-01-15 09:00"
journalctl -b # this boot only
journalctl -b -1 # the previous boot
journalctl -p err -b # errors and worse in this boot
journalctl -k # kernel messages (like dmesg)
journalctl -xeu nginx # jump to the end, with explanations
-ptakes a priority name or number:emerg(0),alert,crit,err,warning,notice,info,debug(7). One level includes everything more severe.-g PATTERN(--grep) filters the message text with a regular expression.-o short-isoprints exact timestamps;-o catprints only the message text;-o jsongives one JSON object per line for scripts.
Is the journal kept after a reboot?
If journalctl --list-boots shows only the current boot, logs are not being stored on disk. The Storage= option in /etc/systemd/journald.conf (or a drop-in under /etc/systemd/journald.conf.d/) controls this; with auto, logs persist only if /var/log/journal exists. Check how much space the journal uses, and trim it, with:
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
journalctl --disk-usage
sudo journalctl --vacuum-size=500M # delete oldest archived files above 500 MiB
sudo journalctl --vacuum-time=30d # delete archived files older than 30 days
Official documentation
See also
- 0165 Write a systemd service unit for your own app Turn any long-running program into a proper service: create a unit file, run it as an unprivileged user, restart it on failure… Intermediate · How-to · Linux Article Services & systemd 15 Oct 2026
- 0166 Replace a cron job with a systemd timer A systemd timer runs a service on a schedule like cron, but logs every run to the journal, can catch up missed… Intermediate · How-to · Linux Article Services & systemd 15 Oct 2026
- 0167 Fix: Job for nginx.service failed because the control process exited with error code systemctl prints this when a service's start command exits with an error. The real reason is in journalctl; for nginx it is… Intermediate · Fix · Linux Article Networking & firewalls · Services & systemd 15 Oct 2026
- 0168 Server health check script: disk, memory and failed units A dependency-free bash script that checks disk and inode usage, available memory, load, failed systemd units and pending reboots, and exits non-zero… Intermediate · Reference · Linux Script Disks, LVM & filesystems · Services & systemd 15 Oct 2026
- 0255 Build a monitoring stack with Prometheus, node_exporter and Grafana on one Linux server Install Prometheus and node_exporter as systemd services, scrape and query host metrics with PromQL, then add Grafana with a dashboard and an… Intermediate · Tutorial · Linux Article Prometheus & Grafana · Services & systemd 15 Oct 2026
- 0265 Turn a one-liner into a robust bash script: strict mode, options, logging, traps, locking and a schedule Grow a find-and-gzip one-liner step by step into a dependable bash script with strict mode, getopts, usage text, logging, error traps, dry-run,… Intermediate · Tutorial · Linux, macOS Article Services & systemd · Shell scripting 15 Oct 2026
Repos in the wild
- systemd: the Linux system and service manager systemd/systemd The source of systemd, the init system and service manager on most Linux distributions, together with journald, networkd, resolved, timers and the systemctl tool. GitHub
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Commitpedia +4,463 chars