0
0
Raspberry Piprogramming~20 mins

systemd service for auto-start in Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Systemd Service Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this systemd service status command?
Given the following systemd service file content, what will be the output of systemctl status myscript.service after enabling and starting the service successfully?
Raspberry Pi
[Unit]
Description=My Script Service
After=network.target

[Service]
ExecStart=/usr/bin/python3 /home/pi/myscript.py
Restart=on-failure

[Install]
WantedBy=multi-user.target
AActive: active (running) since <timestamp>; Main PID: <pid> (python3)
BActive: inactive (dead) since <timestamp>
CFailed to start myscript.service: Unit not found.
DActive: activating (start) since <timestamp>
Attempts:
2 left
💡 Hint
Think about what happens when a service is enabled and started without errors.
🧠 Conceptual
intermediate
1:30remaining
Which section of a systemd service file controls when the service starts?
In a systemd service file, which section defines the conditions or targets that determine when the service should start automatically?
A[Unit]
B[Install]
C[Service]
D[Timer]
Attempts:
2 left
💡 Hint
Look for the section that mentions 'WantedBy' or 'RequiredBy'.
🔧 Debug
advanced
2:30remaining
Why does this systemd service fail to start?
This systemd service file fails to start the script. What is the cause?
Raspberry Pi
[Unit]
Description=Test Service

[Service]
ExecStart=/home/pi/myscript.py

[Install]
WantedBy=multi-user.target
AThe ExecStart path lacks the interpreter, causing a permission error.
BThe [Unit] section is missing the After=network.target line.
CThe service file is missing the Restart=always directive.
DThe WantedBy target is incorrect; it should be graphical.target.
Attempts:
2 left
💡 Hint
Consider how systemd executes scripts and what is needed to run a Python script.
📝 Syntax
advanced
1:30remaining
Identify the syntax error in this systemd service file snippet
Which option shows the correct syntax for the ExecStart line in a systemd service file?
Raspberry Pi
[Service]
ExecStart=python3 /home/pi/myscript.py
AExecStart=>python3 /home/pi/myscript.py
BExecStart: python3 /home/pi/myscript.py
CExecStart = python3 /home/pi/myscript.py
DExecStart=python3 /home/pi/myscript.py
Attempts:
2 left
💡 Hint
Check the correct assignment operator and spacing in systemd unit files.
🚀 Application
expert
3:00remaining
How to ensure a systemd service restarts automatically on failure?
You want your Raspberry Pi systemd service to restart automatically if the script crashes. Which option correctly adds this behavior?
Raspberry Pi
[Service]
ExecStart=/usr/bin/python3 /home/pi/myscript.py
AAdd RestartSec=5 under the [Unit] section
BAdd Restart=always under the [Install] section
CAdd Restart=on-failure under the [Service] section
DAdd Restart=on-abort under the [Service] section
Attempts:
2 left
💡 Hint
Restart directives belong in the [Service] section and control restart behavior on failure.