systemd: units, dependencies, restart policy, targets, journald, boot triage, and timers

Wants pulls a unit in, After only orders it. Restart handles failures until the start limit trips. And journalctl -b -1 is where 'why did it reboot' lives — if the journal is persistent.

Read the briefing
About 3 min to read 12 drills

What to remember

  1. After= orders; Wants=/Requires= pulls in. After alone on a disabled unit does nothing. Pair them, always.
  2. network.target is not 'the network works'. Use Wants + After network-online.target if you need an address at start.
  3. 'start-limit-hit' means the breaker tripped. Fix the cause, then systemctl reset-failed. Restart= alone does not override the rate limit.
  4. LimitNOFILE in the unit, not ulimit in your shell. Services inherit limits from systemd. Verify in /proc//limits after restarting.
  5. journalctl -b -1 is the previous boot. The only way to answer 'why did it reboot' — and it needs Storage=persistent.

The big picture

systemd is how Linux hosts decide what runs, in what order, and what happens when it dies. Interviewers use it to test whether you can read a unit file, predict boot and restart behaviour, and find the reason a service is down from journald rather than from folklore. On chain infrastructure, where validators and RPC nodes run as long-lived services on bare metal, unit files are production code.

The mental model

A dependency graph of units driven toward a target. Wants/Requires say what must exist; After/Before say ordering; ExecStart says what to run; Type says how systemd knows it is up; Restart and the start rate limit say what happens on failure; journald records everything with the unit's name attached. Most incidents are one field wrong.

Diagrams

enable vs start, and the restart limiter
systemctl enable   -> writes a symlink under /etc/systemd
                      takes effect at the NEXT boot
                      changes nothing running now

systemctl start    -> runs it NOW
                      writes nothing to disk

  inactive --start--> activating -------> active
      ^                   |                 |
      |                   | ExecStart       | crash / exit
      |                   |   fails         |
      |                   v                 v
      +----- failed <-- start-limit-hit <---+
                        5 starts in 10s

reset-failed clears the counter. It does not fix the crash.

In depth

Units, dependencies, and ordering

Unit types you meet daily: .service (a process), .socket (activate on connection), .timer (cron replacement), .mount, .target (a grouping such as multi-user.target). Dependencies are two separate ideas: requirement (Wants= soft, Requires= hard, BindsTo= hard plus stop-with) and ordering (After=, Before=). Requires= without After= starts both units in parallel and fails yours if the other fails; After=network-online.target is only meaningful with Wants=network-online.target and a network manager that actually implements it. WantedBy=multi-user.target in [Install] is what systemctl enable uses to create the symlink that starts the unit at boot. systemctl list-dependencies <unit> and systemd-analyze critical-chain show the graph and the boot timeline.

Service types, restarts, and the rate limit

Type=simple (default) considers the service started as soon as the process forks; Type=notify waits for sd_notify(READY=1); Type=forking waits for the parent to exit and needs PIDFile=; Type=oneshot runs to completion. Choosing wrong breaks ordering: a simple database is "started" before it accepts connections, so dependents race it. Restart=on-failure (or always) with RestartSec= governs recovery; StartLimitBurst and StartLimitIntervalSec (in [Unit]) stop a crash loop after N starts in T seconds, and the unit then sits in failed with "start request repeated too quickly" until systemctl reset-failed. Resource controls (MemoryMax=, CPUQuota=, TasksMax=, LimitNOFILE=) map onto cgroups and ulimits; a validator with the default LimitNOFILE=1024 will fall over under load.

journald, boot triage, and timers

journalctl -u <unit> -b shows a unit's log for this boot; -p err filters by priority; --since "-15min" bounds time; -k shows the kernel ring; journalctl -b -1 is the previous boot, which is where "why did it reboot" lives. Persistent journals need Storage=persistent in journald.conf (or /var/log/journal to exist); otherwise logs vanish on reboot. Boot triage: systemctl --failed, systemd-analyze blame, and the emergency/rescue targets when a mount in /etc/fstab blocks boot (nofail and x-systemd.device-timeout= prevent that). Timers replace cron with dependencies, logging, and Persistent=true for missed runs; systemctl list-timers shows the schedule.

Myths and facts

Myth: After= makes systemd start the other unit first.

