Start with the manager, not a startup script
When an administrator says “systemd,” they may mean the Linux service manager or the larger collection of tools shipped with it. Here the subject is the manager: when systemd runs as process ID 1, or PID 1, it brings up and maintains userspace services. Separate per-user managers can supervise an individual user's services. The systemd manual describes both roles. You normally ask the manager questions through its client, systemctl, rather than launch another systemd process yourself.
Start with one read-only question on a Linux machine booted with systemd: what is the state of multi-user.target? The final operand is a unit name, a name for something the manager controls. The .target suffix identifies a grouping and synchronization unit, not a program. This particular target represents the non-graphical multi-user system. The status command requests a human-readable report. The --no-pager flag prints directly instead of opening an interactive page viewer.
This installment uses the systemd 255 interface, checked against its upstream manuals and Ubuntu's 255.4-1ubuntu8.17 binaries. The disposable file and verification examples below ran with Bash 5.2.21 on Linux. The test container was not booted with systemd; live-manager commands are therefore documented inspection recipes, not captured executions. Their results depend on your host. No example starts a service, changes boot policy, or installs a unit.
systemctl --no-pager status multi-user.targetLook for Loaded, which describes loading the definition, and Active, which describes runtime state. A host that has reached this target will normally report it as active. Do not expect a service process ID for the target itself. A connection failure in a non-systemd container says nothing about the target's health on another machine. Even an inspection can cause a definition to be loaded into the manager's memory; “read-only” here means no requested activation or configuration change, not absolutely no internal state change.
A unit names a resource, not necessarily a process
Think of units as the manager's nouns. A .service describes supervised work; a .socket describes an endpoint that can activate work; a .timer or .path can trigger work when time passes or a filesystem condition changes. A .mount manages a mount point, .automount arranges on-demand mounting, .swap represents swap space, and .device represents a device exposed to the manager. A .target groups units. A .slice organizes resource-control groups, while a .scope groups processes created outside the service manager. These are the eleven unit types listed in the systemd manual.
Linux control groups, usually called cgroups, let systemd account for and control groups of processes. This matters when a service creates children: “the service” is not merely the one PID you happened to see. The systemd.resource-control manual describes the resource controls shared by services, scopes, and slices.
State has more than one dimension. A definition can be loaded while its unit is inactive. Active means the unit's activation contract is satisfied: a running service, a mounted filesystem, and a waiting timer need not have the same detailed state. Failed records an unsuccessful operation, not simply the absence of a process. Activating and deactivating describe transitions. The unit-specific substate adds detail. Before deciding that something should be restarted, first identify which resource and which state you are inspecting.
Read the two contracts before creating them
Our scenario is a preparation step followed by some work. First read the two proposed files as configuration, not shell commands. Both commands are deliberately /usr/bin/true, a program that does nothing and exits successfully. The filenames, relationships, and verification results are the experiment; no application behavior is being simulated. The filename comments beginning with # identify the two separate definitions below; systemd ignores comment lines.
A unit file has named sections and key=value settings, as documented in systemd.syntax. [Unit] holds general metadata and relationships; Description is its readable label. [Service] holds the service contract. Type=oneshot makes completion of the command part of startup. ExecStart specifies that command; it is not implicitly a shell script. RemainAfterExit=yes keeps the preparation unit logically active after successful completion, even with no remaining process. The work unit omits that setting and would return to inactive after its successful one-shot work. These are documented service semantics, not observed activations in this lab.
Requires names the preparation unit as a requirement, and After adds startup ordering. Keep those two lines distinct as you read; we will examine their separate effects after checking the files.
# clitdj-demo-prepare.service
[Unit]
Description=CLI demo preparation
[Service]
Type=oneshot
ExecStart=/usr/bin/true
RemainAfterExit=yes
# clitdj-demo.service
[Unit]
Description=CLI demo work
Requires=clitdj-demo-prepare.service
After=clitdj-demo-prepare.service
[Service]
Type=oneshot
ExecStart=/usr/bin/trueThese are two file definitions, not one combined file and not terminal commands. Nothing has been created or activated yet. The next block creates the two files with these settings, omitting only the filename comments and separating blank line.
Make a small contract you can inspect without running it
Check that /usr/bin/true and systemd-analyze are installed. Run the following fixture blocks in order in one disposable shell session. They create systemd-lab below your current directory and never place files in a manager's installation paths.
Mkdir creates the directory; cd enters it. Every setup operation is connected with &&, so failure stops the remaining setup. If systemd-lab already exists, choose a new name before starting; do not continue with later blocks. Export sets LC_ALL=C for predictable diagnostics in this shell and its child commands. Umask 022 removes group-write and other-write permission from newly created files and directories in this session, keeping the later permission check reproducible. Printf uses %s to print each following argument as text and \n to end its line. Single quotes protect each argument from shell interpretation. The shell's > creates the named file. The printf article explains why the fixed format and the supplied text are separate.
Systemd-analyze's verify command loads the supplied definitions and their dependencies for checking, without starting their commands. The ./ prefix means a file in the current directory. The --man=no option disables checking referenced manual pages; it does not disable unit verification. Its success is followed by a printed marker only because && guards that marker.
mkdir systemd-lab &&
cd systemd-lab &&
export LC_ALL=C &&
umask 022 &&
printf '%s\n' '[Unit]' 'Description=CLI demo preparation' '[Service]' 'Type=oneshot' 'ExecStart=/usr/bin/true' 'RemainAfterExit=yes' > clitdj-demo-prepare.service &&
printf '%s\n' '[Unit]' 'Description=CLI demo work' 'Requires=clitdj-demo-prepare.service' 'After=clitdj-demo-prepare.service' '[Service]' 'Type=oneshot' 'ExecStart=/usr/bin/true' > clitdj-demo.service &&
systemd-analyze --man=no verify ./clitdj-demo.service ./clitdj-demo-prepare.service &&
printf 'verification succeeded\n'verification succeededVerify itself was silent on success. It can detect missing required dependencies and missing or nonexecutable command paths, among other problems. It also consults normal unit search paths, so a differently provisioned host can report additional dependency problems. Passing is not proof that an application will work, that a service was started, or that its configuration is secure. The systemd-analyze manual defines this narrower checking contract.
Separate “include this” from “wait for this”
The two relationship lines answer different questions. Requires=clitdj-demo-prepare.service pulls preparation into activation of the work unit. After=clitdj-demo-prepare.service orders the work's startup after preparation's startup. With both, preparation failing to start prevents work from starting. After alone does not pull preparation in; Requires alone does not impose that order. Wants is a weaker inclusion dependency that allows the requesting unit's startup to proceed despite the wanted unit's failure. These distinctions come from systemd.unit, not the textual order of lines in a file.
Startup completion is defined by the unit's contract. For our oneshot preparation, it includes completion of /usr/bin/true. For a real long-running service, an ordering edge is not automatically an application-level readiness probe. Requires also does not mean “the other unit must remain active forever”; systemd.unit documents exceptions and stronger relationships for tighter lifetime coupling. Choosing the edge requires knowing the failure behavior you want.
Make the requirement visibly unsatisfied without executing either service. Mv renames our preparation file to a non-unit filename. The brace group keeps verification, immediate status reporting, and restoration behind the successful rename. Braces are shell grouping, not unit-file syntax. The shell parameter $? is the preceding command's exit status; double quotes permit its expansion as one argument. Run this in an ordinary shell without exit-on-error enabled: verification is intentionally expected to fail, and the next command restores the fixture.
mv clitdj-demo-prepare.service clitdj-demo-prepare.saved &&
{
systemd-analyze --man=no verify ./clitdj-demo.service
printf 'verification status=%s\n' "$?"
mv clitdj-demo-prepare.saved clitdj-demo-prepare.service
}clitdj-demo.service: Failed to create clitdj-demo.service/start: Unit clitdj-demo-prepare.service not found.
verification status=1The diagnostic is standard error; the status line is standard output, so a tool that captures the streams separately may display them differently. This observed failure concerns the verification process's dependency graph. It is not a failed live service or an executed startup-order test. The preparation file is restored afterward; stop if restoration reports an error. Diagnostic wording can vary by systemd release.
Give the group a name without inventing another daemon
Now add clitdj-demo.target. Its Wants line includes the work service. Targets have no [Target] settings section and need no ExecStart: their purpose is grouping and synchronization. The systemd.target manual explains an important default: a target normally orders itself after the units it wants or requires. Units that disable default dependencies are an exception. Our fixtures retain the defaults.
Consequently, the target's activation graph includes work, which requires preparation; its ordering places preparation before work and work before the target is reached. This is a prediction from the definitions and documented defaults, not a live timing measurement. Normal service units also acquire default initialization and shutdown dependencies, so these three files are not the entire graph. The systemd.service manual describes those automatic edges.
printf '%s\n' '[Unit]' 'Description=CLI demo group' 'Wants=clitdj-demo.service' > clitdj-demo.target &&
systemd-analyze --man=no verify ./clitdj-demo.target &&
printf 'target verification succeeded\n'target verification succeededVerification follows the target's dependencies; you do not need to list every file again. A reached target is not a continuing health certificate for everything it wanted. That distinction explains why a machine can reach multi-user.target while an optional service is broken. As systemd.special describes, standard targets name useful system milestones; they are not mutually exclusive numbered boot modes.
Separate disk contents, loaded configuration, and runtime state
There are three different questions behind “what configuration is this service using?” What files exist on disk? What definition has the manager loaded? What state has the managed resource reached? On a systemd host, inspect the familiar multi-user.target again. Show exposes properties; --property selects the named fields, and --all includes empty values. LoadState is definition-loading state; ActiveState is general runtime state; SubState gives type-specific detail. FragmentPath identifies the main definition, and DropInPaths identifies supplementary configuration files, called drop-ins.
Cat prints the backing main file and drop-ins with filename comments. It is a systemctl command here, not the separate cat utility. Its disk contents may differ from the manager's loaded understanding after an edit. The systemctl manual explicitly documents this distinction. Expect host-specific key=value properties followed by host-specific file text, not the fixture files: we have not installed those.
systemctl --no-pager --all --property=LoadState,ActiveState,SubState,FragmentPath,DropInPaths show multi-user.target
systemctl --no-pager cat multi-user.targetThese are read-only live-manager recipes. Conceptually, daemon-reload asks the manager to reread unit definitions and rebuild dependencies; it does not restart every service or reload each application's own configuration. Enable concerns installation relationships, often links that connect a unit to a target. It is not synonymous with start. An inactive enabled unit and an active unit without enablement are both possible. Keep file installation, manager configuration, and activation separate before selecting any state-changing command.
Find the definition that wins
Do not assume a unit's filename tells you which copy is in use. For ordinary system units, /usr/lib/systemd/system supplies vendor definitions, /etc/systemd/system supplies persistent local administration, and /run/systemd/system supplies runtime configuration. A same-named main file in /etc wins over /run, which wins over /usr/lib. The full path includes additional locations for generated, transient, and other units. Ask this installed implementation for its system-manager lookup paths with systemd-analyze unit-paths; no running manager is required.
The systemd.unit manual documents drop-in merging separately from main-file selection. A per-unit drop-in directory uses the unit's full name followed by .d and contains .conf files. Different .conf filenames are processed in lexical order; same-named drop-ins use directory precedence. A local drop-in can change selected settings while retaining vendor updates to the main file. Copying the whole vendor file locally instead shadows that main file. Settings do not all merge alike; dependency lists, for example, cannot be cleared with an empty assignment in a drop-in.
systemd-analyze unit-pathsOutput is an ordered list of search directories, one per line. On the tested installation it included /etc/systemd/system, /run/systemd/system, /usr/local/lib/systemd/system, and /usr/lib/systemd/system, among others. It lists potential paths, not proof that a particular unit exists there. Per-user managers have different paths and privileges. Do not apply this system-manager path list to a user's services, or infer the effective configuration from a single vendor file.
Inspect who can rewrite the contract
The same configuration model creates a useful authorized assessment question: can a less-trusted account change instructions consumed by a more-privileged manager? Unit and drop-in files are administrative input. For system services, the systemd.exec manual says the default execution identity is root unless configured otherwise. A writable trusted definition or replaceable command can therefore be consequential. This is an unsafe-configuration scenario, not evidence of a systemd vulnerability or exploitation in the wild.
Demonstrate the permission check only in our disposable fixture. Create a drop-in setting Environment=CLITDJ_LABEL=reviewed, a harmless environment-variable assignment for a prospective service process. It is not a shell assignment executed now. Chmod sets ordinary permission bits: 755 gives the owner read/write/search access to a directory and everyone else read/search; 775 additionally gives its group write permission; 644 gives the file owner read/write and others read-only access. Search permission on a directory permits pathname traversal. We deliberately make the drop-in directory group-writable while leaving its file non-group-writable.
GNU find 4.9.0 walks . (the current directory). Its -perm /022 test matches either group-write or other-write permission; the leading slash means any listed bit, a GNU form. The -print action outputs each matching path. As the find article explains, this examines metadata rather than file contents. We omit a regular-file filter deliberately: a writable directory can permit replacement of a file whose own mode appears safe. After the first scan, repair only our test directory and scan again.
mkdir clitdj-demo.service.d &&
printf '%s\n' '[Service]' 'Environment=CLITDJ_LABEL=reviewed' > clitdj-demo.service.d/20-label.conf &&
chmod 755 . &&
chmod 775 clitdj-demo.service.d &&
chmod 644 clitdj-demo.service.d/20-label.conf &&
find . -perm /022 -print &&
chmod 755 clitdj-demo.service.d &&
printf 'after repair:\n' &&
find . -perm /022 -print./clitdj-demo.service.d
after repair:Only the intentionally writable directory appeared; the second scan found no matching mode bits in this fixture. That is not a complete access-control audit. On an authorized host, inspect the actual selected files, parent directories, ownership, group membership, access-control lists, link destinations, and referenced executables or scripts. Determine whether a less-trusted identity can actually replace them and whether the manager would consume the change. Our lab's private parent directory may prevent another account from reaching it at all. We neither install this drop-in nor demonstrate privilege escalation. Fix real ownership and access policy deliberately; do not copy the lab chmod commands onto production trees.
Read a failure as a graph question
Return to the original target. The live-manager list-dependencies command displays requirement and related relationships; --all expands non-target units recursively too. The traversed relationship types do not all pull an inactive unit into startup, so this is not simply a list of units the target would start. Adding --after switches the question to ordering predecessors. Results vary with the host and loaded units. Neither display is a chronological boot trace, and the ordering view does not mean that every listed predecessor is pulled in by this target. The systemctl manual also cautions that the view is limited to loaded units, particularly important when searching reverse relationships.
systemctl --no-pager --all list-dependencies multi-user.target
systemctl --no-pager --all --after list-dependencies multi-user.targetWhen work does not happen, ask which unit should represent it, which definition was selected, what included it in the activation request, what ordered it, and which contract determined success. When it happens with surprising privileges, add who can modify that contract. Those questions are more useful than immediately reaching for restart. A unit file describes the request; the graph connects it to other requests; runtime state tells you what actually happened.