Linux Labs

Packages, services, and logs / Stage 8 of 13

Your own service unit and applying changes

Not running Starting usually ~20 s
Leave the lesson

Step 1 of 7 · on a machine · 6 min

The file and the process disagree

What you will learn

  • Read and write the sections of a service unit — what to start, as whom, and when to start it again.
  • Apply a unit change — daemon-reload for the description and a restart for the process.
  • Check the result by the service's live process, not just by the file.

The lab-worker report service ran as root, although it has no need for root. A colleague fixed the unit file, which now says User=student, and wrote: "done". Check which user the service runs as.

Exercise · look

Who runs lab-worker

Read the lab-worker unit file, see which user the service's process (the sleep program) runs as, and read the service summary.

First, predict

The unit file says User=student. What will ps print in the USER column for the sleep process?

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
Check yourself 1 question

Why does the lab-worker process run as root although the unit file says User=student?

  • The summary asks for systemctl daemon-reload, the command that rereads unit files, rather than for a reboot.

  • systemd works with this file: its path is on the summary's Loaded line, and the warning at the end says the file has changed.

  • systemd starts services as the user named in the loaded description. The summary points elsewhere: the file has changed and needs reloading.

The process was started from the old description with User=root, and systemd has not reread the new file yet, which is what the summary warns about.

Ubuntu 24.04
Loading…