hardMultiple Choice
XK0-006 Practice Question: An administrator is tasked with creating a…
An administrator is tasked with creating a systemd service that runs a Python script after the network is available. The script must restart automatically if it fails. Which systemd service unit directive should be used to ensure restart on failure?
⚠ Common exam trap
CompTIA often tests the distinction between `Restart=always` and `Restart=on-failure`, trapping candidates who assume that 'always' is the safest choice without reading the exact failure condition requirement.
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
The `Restart=on-failure` directive instructs systemd to restart the service unit only when the process exits with a non-zero exit code, is terminated by a signal (including SIGKILL), or times out. This is the correct choice because the requirement is to restart the script only if it fails, not unconditionally. Using `Restart=always` would restart the service even after a clean exit, which is unnecessary and could mask intentional stops.
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
Why it's wrong here
Restart=always restarts the unit on any exit, including clean exits and manual stops, which is broader than the requirement to restart only on failure. It is tempting because it guarantees the script comes back after crashes, and would be correct if the service should also restart after successful completion.
- ✗
RemainAfterExit=yes
Why it's wrong here
RemainAfterExit keeps the unit marked active after its main process exits; it never relaunches a failed script. It is tempting because it concerns service state, and it is genuinely correct for oneshot units running setup tasks, but it provides no failure-triggered restart mechanism.
- ✓
Restart=on-failure
Why this is correct
Restart=on-failure instructs systemd to relaunch the unit only when the Python script exits with a non-zero status or is killed by a signal, meeting the stem's requirement for automatic restart after failure without restarting on clean exits.
- ✗
RestartSec=5
Why it's wrong here
RestartSec only sets the delay before a restart attempt; it does not trigger one. It is tempting because it appears in restart-related documentation, and it is genuinely correct when throttling rapid crash loops, but without a Restart= directive systemd never attempts recovery at all.
Visual reference
Go deeper
Related to this question
Learn chapter
Process Management and System Monitoring
Key term
systemd
systemd is a system and service manager for Linux operating systems that initializes and manages processes, services, and system resources after the kernel boots.
Key term
Service
A service is a software component or system that performs a specific function and is available to be used by other programs or users over a network.
About these practice questions
Courseiva writes every XK0-006 question from scratch — 781 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This XK0-006 practice question is part of Courseiva's free CompTIA 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 XK0-006 exam.