hardMultiple ChoiceObjective-mapped
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
Restarts the service regardless of exit status, which is not required and could cause unnecessary restarts on expected exits.
- ✗
RemainAfterExit=yes
Why it's wrong here
Marks the service as active even after the main process exits, but does not restart it.
- ✓
Restart=on-failure
Why this is correct
Restarts the service only when the process exits with a non-zero exit status or is terminated by a signal.
- ✗
RestartSec=5
Why it's wrong here
Sets the time to wait before restarting, but does not enable restart itself.
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 — 979 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.