0
0
Linux CLIscripting~20 mins

Startup and init systems (systemd) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Systemd Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of checking a service status?
You run the command systemctl status sshd on a Linux system with systemd. What output will you see if the SSH service is active and running?
Linux CLI
systemctl status sshd
AFailed to start sshd.service: Unit sshd.service not found.
Bsshd: command not found
CActive: inactive (dead)
DActive: active (running) since ...
Attempts:
2 left
💡 Hint
Think about what 'active and running' means in systemd service status.
💻 Command Output
intermediate
2:00remaining
What happens when you enable a service?
You run systemctl enable nginx. What is the expected result?
Linux CLI
systemctl enable nginx
ACreated symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /lib/systemd/system/nginx.service.
Bnginx.service is already running.
CFailed to enable unit: Unit file nginx.service does not exist.
Dnginx service started successfully.
Attempts:
2 left
💡 Hint
Enabling a service creates links for automatic start, it does not start the service.
🔧 Debug
advanced
3:00remaining
Why does this systemd service fail to start?
Given this service file snippet, why will the service fail to start? [Service] ExecStart=/usr/bin/myapp Restart=always [Install] WantedBy=multi-user.target
Linux CLI
[Unit]
Description=My App Service

[Service]
ExecStart=/usr/bin/myapp
Restart=always

[Install]
WantedBy=multi-user.target
AThe service file is missing the 'Type=' directive, causing systemd to not know how to manage the process.
BThe ExecStart path is incorrect or the binary is missing, causing start failure.
CThe [Unit] section is missing a required 'After=' directive.
DThe [Install] section is missing 'Alias=' directive.
Attempts:
2 left
💡 Hint
Check if the executable path exists and is executable.
📝 Syntax
advanced
3:00remaining
Identify the syntax error in this systemd service file
Which option shows the syntax error in this service file snippet? [Service] ExecStart=/usr/bin/myapp Restart=always RestartSec=5s TimeoutStartSec=30 User=appuser Group=appgroup [Install] WantedBy=multi-user.target
Linux CLI
[Service]
ExecStart=/usr/bin/myapp
Restart=always
RestartSec=5s
TimeoutStartSec=30
User=appuser
Group=appgroup

[Install]
WantedBy=multi-user.target
AUser and Group directives must be in [Unit] section
BTimeoutStartSec=30 should be TimeoutStartSec=30s
CNo syntax error; the file is valid
DRestartSec=5s should be RestartSec=5
Attempts:
2 left
💡 Hint
Check systemd documentation for valid directive formats and sections.
🚀 Application
expert
4:00remaining
How to create a one-shot systemd service that runs a script once at boot?
You want to create a systemd service that runs a script /usr/local/bin/startup.sh only once during boot and then stops. Which service file configuration is correct?
A
[Unit]
Description=Run startup script once

[Service]
Type=oneshot
ExecStart=/usr/local/bin/startup.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
B
[Unit]
Description=Run startup script once

[Service]
Type=simple
ExecStart=/usr/local/bin/startup.sh

[Install]
WantedBy=multi-user.target
C
[Unit]
Description=Run startup script once

[Service]
Type=forking
ExecStart=/usr/local/bin/startup.sh

[Install]
WantedBy=multi-user.target
D
[Unit]
Description=Run startup script once

[Service]
Type=idle
ExecStart=/usr/local/bin/startup.sh

[Install]
WantedBy=multi-user.target
Attempts:
2 left
💡 Hint
One-shot services run a command and then stop, optionally remaining active.