Skip to content
← Systems Foundations

Learning bite

systemd units and lifecycle

Separate service configuration, startup, readiness, and boot enablement.

  • Linux
Documentation reviewed2026-10-26 · 3 min read
  1. Why
  2. Predict
  3. Try
  4. Inspect
  5. Explain
  6. Save evidence

Predict before you try

Predict the lab: if ExecStart=/usr/bin/false, will enabling the unit repair it?

Try it: Put a process under a manager →
On this page

Put a process under a manager

A service manager starts work, tracks its exit, and can restart it according to a policy. On many Linux distributions that manager is systemd. A unit is its named configuration for a service, timer, socket, mount, or another managed object. A service unit explains what to run and under which conditions.

Inside the Ubuntu machine, check ps -p 1 -o comm=. The system-level commands below assume PID 1 is systemd; they do not apply to macOS or to a minimal application container. A user service uses a separate per-user manager through systemctl --user.

Ask four separate questions

QuestionRelevant operationWhat it does not establish
Is it running now?start, stop, statusWhether it starts after the next boot
Is future activation configured?enable, disable, is-enabledCurrent success or failure
Has the unit definition been reread?daemon-reloadApplication configuration has reloaded
Can it serve the intended request?Application-level checkThis cannot be inferred from enablement

restart stops then starts a service. reload asks the application to reread its own configuration when supported. enable --now combines activation configuration with immediate start. Repeating enable cannot fix an invalid ExecStart command.

Inspect existing units without restarting them:

bash
systemctl --failed --type=service
systemctl list-units --type=service --state=running

Choose one actual listed name and substitute it for SERVICE.service:

bash
systemctl status SERVICE.service --no-pager
systemctl cat SERVICE.service
systemctl show SERVICE.service -p MainPID -p ActiveState -p SubState
systemctl is-enabled SERVICE.service

The status display's Loaded line describes the definition and enablement; Active describes current state. MainPID identifies the main process when one exists. A disabled unit may be running because someone started it, while an enabled unit may have failed. is-enabled can report other states such as static; not every unit is designed for direct enablement.

Read a unit as instructions

This is a complete small oneshot unit, used as a reading example here and installed as a separate user fixture in the lab:

ini
[Unit]
Description=Study one-shot check

[Service]
Type=oneshot
ExecStart=/usr/bin/true

[Unit] contains general description/dependencies. [Service] defines service execution. true performs no work and exits 0. A successful oneshot normally becomes inactive when done unless configured to remain active, so “inactive” is not sufficient evidence of failure. A long-running foreground web server uses a different lifecycle; Type=exec, simple, or notify have different startup/readiness semantics.

For a system service, User= and Group= choose credentials; WorkingDirectory= defines relative-path context; EnvironmentFile= can supply environment values; and ExecStart= chooses the program and arguments. ExecStart is not an arbitrary shell command line: shell pipes and > need an explicitly invoked shell. A per-user unit already runs under that user; do not copy a system unit's root assumptions into it.

After= orders units but does not itself pull them in or prove a dependency is ready to answer application requests. Restart=on-failure can help with an unexpected exit, but a consistently invalid configuration may simply fail repeatedly. Start-rate controls belong to [Unit]. Understand the first failure before adding more retries.

Change definitions without losing the original

Packaged definitions typically live in distribution-managed locations. Local drop-ins can override selected settings without editing a vendor file; systemctl cat includes them for inspection. After a unit edit, use daemon-reload, then perform the appropriate start/restart. List-valued directives such as ExecStart can require clearing the old value in an override before setting the replacement.

A timer can trigger a service on a schedule; it does not require an always-running loop in your script. Timer/calendar configuration and advanced service sandbox settings are optional extensions after this module.

Predict the lab: if ExecStart=/usr/bin/false, will enabling the unit repair it? No: false deliberately exits unsuccessfully. If changed to true, must a PID remain afterward? No: successful oneshot completion is the desired result. Next, use the journal to inspect that result over time.

Apply this to MicroBank

The user-unit fixture teaches how a manager runs a command. Keep it separate from MicroBank application deployment: the later selected profile may use containers and their own supervision. Record who starts and restarts each proposed component. A successful unit command or an enabled unit is not evidence that Accounts can accept a request and Ledger can process it.

Keep this observation in the MicroBank readiness project.

Sources

Primary references: systemd service units↗; systemctl↗.

Prove what you learned

Inspect the result

Retain exit/status evidence and the same behaviour check after recovery.

Explain it in your own words

Explain why your observation supports the stated outcome, and name one thing it does not prove.

Try a small variation

Change one fixture start condition and predict its effect before rerunning the same check.

Your evidence should show

  • Record the context/revision or label the work as a paper or prepared fixture.
  • Compare the prediction with the actual result from “Put a process under a manager”.
  • Retain exit/status evidence and the same behaviour check after recovery.
  • Explain the transfer challenge and retain the same verification question.
Hint

Compare the manager result, current process state and application response.

Answer guide: compare after predicting

No: false deliberately exits unsuccessfully. If changed to true, must a PID remain afterward

Compare this with your actual observation. A paper answer is useful reasoning practice; record execution separately.

Recall the caller and endpoint from the browser request exercise. Revisit the previous lesson.

Save the prediction, result and explanation ↓

Your notes and evidence

Record observations, questions, or links to your work. Keep credentials out of your notes.

Loading saved progress…

Back up or restore this path

Progress and notes stay in this browser. A backup contains only this learning path.