What command should you run to make this service start automatically on boot?
medium
A. sudo systemctl start myscript.service
B. sudo systemctl enable myscript.service
C. sudo systemctl reload myscript.service
D. sudo systemctl stop myscript.service
Solution
Step 1: Understand difference between start and enable
Starting runs the service now; enabling sets it to run on boot.
Step 2: Identify command to auto-start on boot
Use sudo systemctl enable myscript.service to enable auto-start.
Final Answer:
sudo systemctl enable myscript.service -> Option B
Quick Check:
Enable = auto-start on boot [OK]
Hint: Enable service to auto-start, start to run now [OK]
Common Mistakes:
Using start instead of enable for auto-start
Confusing reload with enable
Stopping service instead of enabling
4. You created a systemd service file but after reboot, the program does not start. Which of these is the most likely mistake?
medium
A. You named the service file with a .txt extension
B. You used sudo systemctl start instead of enable
C. You put the program command under the [Unit] section
D. You forgot to run sudo systemctl daemon-reload after creating the service file
Solution
Step 1: Understand systemd reload requirement
After creating or changing service files, systemd must reload to recognize changes.
Step 2: Identify the missing reload command
Forgetting sudo systemctl daemon-reload means systemd ignores new service files.
Final Answer:
You forgot to run sudo systemctl daemon-reload after creating the service file -> Option D
Quick Check:
daemon-reload needed after service file changes [OK]
Hint: Always run daemon-reload after editing service files [OK]
Common Mistakes:
Skipping daemon-reload after file changes
Confusing start and enable commands
Placing ExecStart in wrong section
Wrong file extension for service files
5. You want your Raspberry Pi to run a Python script at boot, but only after the network is ready. Which systemd service file snippet correctly ensures this?
hard
A. [Unit]\nDescription=Run Python Script\nAfter=network-online.target\nWants=network-online.target\n\n[Service]\nExecStart=/usr/bin/python3 /home/pi/script.py\n\n[Install]\nWantedBy=multi-user.target
B. [Unit]\nDescription=Run Python Script\nRequires=network.target\n\n[Service]\nExecStart=/usr/bin/python3 /home/pi/script.py\n\n[Install]\nWantedBy=multi-user.target
C. [Unit]\nDescription=Run Python Script\nBefore=network-online.target\n\n[Service]\nExecStart=/usr/bin/python3 /home/pi/script.py\n\n[Install]\nWantedBy=multi-user.target
D. [Unit]\nDescription=Run Python Script\nAfter=multi-user.target\n\n[Service]\nExecStart=/usr/bin/python3 /home/pi/script.py\n\n[Install]\nWantedBy=network-online.target
Solution
Step 1: Understand network dependency in systemd
To run after network is ready, use After=network-online.target and Wants=network-online.target.
Step 2: Check each option's unit section
[Unit]\nDescription=Run Python Script\nAfter=network-online.target\nWants=network-online.target\n\n[Service]\nExecStart=/usr/bin/python3 /home/pi/script.py\n\n[Install]\nWantedBy=multi-user.target correctly uses both directives to wait for network online before starting.
Final Answer:
After=network-online.target and Wants=network-online.target -> Option A
Quick Check:
Use After and Wants with network-online.target for network wait [OK]
Hint: Use After=network-online.target and Wants=network-online.target [OK]
Common Mistakes:
Using network.target instead of network-online.target
Placing Before=network-online.target instead of After
Wrong WantedBy target
Missing Wants directive
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.