Systemd
This section covers core systemd concepts, service unit management, dependency types (Wants vs. Requires), socket activation, drop-in override files, and troubleshooting unit states for RHCSA preparation.
Theory Questions
1 & 12. How do you display all service units currently loaded on the system?
Use systemctl list-units filtered by unit type.
- Command(s):
systemctl list-units --type=service --all - Why:
list-unitsqueries active and inactive units currently loaded into system memory;--type=servicelimits output strictly to service units, and--allincludes stopped or inactive services. - Gotchas: Running
systemctl list-unit-filesreads unit files stored on disk rather than showing what is currently loaded in active system memory. - Verify:
systemctl list-units --type=service --all | head -n 10
2. How do “Wants” dependencies function in Systemd?
Wants= defines a weak dependency where failure of the target unit does not stop the requesting unit from starting.
- Command(s):
systemctl show <unit> -p Wants - Why:
Wants=signalssystemdto attempt starting the specified dependency, but execution continues even if that dependency fails to initialize. - Gotchas: Do not confuse
Wants=withRequires=. If aRequires=dependency fails, the primary unit startup fails immediately. - Verify:
systemctl show multi-user.target -p Wants
3. How do you prevent conflicts between incompatible Systemd units?
Use the Conflicts= directive within the [Unit] section of the unit file.
- Command(s):
systemctl show <unit> -p Conflicts - Why:
Conflicts=enforces mutual exclusion. If unit A is started, any running unit listed in itsConflicts=setting is automatically stopped. - Gotchas: Conflicts operate bidirectionally—starting either conflicting unit will deactivate the other.
- Verify:
systemctl show firewalld.service -p Conflicts
4. What are valid and invalid main service states in Systemd?
Valid primary service states are active, inactive, and failed.
- Command(s):
systemctl is-active <service> - Why:
systemdcategorizes unit activation into high-level main states (active,inactive,failed) and descriptive substates (running,exited,dead). - Gotchas: Terms like “running” or “stopped” are substates or status descriptions, not primary
is-activestate values. - Verify:
systemctl is-active sshd
5. What is the purpose of a Systemd socket unit?
Socket units (.socket) enable on-demand service activation by listening on network ports or IPC sockets before starting the associated service process.
- Command(s):
systemctl list-units --type=socket - Why: Socket activation frees system memory by keeping service daemons inactive until incoming traffic arrives at the listening socket.
- Gotchas: Socket units do not keep the backing service running continuously; they spawn or hand off control to the service upon connection receipt.
- Verify:
systemctl list-units --type=socket
6. What are valid Systemd unit types?
Valid unit types include .service, .socket, .target, .timer, .path, .mount, .automount, .swap, .slice, and .scope.
- Command(s):
systemctl list-units --type=help - Why: Unit types define the specific system resource being managed by
systemd. - Gotchas: Labels like “process”, “daemon”, or “script” are invalid unit type extensions.
- Verify:
systemctl list-units --type=timer
7. How do you find which units depend on a specific unit (reverse dependencies)?
Use the --reverse flag with systemctl list-dependencies.
- Command(s):
systemctl list-dependencies --reverse <unit> - Why: The
--reverseflag searches backward to list all parent units that pull in or require the specified target unit. - Gotchas: Omitting
--reverseoutputs forward dependencies (what the specified unit depends on). - Verify:
systemctl list-dependencies --reverse sshd.service
8. How do you change the default text editor used by systemctl edit?
Export the SYSTEMD_EDITOR or EDITOR environment variable in your shell profile.
- Command(s):
echo 'export SYSTEMD_EDITOR=vim' >> ~/.bashrc && source ~/.bashrc - Why:
systemctl editchecksSYSTEMD_EDITOR,VISUAL, andEDITORin order when choosing an interactive text editor. - Gotchas: Setting
export EDITOR=vimonly in an active shell session loses the configuration upon logout or system reboot. - Verify:
echo $SYSTEMD_EDITOR
9. Which dependency type prevents boot failure if a required component fails?
The Wants= directive creates a non-fatal dependency relationship.
- Command(s):
systemctl show <unit> -p Wants - Why: If a service listed under
Wants=fails to launch,systemdlogs the failure and continues booting the primary service. - Gotchas: Using
Requires=orBindsTo=aborts execution of the main unit if the dependency fails. - Verify:
systemctl show graphical.target -p Wants
10. What are valid systemctl subcommands for unit management?
Valid subcommands include start, stop, restart, reload, status, enable, disable, mask, unmask, is-active, and is-enabled.
- Command(s):
systemctl --help - Why: Standard
systemctlsubcommands manage runtime states, unit persistence symlinks, and security masks. - Gotchas: Command terms like
run,execute, orbeginare not validsystemctlunit management verbs. - Verify:
systemctl --help | grep -E 'start|stop|enable'
11. What is a “unit” in Systemd?
A unit is an encapsulated configuration file representing a system resource managed by systemd.
- Command(s):
systemctl list-units - Why: Units standardize management for services, socket endpoints, storage mounts, dynamic timers, and resource groups.
- Gotchas: Units extend far beyond service daemons to include system targets, device paths, and swap spaces.
- Verify:
systemctl list-units
13. How do you create a “Wants” dependency for a service target?
Create a symlink in the target’s .wants directory inside /etc/systemd/system/ or add Wants= via a drop-in override.
- Command(s):
systemctl enable <service>(ormkdir -p /etc/systemd/system/<target>.wants && ln -s /usr/lib/systemd/system/<service>.service /etc/systemd/system/<target>.wants/) - Why: Systemd reads directory structures ending in
.wantsto load optional weak dependencies automatically when activating the primary target. - Gotchas: Manually creating symlinks requires running
systemctl daemon-reloadto update the runtime manager state. - Verify:
systemctl show <target> -p Wants
14. Which directory contains custom and administrator-overridden Systemd unit files?
Administrative units and overrides reside in /etc/systemd/system/.
- Command(s):
ls -ld /etc/systemd/system/ - Why:
/etc/systemd/system/has highest precedence over vendor-supplied defaults in/usr/lib/systemd/system/. - Gotchas: Editing unit files in
/usr/lib/systemd/system/directly is improper practice, as package updates overwrite those files. - Verify:
ls /etc/systemd/system/
15. How do you ensure a unit file automatically triggers another unit file upon execution?
Add the target unit to the Requires= or Wants= key under the [Unit] header section.
- Command(s):
systemctl show <unit> -p Requires -p Wants - Why:
Requires=forces mandatory co-activation, whileWants=initiates optional co-activation upon unit launch. - Gotchas: Placing dependency directives under the
[Service]or[Install]section causes configuration parsing errors. - Verify:
systemctl cat <unit>
16. How do you display all loaded configuration properties for a specific unit?
Inspect low-level unit attributes using systemctl show.
- Command(s):
systemctl show <unit> - Why: Outputs parsed runtime attributes, execution parameters, active limits, and dependency arrays.
- Gotchas:
systemctl catdisplays raw unit file text on disk, whereassystemctl showoutputs merged active runtime parameters. - Verify:
systemctl show sshd.service | head -n 15
17. How do you list all active dependencies for a specific unit in a tree format?
Run systemctl list-dependencies.
- Command(s):
systemctl list-dependencies <unit> - Why: Renders a tree of units required or wanted by the target service or system target.
- Gotchas: Running
systemctl list-dependencieswithout arguments defaults to displaying the dependency tree ofdefault.target. - Verify:
systemctl list-dependencies multi-user.target
18. What does a status of “dead” indicate in systemctl status?
A state of “dead” means the unit process is currently inactive (stopped) and has not encountered an unhandled execution failure.
- Command(s):
systemctl is-active <unit> - Why: “dead” is a normal substate for an inactive service that exited cleanly or has not been triggered yet.
- Gotchas: Do not confuse “dead” with “failed”. A “failed” status indicates the process terminated with a non-zero exit code or crashed.
- Verify:
systemctl status <inactive_unit>
19. How do you create a safe Systemd drop-in override file?
Use systemctl edit <unit> to construct a custom configuration snippet inside /etc/systemd/system/<unit>.d/override.conf.
- Command(s):
systemctl edit <unit> - Why: Drop-in overrides allow customization of package-managed services without modifying core files under
/usr/lib/systemd/system/. - Gotchas: Custom parameters must be placed under their correct section headers (e.g.,
[Unit],[Service],[Install]). - Verify:
cat /etc/systemd/system/<unit>.d/override.conf
Lab Tasks
Systemd Practice
Install target services, set up persistent environment variables, and configure unit auto-dependencies and restart policies using drop-in overrides.
Configuration Steps
# 1. Install target HTTP and FTP service packages
dnf install vsftpd httpd -y
# 2. Configure systemd default editor persistently across shell sessions
echo 'export SYSTEMD_EDITOR=vim' >> ~/.bashrc
source ~/.bashrc
# 3. Create a drop-in override for httpd.service
systemctl edit httpd.service
In the drop-in editor buffer, enter the following lines:
[Unit]
Wants=vsftpd.service
[Service]
Restart=on-failure
RestartSec=10
Save the file, exit the editor, and reload the systemd manager daemon:
# 4. Reload systemd manager configuration to load drop-in changes
systemctl daemon-reload
-
Why:
-
dnf installinstalls required service binaries and systemd unit definitions. -
echo ... >> ~/.bashrcensuressystemctl editusesvimpersistently. -
Wants=vsftpd.serviceunder[Unit]creates a weak dependency to startvsftpdwheneverhttpdstarts. -
Restart=on-failureandRestartSec=10under[Service]instruct systemd to wait 10 seconds and restarthttpdif it crashes. -
systemctl daemon-reloadrescans unit files and applies new drop-in overrides. -
Gotchas:
-
Placing
Wants=under[Service]orRestart=under[Unit]causes parsing errors. -
Forgetting to run
systemctl daemon-reloadleaves systemd using previous un-modified unit settings.
Verification Procedures
Confirm drop-in override values and active dependency parameters.
# Verify active drop-in parameters loaded for httpd.service
systemctl show httpd.service -p Wants -p Restart -p RestartSec
# Inspect drop-in override file content
cat /etc/systemd/system/httpd.service.d/override.conf