Bird
Raised Fist0
Linux CLIscripting~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of systemd in a Linux system?
easy
A. To manage how the system starts and stops programs automatically
B. To edit text files in the system
C. To compile software from source code
D. To monitor network traffic

Solution

  1. Step 1: Understand systemd's role

    systemd is a system and service manager that controls how programs start and stop on Linux.
  2. Step 2: Compare options

    Only To manage how the system starts and stops programs automatically describes managing startup and shutdown of programs, which matches systemd's purpose.
  3. Final Answer:

    To manage how the system starts and stops programs automatically -> Option A
  4. Quick Check:

    systemd manages startup and shutdown = B [OK]
Hint: Remember: systemd controls startup and shutdown of services [OK]
Common Mistakes:
  • Confusing systemd with text editors
  • Thinking systemd compiles code
  • Mixing systemd with network tools
2. Which of the following is the correct command to enable a service named nginx to start automatically at boot?
easy
A. systemctl enable nginx
B. systemctl start nginx
C. systemctl status nginx
D. systemctl stop nginx

Solution

  1. Step 1: Understand systemctl commands

    To enable a service to start at boot, the command is systemctl enable [service].
  2. Step 2: Match command to action

    systemctl enable nginx uses enable with nginx, which is correct for auto-start.
  3. Final Answer:

    systemctl enable nginx -> Option A
  4. Quick Check:

    Enable means auto-start = A [OK]
Hint: Enable means auto-start at boot, start means immediate run [OK]
Common Mistakes:
  • Using start instead of enable for auto-start
  • Confusing status with enable
  • Using stop instead of enable
3. What will be the output of the command systemctl is-active sshd if the SSH service is running?
medium
A. inactive
B. failed
C. active
D. unknown

Solution

  1. Step 1: Understand systemctl is-active

    This command checks if a service is running and returns its state.
  2. Step 2: Identify expected output when running

    If the SSH service is running, the output is active.
  3. Final Answer:

    active -> Option C
  4. Quick Check:

    Running service status = active [OK]
Hint: Active means running, inactive means stopped [OK]
Common Mistakes:
  • Confusing active with inactive
  • Expecting failed when service is running
  • Thinking unknown means running
4. You run systemctl enable apache2 but the service does not start on boot. What is the most likely reason?
medium
A. The service is already running
B. You used start instead of enable
C. The systemctl command is not installed
D. The service file for apache2 is missing or incorrect

Solution

  1. Step 1: Understand what enable does

    Enable creates links so the service starts at boot but does not start it immediately.
  2. Step 2: Identify why enable might fail

    If the service file is missing or broken, enabling won't work properly, so it won't start on boot.
  3. Final Answer:

    The service file for apache2 is missing or incorrect -> Option D
  4. Quick Check:

    Missing service file blocks enable = D [OK]
Hint: Enable needs a valid service file to work [OK]
Common Mistakes:
  • Confusing enable with start
  • Assuming systemctl is missing
  • Thinking running service means enable failed
5. You want to create a custom service that runs a script at startup. Which two steps must you perform to make sure it starts automatically with systemd?
hard
A. Add your script to /etc/rc.local and make it executable
B. Create a service file in /etc/systemd/system, then run 'systemctl enable yourservice' to auto-start it
C. Place your script in /usr/bin and reboot the system
D. Run 'systemctl start yourservice' and then 'systemctl status yourservice' only

Solution

  1. Step 1: Create a systemd service file

    Write a service file describing your script and place it in /etc/systemd/system/ to define how systemd runs it.
  2. Step 2: Enable the service

    Run systemctl enable yourservice to make it start automatically at boot.
  3. Final Answer:

    Create a service file in /etc/systemd/system, then run 'systemctl enable yourservice' to auto-start it -> Option B
  4. Quick Check:

    Create service file + enable = auto-start [OK]
Hint: Create service file and enable it to auto-start [OK]
Common Mistakes:
  • Only starting service without enabling
  • Using old /etc/rc.local method
  • Placing script without service file
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard