6.2 Service Management, Timers, Targets & System Control with systemd

Key Takeaways

  • Systemd units describe services, mounts, targets and timers in the selected manager. Requirement dependencies and ordering are separate.

  • A local drop-in can override a packaged setting. Reread manager definitions after a direct edit and apply process limits when starting a new process.

  • Start and stop change current state. Enable and disable manage installation wiring. Mask blocks activation of a unit name through systemd.

  • Persistent calendar timers can trigger once for missed schedules on timer activation. Result status comes from the service, and delay settings still apply.

  • Use systemd-analyze and journal evidence to investigate boot. Inspect hostname, time, DNS and sysctl settings through the tool that owns each setting.

Last updated: November 2026

6.2 Service Management, Timers, Targets & System Control with systemd

On a host using systemd as its system manager, the system instance normally runs as PID 1. It starts units according to dependency and ordering rules. There can also be a separate user manager, which you query with systemctl --user. Verify the manager and the unit scope when troubleshooting.

Units, dependency and precedence

UnitExample and purpose
Servicelab-report.service runs a command or manages a daemon. systemd tracks the service's processes, typically using a cgroup. Stop behavior depends on settings such as KillMode= and timeouts.
SocketCan bind a network or local socket and activate an appropriate service on demand. The application must support the selected socket activation design.
Timerlab-report.timer activates another unit according to monotonic or calendar rules.
Mountmnt-lab.mount manages the mount at /mnt/lab. Mount names correspond to escaped paths. A generator can create units from /etc/fstab, and explicit mount units are also possible.
Targetmulti-user.target groups units and provides a point for dependency and ordering relationships. Several targets can be active simultaneously.

For a typical system unit using the standard paths, a same-named local file in /etc/systemd/system/ takes precedence over a file in /run/systemd/system/ or the packaged file in /usr/lib/systemd/system/. Additional paths, aliases and generated units can affect lookup. Inspect systemctl cat NAME for files and drop-ins and systemctl show NAME -p FragmentPath -p DropInPaths for the manager's view. Drop-ins are processed by filename order, with directory precedence for identically named drop-ins. List-valued directives can accumulate or require an explicit reset. Prefer a local drop-in for a narrow override of a packaged unit.

A lab host with a provisioned reporter user and trusted executable could use:

[Unit]
Description=Generate the lab report
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
User=reporter
ExecStart=/usr/local/libexec/lab-report

Wants= pulls in the named unit when starting this one. After= sets order if both jobs are scheduled. Together they express a startup relationship. The active network setup must provide the online check, and an online target alone cannot guarantee the application's remote endpoint is reachable. Requires= creates a stronger dependency. If the required unit's activation fails and an ordering dependency puts this service after it, this service does not start. The service does not automatically track every spontaneous deactivation of the required unit. See BindsTo= for a stronger runtime binding and Conflicts= to express incompatible activity.

Choose the service type to match application behavior. A Type=simple service can be considered started as soon as its process is forked. Type=exec waits for successful execution of the program. Type=notify waits for the program's readiness notification. A traditional forking service may use a PID file to identify the daemon. The lab's oneshot service finishes its startup action when the command exits and normally becomes inactive afterward. Other service directives include account, environment, resource limit, restart and explicit reload behavior.

Managing a unit's current state and installation

CommandWhat it does
systemctl start NAME, systemctl stop NAMERequest activation or stopping now. Stop behavior depends on the unit and the manager. Other units may still be able to activate it later.
systemctl status NAMEShows load and activity, recent journal entries and process information where available. Use systemctl is-active NAME or systemctl is-failed NAME for those state checks.
systemctl restart NAMEStops and starts the unit under the manager. Plan for any interruption.
systemctl reload NAMERequests the service's supported configuration reload. This does not reread manager unit files or promise uninterrupted client sessions.
systemctl daemon-reloadRereads the manager's unit definitions, reruns generators and updates dependencies. This does not itself restart a running service.
systemctl enable NAME, systemctl disable NAMESet or remove installation-time unit wiring such as symlinks requested by WantedBy=. On their own these do not start or stop a running service. --now also requests the corresponding state change. Disabled units can still be activated by dependencies or other triggers.
systemctl mask NAME, systemctl unmask NAMEA mask normally links the unit name to /dev/null and blocks activation of that name through the manager. A local definition at the mask path may prevent creation. A successful mask alone does not stop an active unit, and unmasking alone does not start it.