Fact: After= only orders; it does not pull the unit in. Use Wants= or Requires= for that, plus After= for ordering.

Myth: Restart=always means the service will always come back.

Fact: The start rate limit stops it after StartLimitBurst failures in StartLimitIntervalSec; the unit then stays failed.

Myth: systemctl enable starts the service.

Fact: enable creates the boot symlink; start starts it now. enable --now does both.

Myth: Type=simple is fine for a database.

Fact: systemd considers a simple service up immediately; dependents may connect before it listens. Use notify or a readiness check.

Myth: journalctl shows logs from before the reboot by default.

Fact: Only if the journal is persistent; volatile journals are lost at reboot, and -b -1 needs persistence.

How pros do it

  • Pair every After= with Wants= or Requires=; use Type=notify for services that support it.
  • Set Restart=on-failure with a RestartSec that avoids hammering dependencies, and tune StartLimitBurst/IntervalSec deliberately.
  • Raise LimitNOFILE and TasksMax for high-connection services; set MemoryMax as a guardrail on bare metal.
  • Make the journal persistent and forward it; boot triage needs the previous boot.
  • Use timers with Persistent=true instead of cron for anything that must not be skipped.

Questions people ask

The unit shows 'failed (Result: start-limit-hit)'. What now?

Fix the crash, then clear the breaker. The service failed StartLimitBurst times inside StartLimitIntervalSec (5 in 10 s by default), so systemd stopped retrying and parked it as failed; read journalctl -u <unit> -b for the exit status of the attempts, fix that, then systemctl reset-failed <unit> and start it. The caveat: raising the limits only helps when a dependency is genuinely slow to appear; for a deterministic crash the breaker is doing you a favour.

Why does my service start before the network is up despite After=network.target?

Because network.target only means network management has started, not that an address is configured. Use Wants=network-online.target plus After=network-online.target: the Wants pulls the target in, the After orders you behind it. The caveat: network-online only means something when a network manager implements it (systemd-networkd-wait-online, NetworkManager-wait-online), and a service that reconnects on its own should not depend on it at all.

How do I see why the machine rebooted?

journalctl -b -1 -e for the end of the previous boot, then -k -b -1 for the kernel's last words and last -x reboot for the timeline. The previous boot exists only if the journal is persistent (Storage=persistent, or /var/log/journal present). The caveat: a panic or a watchdog reset often leaves nothing in the journal at all, so the console, pstore and the BMC event log are the next stops.

Timer vs cron?

Timers, for anything that matters: they get dependencies, journald logging under the unit's name, resource limits, RandomizedDelaySec to spread fleet load, Persistent=true for missed runs, and they cannot overlap themselves. cron is fine for a trivial job on a legacy host. The caveat: AccuracySec defaults to a minute, so set it explicitly when the job must fire on the second.

Where should environment secrets for a unit live?

Not in the unit file. Use LoadCredential= (systemd credentials, handed to the service under $CREDENTIALS_DIRECTORY) or an EnvironmentFile= with 0600 permissions outside the repo. The caveat: environment variables are readable in /proc//environ by anything with ptrace rights over the process, which is why credentials are the better answer for keys.

Further reading

Drills · 12

Answer in your head, or out loud, before you reveal. Mark each one: "Again" brings it back, "Got it" counts on your desk.

1 Pick the strongest answer

Quick one: what is the difference between systemctl start api and systemctl enable api?

  1. start runs it now and changes nothing on disk; enable creates the symlink that starts it at boot and does not touch the running system. enable --now does both. They are orthogonal: one is about this instant, one is about every future boot.
  2. enable starts the service and start only marks it for the next boot. Exactly backwards, and it is a common slip under pressure.
  3. They are aliases; enable is the newer spelling. Running one without the other is the cause of a whole genre of incident.
  4. start applies until the next daemon-reload, enable is permanent. daemon-reload re-reads unit files; it does not stop running services.
In short

start runs it now and enable only makes it come back after a reboot, so they are two separate things.

Why

A small question that catches a real operational habit. On any host you have changed by hand, verifying both states before you walk away is the discipline being tested.

The common mistake

Starting a service by hand during an incident and assuming it will survive the next reboot. It will not, and the failure arrives months later with no obvious cause.

Read the docs

