Courseiva
Operation of Running SystemshardMultiple ChoiceObjective-mapped

LFCS Operation of Running Systems Practice Question

A system administrator needs to ensure that a specific service, 'myapp', starts automatically after a system crash and also restarts if it fails. Which systemd unit directive should be used to achieve this behavior?

⚠ Common exam trap

Many exam-takers confuse `Restart=always` with `Restart=on-failure`, not realizing that `always` restarts even on manual stops, which violates the typical requirement to only restart on failure, and they may overlook that `WantedBy=multi-user.target` is necessary for automatic start after a crash.

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 WantedBy=multi-user.target

The combination of `Restart=on-failure` ensures the service restarts automatically if it exits with a non-zero exit code or is terminated by a signal, and `WantedBy=multi-user.target` creates a dependency that starts the service at boot, including after a system crash. This satisfies both requirements: automatic start after crash (via systemd's dependency-based boot) and restart on failure (via the Restart directive).

Answer analysis

Option-by-option breakdown

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

  • RemainAfterExit=yes

    Why it's wrong here

    RemainAfterExit=yes only keeps the service unit active after the main process exits, but does not restart it.

  • Restart=always

    Why it's wrong here

    Restart=always restarts the service regardless of exit status, but it also restarts if the admin stops it manually, which is not desired.

  • Restart=on-failure and WantedBy=multi-user.target

    Why this is correct

    Restart=on-failure restarts the service only if it fails (non-zero exit), and WantedBy=multi-user.target ensures it starts at boot.

  • ExecStopPost=/bin/systemctl restart myapp.service

    Why it's wrong here

    ExecStopPost runs a command after the service stops, but it is not the standard way to handle automatic restart on failure.

About these practice questions

This LFCS question is part of Courseiva's 507-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 by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.