Courseiva
Service Configuration →mediumMultiple Choice

LFCS Service Configuration Practice Question

A system administrator needs to configure a systemd service so that it restarts automatically only when it exits with a non-zero exit code, but not when it is cleanly stopped by an administrator. The service unit file currently has no Restart directive. Which combination of directives should the administrator use?

⚠ Common exam trap

The trap here is assuming that Restart=always is needed for automatic restarts, but it also restarts after a clean administrator stop, which is not desired.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

Restart=on-failure and RestartSec=5

Restart=on-failure is the correct directive because it restarts the service only on abnormal termination, such as non-zero exit codes or signals. It does not restart on a clean stop, which matches the requirement. RestartSec=5 adds a delay to prevent tight restart loops. The other Restart values either restart too broadly (always) or too narrowly (on-abnormal, on-success).

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    Restart=always and RestartSec=5

    Why it's wrong here

    Restart=always restarts the service regardless of exit status, including when it is stopped cleanly with systemctl stop. This would cause the service to restart even after an administrator intentionally stops it, which contradicts the requirement. RestartSec only controls the delay, not the condition.

  • ✓

    Restart=on-failure and RestartSec=5

    Why this is correct

    Restart=on-failure tells systemd to restart the service only when it exits with a non-zero exit code, is killed by a signal, or times out. A clean stop via systemctl stop is considered a success and will not trigger a restart. RestartSec=5 adds a five-second delay between restart attempts, which is useful to avoid rapid restart loops.

  • ✗

    Restart=on-success and RestartSec=5

    Why it's wrong here

    Restart=on-success is the opposite of what is needed: it restarts the service only when it exits cleanly with a zero exit code. A failure with a non-zero exit code would not trigger a restart. This setting is typically used for oneshot services that need to restart after successful completion.

  • ✗

    Restart=on-abnormal and RestartSec=5

    Why it's wrong here

    Restart=on-abnormal restarts only when the service is terminated by a signal, times out, or is killed, but not when it exits with a non-zero exit code. A script that exits with code 1 would not trigger a restart under this setting. This does not meet the requirement of restarting on non-zero exit.

About these practice questions

This LFCS question is part of Courseiva's 406-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Linux Foundation exam blueprint

This LFCS practice question is part of Courseiva's free Linux Foundation certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the LFCS exam.