2 Pick the strongest answer

Your unit has After=postgresql.service and says nothing else about postgresql. On boot, postgresql is not enabled. What happens to your unit, and why?

  1. It fails because a dependency is missing. That is Requires= behaviour.
  2. systemd starts postgresql automatically. Only Wants=/Requires= (or a target) pull units in.
  3. It starts normally without postgresql; After= only orders units that are both scheduled, it does not pull postgresql in. Ordering and requirement are separate; Wants= or Requires= would pull it in.
  4. It waits forever for postgresql. After= imposes no wait on a unit that is not being started.
In short

Your unit starts anyway, because After= only orders units that are already going to start; it never pulls postgresql in.

Why

Two axes: requirement (does it get started?) and ordering (when?). Wants=postgresql.service + After=postgresql.service is the usual pair; Requires= if yours must fail when it fails.

The common mistake

Believing After= starts the other unit. It only sequences two units that are both already being started, so a disabled dependency is silently skipped.

Read the docs

3 Read the output

What has actually gone wrong, and what will systemctl restart api do right now?

$ systemctl status api
* api.service - API
     Loaded: loaded (/etc/systemd/system/api.service; enabled)
     Active: failed (Result: start-limit-hit) since Tue 2026-09-02 14:22:07 UTC
    Process: 5521 ExecStart=/usr/local/bin/api (code=exited, status=1/FAILURE)

Sep 02 14:22:07 web-3 systemd[1]: api.service: Scheduled restart job, restart counter is at 5.
Sep 02 14:22:07 web-3 systemd[1]: api.service: Start request repeated too quickly.
Sep 02 14:22:07 web-3 systemd[1]: api.service: Failed with result 'start-limit-hit'.
  1. The service crashes on start (status=1); systemd retried five times, hit the start rate limit and gave up. A plain restart is refused while the 10-second limit window is still open unless you clear it with systemctl reset-failed api — and either way it will just fail again unless the crash is fixed. start-limit-hit describes systemd's response, not the fault; the fault is the exit status 1 on ExecStart.
  2. systemd is misconfigured with too few retries; raise StartLimitBurst and it will recover. Retrying a deterministic crash more times just crashes more times.
  3. The binary is missing, which is what status=1 means. A missing executable gives 203/EXEC; status=1 means the program ran and chose to exit.
  4. The unit file is invalid; run daemon-reload. It is Loaded and enabled; the unit parsed fine.
In short

The binary itself exits with status 1 on every start and systemd gave up after five tries; fix the crash, then run systemctl reset-failed api and start it.

Why

The trap is treating start-limit-hit as the problem. It is the symptom of five earlier failures, and every one of them is described a few lines up. Interviewers watch to see whether you scroll past systemd's own noise to the process exit status.

The common mistake

Treating start-limit-hit as the fault and tuning StartLimitBurst. The fault is five lines up: the binary exits 1 every time.

Read the docs

4 Scenario: what do you do next?

A host was rebooted for patching. It came back, but the api service is not running. Starting it by hand with systemctl start api works immediately and the service is healthy.

Step 1. It starts fine by hand. Where do you look for why it did not start at boot?

  1. Add a 60-second sleep to ExecStartPre so it starts later. A sleep is a guess about a race you have not diagnosed, and it slows every future boot.
  2. The boot journal for that boot: journalctl -b -u api for the unit's own attempt, and systemctl is-enabled api to confirm it was even supposed to start. Those two answer 'was it asked' and 'what happened when it was'. A service that works by hand but not at boot is either not enabled or lost a race with a dependency, and these two commands separate the cases.
  3. Set Restart=always and let it retry until it works. It might paper over the race, but the host now has a service that is expected to fail on boot.
  4. Assume the reboot was unclean and reboot again to check. Rebooting production to reproduce, before reading the journal you already have, is expensive and unnecessary.

Step 2. It is enabled, and the boot journal shows the unit failing to bind its socket because the network address was not up yet. What is the correct fix?

  1. Configure the application to bind 0.0.0.0 instead. Sometimes a legitimate simplification, but it dodges the ordering bug rather than fixing it, and fails again for anything that needs the specific address.
  2. Set the service to Type=idle so it starts last. Type=idle only delays console output ordering; it makes no dependency guarantee.
  3. Declare the real dependency — After=network-online.target with Wants=network-online.target — so systemd waits for an address rather than merely for the network stack to exist. network.target only means networking is being set up; network-online.target is the one that means an address is configured.
  4. Add After=network.target, which is what network dependencies use. This is the classic near-miss: network.target is reached long before an address exists, so the race remains.

