Linux Labs

Inside the system: resources, kernel, processes / Stage 10 of 12

From GRUB to a target: how the system boots

Not running Starting usually ~20 s
Leave the lesson

Step 4 of 8 · on a machine · 6 min

Ordering and dependency

A service can sit in a queue waiting for another unit. At boot dozens of services wait for each other like this, and you can see the waiting on a running machine too — in systemd's start queue.

Exercise · look

See what the service is waiting for

The lab-report service has just been started, but it serves no reports. Look at systemd's start queue, at the state of lab-report and at its unit file.

First, predict

lab-report was started with systemctl start, yet its process is not there. What will the systemctl list-jobs start queue show?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in

A unit file has two kinds of links (in the Wiki). Start ordering is set by After= and Before=: "if both units are being started, this one starts after that one". On its own After= does not start the other unit. A dependency is set by Wants= and Requires=: "start that unit together with me". The difference is in failure: with Wants= the service starts even if that unit failed, with Requires= (and After= on the same unit) it does not, and the journal gets Dependency failed.

The usual thing is to write a pair: Wants= and After= — "start it and wait for it". That is how lab-report is built: Wants= started lab-cache, and After= keeps lab-report in the queue until lab-cache is done. Without After= both services would start at the same time. systemctl list-jobs shows the queue: running means the job is being carried out, waiting means it is waiting for others.

Check yourself 1 question

lab-cache crashed at startup. What happens to lab-report if its unit has Requires=lab-cache.service instead of Wants= (and After= as before)?

  • That is how Wants= behaves: the service starts even after a failure. With Requires= systemd cancels the start: systemctl start answers A dependency job … failed.

  • The service waits while lab-cache is starting. Once lab-cache has failed there is nothing left to wait for: with Requires= the lab-report job is cancelled.

Requires= is a hard dependency: if that unit did not start, this one does not either, and the journal says Dependency failed for lab-report.service. With Wants= lab-report would have started even after lab-cache failed.

Ubuntu 24.04
Loading…