Use systemctl is-enabled to examine installation state, including values such as enabled, static, disabled or masked. Compare it with current state and the applicable triggers or dependencies. To troubleshoot a future start that should be blocked, inspect the service and related socket/timer units. Treat independently launched programs separately from unit activation.

Suppose a packaged service needs a different open-file limit. Use systemctl edit db.service to save a local drop-in:

[Service]
LimitNOFILE=65536

Supported systemctl edit normally asks the running manager to reload after saving. If you edit the drop-in directly, run systemctl daemon-reload. Confirm the effective configuration. A currently running process keeps its limits until it or its service changes them. Coordinate a restart to apply the setting to newly started processes and inspect the new main process's /proc/PID/limits. With a single systemd limit value, soft and hard limits are set to the same value.

Timers and targets

This timer uses the matching lab-report service by default. Set Unit= if another unit should be activated.

[Unit]
Description=Daily lab report

[Timer]
OnCalendar=*-*-* 02:30:00
Persistent=true
RandomizedDelaySec=10m

[Install]
WantedBy=timers.target

OnCalendar= uses the wall clock. OnBootSec= is relative to boot, and OnUnitActiveSec= is relative to the activated unit's previous activation. Use systemd-analyze calendar '*-*-* 02:30:00' to inspect this expression. With Persistent=true on a calendar timer, systemd stores the last trigger time. When the timer is activated again, a missed event during inactivity can trigger one catch-up activation, subject to the configured random delay. A trigger is distinct from successful completion. A service that is already active is generally left running when its timer elapses.

After installing and loading the definitions on the lab host, systemctl enable --now lab-report.timer adds activation wiring and starts the timer. Inspect current and next events with systemctl list-timers and the service result with journalctl -u lab-report.service. The timer and the service have different state records.

systemctl get-default shows the default boot target. systemctl set-default multi-user.target changes the future default. systemctl isolate requests a current transition to an isolatable target and stops units outside its dependencies unless configured to ignore isolation. This can end remote access. Graphical and non-graphical target contents depend on installed services and local policy. rescue.target pulls in more base services than emergency.target, and emergency mode's root mount permissions depend on how it was reached.

Inspect startup and system settings

ToolPractical use
systemd-analyze timeReports startup timing known to systemd. Firmware and loader times depend on available data.
systemd-analyze blameLists measured activation durations. A long duration may reflect waiting on other work, and some units have no measured activation interval. Use critical-chain and the journal for dependency and timing evidence. The exam outline's “systemd-blame” refers to this subcommand.
hostnamectl status, hostnamectl set-hostname lab01.example.testInspect hostname state or apply a new host name on a lab host. Verify the configured name and separately check any DNS records.
timedatectl status, timedatectl set-timezone America/New_YorkInspect or adjust time settings. timedatectl set-ntp true requests an available synchronization service from the configured list. Verify clock synchronization with the active service.
systemd-resolved and resolvectlWhere this resolver is active, resolvectl status displays global and per-link DNS settings, and resolvectl query lab01.example.test tests resolution. A runtime per-link setting can be reset with resolvectl revert LINK. Make persistent changes with the network configuration owner.
sysctlsysctl net.ipv4.ip_forward displays a live kernel setting and sysctl -w KEY=VALUE writes a supported setting. Use approved values and a scoped test host. Persistent configuration depends on the distribution's loader. The systemd-sysctl service reads sysctl.d files at boot. Procps sysctl -p reads the named file, or /etc/sysctl.conf by default. Check which mechanism will apply a setting after restart.
Test Your Knowledge

A packaged legacy-report.service is inactive and has no local file occupying the mask path. Which command blocks future activation of that unit name through systemd, including dependency-triggered starts?

A

systemctl disable legacy-report.service

B

systemctl stop legacy-report.service

C

systemctl isolate multi-user.target

D

systemctl mask legacy-report.service

Test Your Knowledge

On a systemd host, the packaged db.service is running. Which approach preserves a local LimitNOFILE=65536 setting across package updates and applies it to a freshly started service process?

A

Edit the vendor unit itself and restart the service

B

Create a persistent systemctl edit drop-in under [Service], then perform a planned restart

C

Copy the edited unit to /run/systemd/system and restart it

D

Add LimitNOFILE to sysctl.conf and load it

Test Your Knowledge

A daily timer configured with OnCalendar is inactive over several scheduled times. Which setting stores its last trigger and permits a catch-up activation when the timer becomes active again?

A

OnBootSec=0

B

CatchUp=true

C

Persistent=true

D

WakeSystem=true

Sections you finish are checked off in the contents.