Step 3. How do you know it is really fixed?

  1. Assume it is fixed because the unit file now looks right. This whole class of bug hides for months precisely because nobody reboots to check.
  2. Start it by hand and confirm it is healthy. That is the state you already knew worked; it tests nothing about boot.
  3. Reboot the host once in a controlled window and confirm the service comes up on its own, then add the check to the host build so drift is caught before the next unplanned reboot. Boot behaviour can only be proven by booting; the automated check is what stops it regressing quietly.
In short

Check systemctl is-enabled and the boot journal, then declare the real dependency with Wants= and After=network-online.target, and prove it with a reboot.

Why

"Works by hand, not at boot" is one of the most common real-world systemd problems, and interviewers use it because the diagnosis path is short and very revealing. The two-command opening, and knowing the network.target versus network-online.target distinction, is the whole answer.

The common mistake

Adding a sleep in ExecStartPre, or After=network.target, which is reached long before an address exists. Both leave the race in place.

Read the docs

5 Pick the strongest answer

systemctl stop api hangs for a minute and a half before returning, and the journal shows api.service: State 'stop-sigterm' timed out. Killing. followed by Main process exited, code=killed, status=9/KILL. What happened, and what do you change?

  1. The service did not exit on SIGTERM, so systemd waited TimeoutStopSec (90 s by default) and escalated to SIGKILL for everything in the unit's cgroup. Fix the application's shutdown so it exits on SIGTERM (or set KillSignal= to the signal it honours), then set TimeoutStopSec to the time a clean shutdown genuinely needs. The stop path is signal, wait TimeoutStopSec, SIGKILL; the timeout message names the phase that expired and the 9/KILL status is the escalation.
  2. Switch to KillMode=process so only the main process is signalled and the stop returns immediately. KillMode changes who receives the signals, not whether the main process exits; it also leaves children orphaned when the main process finally goes.
  3. That is how every stop works: systemd always waits 90 seconds before a service counts as stopped. systemd returns the moment the cgroup is empty; the wait happens only while processes are still alive after the stop signal.
  4. Restart=always restarted it faster than stop could act; set Restart=no first. A stop job cancels any pending restart; Restart= plays no part in how long a stop takes.
In short

The service ignored SIGTERM, so systemd waited the 90-second TimeoutStopSec and then SIGKILLed it; fix the shutdown handler, then size TimeoutStopSec to a real clean shutdown.

Why

A stop that takes exactly the timeout is a process that never acted on the signal. Interviewers listen for the sequence (signal, wait, kill), the knowledge that 90 s is a default rather than a law, and the instinct to fix the handler before touching the timeout.

Read the docs

6 Pick the strongest answer

You get paged: a service with Restart=always, RestartSec=1 crashes on start. After a few seconds systemctl status shows failed (Result: start-limit-hit) and it never restarts again. Why?

  1. Restart=always only applies to clean exits. always restarts on any exit; the limit is what stopped it.
  2. RestartSec=1 is below the minimum and disables restarts. There is no such minimum.
  3. The unit needs Type=forking to be restarted. Type affects readiness detection, not restart eligibility.
  4. The start rate limit tripped: more than StartLimitBurst (default 5) starts within StartLimitIntervalSec (default 10 s); systemd stops trying until reset-failed. Restart= handles individual failures; the start limit is a separate guard against crash loops.
In short

The start rate limit tripped: more than 5 starts in 10 seconds puts the unit in failed state and systemd stops retrying; fix the crash, then run systemctl reset-failed.

Why

A crash-looping service that restarts every second would spam dependencies and logs; the start limit is the circuit breaker. For services that should retry for a long time, raise RestartSec (for example 5–10 s) and set StartLimitIntervalSec=0 deliberately, understanding what you give up.

Read the docs

7 Read the output

The host came back 40 minutes late after a disk replacement. Walk me through what happened, and what would have prevented the delay?

