Linux Labs

Packages, services, and logs / Stage 6 of 13

Services under systemd

Not running Starting usually ~20 s
Leave the lesson

Step 3 of 7 · on a machine · 6 min

The service journal

systemd records what happens to services. This step shows how to read the records of a single service.

Messages from services and from systemd itself go to the system journal, which journalctl reads:

bash
sudo journalctl -u cron -n 8 --no-pager   # last 8 records of cron

The -u option keeps the records of one unit, -n sets how many of the latest records to show, and --no-pager prints them straight to the terminal.

Note

Service and system records are readable by root and the adm and systemd-journal groups, while student sees only its own. That is why a service journal is read through sudo: without it, journalctl -u cron prints the hint Hint: You are currently not seeing messages from other users and the system and -- No entries --, and systemctl status prints the state with no journal lines.

Exercise · look

The records of both services

cron and nginx have just gone through the same crash as at the start of the lesson. Read the last eight journal records of each service.

Sign in and start The machine is available after signing in

systemd writes the crash records under its own name, systemd[1]:

Record What it means
Main process exited, code=killed, status=9/KILL the main process was killed by the KILL signal
Failed with result 'signal' the service went down; its state is failed
Scheduled restart job, restart counter is at 1 Restart=on-failure fired; this is restart number one
Started cron.service - … systemd started a new process for the service

The record Referenced but unset environment variable … EXTRA_OPTS appears every time cron starts: its ExecStart contains the variable $EXTRA_OPTS, nobody has set it, and systemd put an empty string in its place.

Ubuntu 24.04
Loading…