terminal.cab

Linux Basics Lesson 23 of 38

guestLevel 1Badges and progress0/100 XP, XP to the next levelStreak0

Services with systemctl

9 minutes

Learning goals

Looking needs no sudo

status shows the state, the main process and the latest log lines. is-active answers with one word and an exit code, which is handy in scripts. Neither needs sudo.

systemctl status app

Purpose: Asks systemd about a service and tells it to start, stop or enable it.

Syntax: systemctl status|is-active NAME | sudo systemctl start|stop|restart|enable NAME

Options:

  • enable --now at every boot and also right now

Example:

systemctl status app
● app.service - Shop API
     Loaded: loaded (/etc/systemd/system/app.service; enabled; preset: enabled)
     Active: active (running) since Sat 2026-10-17 06:01:00 UTC; 3h 41min ago
 Invocation: e210961b058d8fb2a7c4efe1121e35a0
   Main PID: 2114 (python3)
      Tasks: 1 (limit: 9387)
     Memory: 96M (peak: 96M)
        CPU: 0
     CGroup: /system.slice/app.service
             └─2114 python3 app.py

Oct 17 06:01:00 web-01 systemd[1]: Starting app.service - Shop API...
Oct 17 06:01:00 web-01 systemd[1]: Started app.service - Shop API.
systemctl is-active app
active
systemctl is-active backup
inactive

in the glossary: systemctl

Changing needs sudo

start, stop, restart and enable change the system, so they need root. Without sudo you get Interactive authentication required. This practice machine does not ask for a password, because of a NOPASSWD line. On a real server, sudo usually asks for yours.

systemctl stop app
Failed to stop app.service: Interactive authentication required.
See system logs and 'systemctl status app.service' for details.
sudo systemctl stop app
systemctl is-active app
inactive
sudo systemctl start app
systemctl is-active app
active

No output is a good sign with systemctl. restart is both in one go, sudo systemctl restart nginx.

enable is not start

start runs it now, and after the next reboot it is gone again. enable makes it start at every boot, and leaves it stopped until then. enable --now does both.

systemctl is-enabled backup
disabled
sudo systemctl enable --now backup
Created symlink '/etc/systemd/system/multi-user.target.wants/backup.service' → '/etc/systemd/system/backup.service'.
systemctl is-active backup
active

Service names differ between distributions: ssh on Debian and sshd on RHEL, apache2 against httpd.

Practice

Terminal task 1/3

Which main process does nginx have? Show the status of the service. It needs no sudo.

Task 1/3: Which main process does nginx have? Show the status of the service. It needs no sudo.

Which main process does nginx have? Show the status of the service. It needs no sudo.

Loading terminal …

lerner@web-01: ~bash
lerner@web-01:~$

Esc, then Tab leaves the terminal

Not done yet

Terminal task 2/3

Maintenance. Stop the service app. nginx keeps running.

Task 2/3: Maintenance. Stop the service app. nginx keeps running.

Maintenance. Stop the service app. nginx keeps running.

Loading terminal …

lerner@web-01: ~bash
lerner@web-01:~$

Esc, then Tab leaves the terminal

Not done yet

Terminal task 3/3

The service backup is stopped and disabled. It should run now and after every reboot.

Task 3/3: The service backup is stopped and disabled. It should run now and after every reboot.

The service backup is stopped and disabled. It should run now and after every reboot.

Loading terminal …

lerner@web-01: ~bash
lerner@web-01:~$

Esc, then Tab leaves the terminal

Not done yet

Fill the gap

To stop and start a service in one go, you type: sudo systemctl nginx

To stop and start a service in one go, you type: sudo systemctl … nginx

Check works once you have typed an answer.

Predict the output

Command

systemctl is-active backup

Before the command, in your home folder ~

  • ~/.bashrc
  • ~/.profile
  • ~/.secret
  • ~/Documents/
  • ~/logs/
  • ~/notes.txt
  • ~/projects/
  • ~/archive/
What does systemctl is-active backup print?

Check works once you have chosen an answer.

Next up: the server is glowing, and this time it is your turn.

Quiz

  1. Question 1 of 3Which of these needs sudo?

    Check works once you have chosen an answer.

  2. Question 2 of 3You end the main process of a service with kill, and it has Restart=always in its unit. What happens?

    Check works once you have chosen an answer.

  3. Question 3 of 3systemctl status ssh says the unit could not be found on a Rocky Linux server. What is the likely cause?

    Check works once you have chosen an answer.

Cards

  1. Card 1 of 3

    Tap the card or press Space to turn it over.

  2. Card 2 of 3

    Tap the card or press Space to turn it over.

  3. Card 3 of 3

    Tap the card or press Space to turn it over.

End of the lesson

Still open: 5 exercises, 3 quiz questions

Next: lesson 24, The server is glowing (8 min)

What you can do now: systemctl status app

+0 XP in this lesson

  1. Lesson 1: open
  2. Lesson 2: open
  3. Lesson 3: open
  4. Lesson 4: open
  5. Lesson 5: open
  6. Lesson 6: open
  7. Lesson 7: open
  8. Lesson 8: open
  9. Lesson 9: open
  10. Lesson 10: open
  11. Lesson 11: open
  12. Lesson 12: open
  13. Lesson 13: open
  14. Lesson 14: open
  15. Lesson 15: open
  16. Lesson 16: open
  17. Lesson 17: open
  18. Lesson 18: open
  19. Lesson 19: open
  20. Lesson 20: open
  21. Lesson 21: open
  22. Lesson 22: open
  23. Lesson 23: done
  24. Lesson 24: open
  25. Lesson 25: open
  26. Lesson 26: open
  27. Lesson 27: open
  28. Lesson 28: open
  29. Lesson 29: open
  30. Lesson 30: open
  31. Lesson 31: open
  32. Lesson 32: open
  33. Lesson 33: open
  34. Lesson 34: open
  35. Lesson 35: open
  36. Lesson 36: open
  37. Lesson 37: open
  38. Lesson 38: open
1 of 38

Next: lesson 24, The server is glowing (8 min) That's enough for today

Path complete

You finished all 38 lessons of Linux Basics.

Back to the path

Cheat sheet

The most important command lines of this module on one A4 page, black and white, to print or keep on your phone.