$ journalctl -b --no-pager | grep -E 'timed out|Timed out|Dependency failed|Emergency Mode'
systemd[1]: dev-disk-by\x2duuid-3f9c....device: Job dev-disk-by\x2duuid-3f9c....device/start timed out.
systemd[1]: Timed out waiting for device dev-disk-by\x2duuid-3f9c....device - /dev/disk/by-uuid/3f9c....
systemd[1]: Dependency failed for data.mount - /data.
systemd[1]: Dependency failed for local-fs.target - Local File Systems.
systemd[1]: Dependency failed for indexer.service - ledger indexer.
systemd[1]: Reached target emergency.target - Emergency Mode.

$ systemctl status indexer.service | head -3
* indexer.service - ledger indexer
     Loaded: loaded (/etc/systemd/system/indexer.service; enabled)
     Active: inactive (dead)

$ systemctl show indexer.service -p Requires -p After
Requires=data.mount
After=data.mount network-online.target
  1. The indexer crashed and took the mount down. Dependencies flow from the mount to the service, not the other way; the journal shows the indexer failing as a dependency, never running.
  2. The device timeout is what cost 40 minutes; raise x-systemd.device-timeout= so systemd waits longer for the disk to appear. The timeout is 90 s by default and the old UUID was never going to appear; the 40 minutes is a boot parked in emergency mode waiting for a human, and a longer timeout would add to it.
  3. network-online.target failed, which is why the indexer never started. Nothing in the output points at the network; the failed dependency named is data.mount.
  4. /etc/fstab still names the old disk's UUID. systemd waited 90 s for a device that never appeared, failed data.mount and everything that Requires= it, and because the entry had no nofail that failure took local-fs.target down and parked the boot in emergency mode until someone reached the console: that is the 40 minutes. nofail (with x-systemd.device-timeout=) on non-root mounts lets the boot finish with the indexer failed and logged; then fix the UUID. A hard fstab entry is a Requires= of local-fs.target; its device job timing out fails the mount as a dependency, local-fs.target's OnFailure= pulls in emergency.target, and the boot stops there.
In short

fstab still points at the old disk's UUID, so the mount's device timed out, local-fs.target failed and the boot sat in emergency mode until someone intervened; nofail and a device timeout would have let it boot, then fix the UUID.

Why

Disk replacements change UUIDs. A hard fstab entry (no nofail) becomes a Requires= of local-fs.target, so when its device job times out after 90 s the mount fails as a dependency, local-fs.target fails, and its OnFailure= pulls in emergency.target: the boot parks at an emergency shell until an operator with console access intervenes, which is where the 40 minutes went. nofail turns the same missing disk into a boot that completes with one clearly failed service, x-systemd.device-timeout= shortens the wait, and the service's own Requires=data.mount (or RequiresMountsFor=/data) makes it fail cleanly instead of starting on an empty directory.

Read the docs

8 Find what's broken

This validator unit falls over under load and occasionally starts before the host has an address. Which two lines, and what do you change them to?

[Unit]
Description=solana validator
After=network.target

[Service]
Type=simple
User=sol
ExecStart=/home/sol/bin/agave-validator --identity /home/sol/keys/identity.json --ledger /mnt/ledger --rpc-port 8899
Restart=always
RestartSec=1
LimitNOFILE=1024
Environment=RUST_LOG=info

[Install]
WantedBy=multi-user.target
In short

Line 3 should wait for network-online.target (with Wants=), and line 11 must raise LimitNOFILE far above 1024.

What's broken
  • Line 3: After=network.target only orders after network management started, not after addresses are configured; and there is no Wants= to pull the online target in.
  • Line 11: LimitNOFILE=1024 is far below what a validator's thousands of connections and ledger files need.
Why

Two quiet lines: the wrong network target (a copy-paste classic) and the default file-descriptor limit. Type=simple (line 6) is acceptable here since nothing depends on readiness; Restart=always (line 9) is fine with the caveat of the start limit; the environment line is harmless.

Read the docs

9 Scenario: what do you do next?

A bare-metal RPC host rebooted unexpectedly at 03:12. It is back up, but the rpc service is inactive (dead) and the on-call is unsure whether to start it: "what if it reboots again?"

