Bird
Raised Fist0
Linux CLIscripting~10 mins

Startup and init systems (systemd) in Linux CLI - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a service named 'nginx' using systemctl.

Linux CLI
sudo systemctl [1] nginx
Drag options to blanks, or click blank then click option'
Astatus
Bstart
Cenable
Dstop
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'enable' instead of 'start' to run the service immediately.
Using 'status' which only shows service state.
2fill in blank
medium

Complete the code to check the status of the 'ssh' service.

Linux CLI
systemctl [1] ssh
Drag options to blanks, or click blank then click option'
Arestart
Breload
Cdisable
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'restart' which restarts the service instead of showing status.
Using 'disable' which prevents service from starting at boot.
3fill in blank
hard

Fix the error in the command to enable the 'docker' service at boot.

Linux CLI
sudo systemctl [1] docker
Drag options to blanks, or click blank then click option'
Aenable
Bstart
Cstatus
Dstop
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' which only runs the service now, not at boot.
Using 'status' which only shows service state.
4fill in blank
hard

Fill both blanks to create a systemd service file snippet that runs a script '/usr/local/bin/myscript.sh' after the network is ready.

Linux CLI
[Unit]
Description=My Script Service
After=[1]

[Service]
ExecStart=[2]

[Install]
WantedBy=multi-user.target
Drag options to blanks, or click blank then click option'
Anetwork-online.target
B/usr/local/bin/myscript.sh
Cnetwork.target
D/bin/bash /usr/local/bin/myscript.sh
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'network.target' which may start before network is fully ready.
Using only the script path without the shell in ExecStart.
5fill in blank
hard

Fill all three blanks to write a command that reloads systemd manager configuration, restarts the 'apache2' service, and then checks its status.

Linux CLI
sudo systemctl [1] && sudo systemctl [2] apache2 && sudo systemctl [3] apache2
Drag options to blanks, or click blank then click option'
Adaemon-reload
Brestart
Cstatus
Dreload
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'reload' instead of 'daemon-reload' which only reloads service configs.
Checking status before restarting the service.

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