Linux Basics Lesson 23 of 38
Services with systemctl
9 minutes
Learning goals
- Read the state of a service with systemctl status and is-active.
- Start, stop and restart a service with sudo, and enable it for every boot.
- Say why you stop a service with systemctl and not with kill.
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:
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
inactiveChanging 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.
Task complete
Solution
systemctl status nginx Why: The status also shows the latest log lines. That makes it the first look when a service acts up.
See the solution? You get fewer XP for this task.
Start over? Files, folders and output go back to the start. Your hints stay.
Loading terminal …
Esc, then Tab leaves the terminal
Not done yet
Repeat: you have solved this task before.
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.
Task complete
Solution
sudo systemctl stop app Why: systemd now knows this was intended, and it does not start the service again until someone asks it to.
See the solution? You get fewer XP for this task.
Start over? Files, folders and output go back to the start. Your hints stay.
Loading terminal …
Esc, then Tab leaves the terminal
Not done yet
Repeat: you have solved this task before.
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.
Task complete
Solution
sudo systemctl enable --now backup Why: Enabled and active are two separate questions. A service can be running without coming back after a reboot, and the other way round.
Another way
sudo systemctl enable backup
sudo systemctl start backup Two lines with the same effect. The form with --now is shorter and cannot forget the second step.
See the solution? You get fewer XP for this task.
Start over? Files, folders and output go back to the start. Your hints stay.
Loading terminal …
Esc, then Tab leaves the terminal
Not done yet
Repeat: you have solved this task before.
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 backupBefore the command, in your home folder ~
- ~/.bashrc
- ~/.profile
- ~/.secret
- ~/Documents/
- ~/logs/
- ~/notes.txt
- ~/projects/
- ~/archive/
Check works once you have chosen an answer.
Next up: the server is glowing, and this time it is your turn.
Quiz
-
Check works once you have chosen an answer.
-
Check works once you have chosen an answer.
-
Check works once you have chosen an answer.
Cards
-
Card 1 of 3
Tap the card or press Space to turn it over.
-
Card 2 of 3
Tap the card or press Space to turn it over.
-
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
What you can do now: systemctl status app
+0 XP in this lesson
- Lesson 1: open
- Lesson 2: open
- Lesson 3: open
- Lesson 4: open
- Lesson 5: open
- Lesson 6: open
- Lesson 7: open
- Lesson 8: open
- Lesson 9: open
- Lesson 10: open
- Lesson 11: open
- Lesson 12: open
- Lesson 13: open
- Lesson 14: open
- Lesson 15: open
- Lesson 16: open
- Lesson 17: open
- Lesson 18: open
- Lesson 19: open
- Lesson 20: open
- Lesson 21: open
- Lesson 22: open
- Lesson 23: done
- Lesson 24: open
- Lesson 25: open
- Lesson 26: open
- Lesson 27: open
- Lesson 28: open
- Lesson 29: open
- Lesson 30: open
- Lesson 31: open
- Lesson 32: open
- Lesson 33: open
- Lesson 34: open
- Lesson 35: open
- Lesson 36: open
- Lesson 37: open
- Lesson 38: open
Cheat sheet
-
systemctl status <name>state, main PID, latest log lines -
sudo systemctl restart <name>stop and start -
sudo systemctl enable --now <name>now and at every boot -
systemctl is-active <name>one word, usable in scripts
The most important command lines of this module on one A4 page, black and white, to print or keep on your phone.
- Download PDF (PDF, 19 KB)
- View as image (PNG, 57 KB)