Step 1. First step?

  1. Reinstall the OS. Destroys evidence for a problem you have not identified.
  2. Find why it rebooted: journalctl -b -1 -e (previous boot's tail), journalctl -k -b -1 for kernel messages, last -x reboot, and the BMC/IPMI event log for hardware resets. Whether to restart depends on the cause; the previous boot's journal is the primary source.
  3. Assume a power blip and move on. An assumption; the logs are right there.
  4. Start the service and watch. If the cause was the service (OOM, kernel panic from a driver it uses), you repeat it.

Step 2. The previous boot's journal ends abruptly with no shutdown messages; -k -b -1 shows Out of memory: Killed process 2211 (rpc) twice in the last hour, then nothing. IPMI shows a 'watchdog reset'. What do you conclude and do?

  1. Start rpc with Restart=always and RestartSec=1. That restarts faster into the same memory exhaustion.
  2. Add 2 GB of swap and start rpc. Swap would delay the OOM by minutes on a machine this size; it is not a guardrail.
  3. Memory exhaustion led to OOM kills and eventually a hard reset (likely the hardware watchdog). Start rpc under a MemoryMax= guardrail below physical RAM, with swap or no swap deliberately decided, and watch PSI; investigate the memory growth. A guardrail turns a host-killing failure into a service restart while the root cause is investigated.
  4. Disable the watchdog so the host does not reset. The watchdog saved a hung host; the memory problem is the cause.

Step 3. Systemic follow-up?

  1. Move the RPC to Kubernetes. Kubernetes does not fix memory sizing; it adds a layer.
  2. Buy more RAM. Without a guardrail or alert, the next index outgrows the new RAM the same way.
  3. Unit-level MemoryMax and OOMPolicy for the service, PSI-based memory alerts, persistent journal shipped off-host, and a capacity rule tying RPC indexes to RAM. Contains the failure, detects it early, preserves evidence, and prevents the configuration that caused it.
In short

Read the previous boot's journal first (journalctl -b -1), find the OOM kills and the watchdog reset, then start rpc only under a MemoryMax guardrail.

Why

systemd's journal across boots is what makes 'why did it reboot' answerable. The interview shape: previous-boot evidence, a cause you can name, a guardrail before restarting, then alerting and a capacity rule.

Read the docs

10 Answer out loud

Talk me through the systemd unit you would ship for a long-running network service on bare metal: the dependency lines, the Type, the restart policy and its limits, the resource controls, and how you would debug it when it fails at boot. Four to six sentences.

In short

A strong answer pairs Wants= and After=network-online.target, sets Restart=on-failure with a tuned start limit and raised limits, and debugs with journalctl -u and -b -1.

What a strong answer does
  • correctness: Wants+After network-online.target; Type=notify (or simple with a readiness caveat); Restart=on-failure, RestartSec 5–10, StartLimit tuned deliberately; LimitNOFILE/TasksMax/MemoryMax; User=; EnvironmentFile or credentials for secrets; WantedBy=multi-user.target.
  • debugging: systemctl --failed, journalctl -u -b (-b -1 for previous boot), systemd-analyze critical-chain, reset-failed after start-limit-hit, persistent journal.
  • communication: Unit → Service → Install, each field justified in a clause, then the debug path.
Why

Interviewers want the fields justified, not recited; the debug path across boots is what shows real operating experience.

11 Quick recall

A service is misbehaving right now. Give me the one command that shows only the api unit's log and follows it as new lines arrive.

In short

journalctl -u api -f shows only that unit's log and follows new lines.

Accepted

journalctl -u api -f · journalctl -fu api · journalctl --unit api --follow

Why

-u scopes to one unit and -f follows. Add -n 200 to start with recent context, or --since -10min to bound it by time. Knowing this without thinking is the difference between debugging a service and hunting through /var/log.

Read the docs

12 Quick recall

The host rebooted overnight and you want to see what it was saying just before it went. Which journalctl option selects the previous boot?

In short

journalctl -b -1 shows the previous boot, if the journal is persistent.

Accepted

-b -1 · journalctl -b -1 · --boot=-1

Why

journalctl -b -1 selects the previous boot (requires a persistent journal); -b alone is the current boot.

Next lesson cgroups v2 and namespaces: how a container is assembled and limited
Drill · systemd
0:00

Loading…