systemd Basics: Check, Start, Stop & Enable Services
You are on call for the shop's web server. First you check what is running and whether the nginx web server is healthy. Then the team asks you to apply a small nginx configuration change without dropping visitors. Finally, the website is moving to another machine, so nginx has to be switched off here for good, so it does not come back after the next reboot.
- Explain what systemd, a service and a unit are, and why PID 1 matters
- List services and read every line of systemctl status
- Choose correctly between start, stop, restart and reload
- Explain the difference between stop and disable, and check both states
What problem does systemd solve?
A server runs many programs that must always be there: a web server, a database, SSH so you can log in, a logging service. Someone has to:
- start them when the machine boots, in the right order,
- restart them if they crash,
- stop them cleanly when the machine shuts down,
- and collect their logs so you can see what went wrong.
On almost every modern Linux distribution (Ubuntu, Debian, Red Hat, Amazon Linux, Fedora) that "someone" is systemd. Think of it as the manager of the building: it arrives first in the morning, unlocks every office, keeps an eye on everyone during the day, and switches the lights off at night.
Three words you will see everywhere
| Word | Meaning | Example |
|---|---|---|
| Service | a program that runs in the background, usually for as long as the machine is on (also called a daemon) | the nginx web server |
| Unit | anything systemd manages. A service is one kind of unit. Others are timers, mounts and targets. | nginx.service |
| Unit file | a small text file that tells systemd how to run a unit: which command, as which user, when | /usr/lib/systemd/system/nginx.service |
The two commands of this lab
systemctl("system control") gives systemd orders and asks it questions: start this, is this running?journalctlreads the logs systemd collects. It gets its own lab later.
This lab machine boots a real systemd, so everything you see is exactly what you would see on a real Ubuntu server.
- Press Start lab. You get your own Ubuntu machine on the right, just for you.
- Read each step. Commands with a ▶ Run button can be sent to the terminal in one click, but typing them yourself helps you remember.
- Do the Your task part, then press Check my work. The check looks at the machine and tells you what is right or still missing.
- Stuck? Open the hint. Nothing you do here can break anything real.
Meet systemd and list services
Save the list of running services to a file.
When Linux boots, the kernel starts exactly one program. That program gets process ID (PID) 1, and every other program on the machine is started by it, directly or indirectly. This first program is called the init system.
On modern Linux the init system is systemd. Because it is PID 1, it knows about every service, can start and stop them, and notices immediately when one dies.
1. Check who is PID 1
ps -p 1 -o pid,user,comm| Part | Meaning |
|---|---|
ps | "process status": shows information about running processes |
-p 1 | only show the process whose ID is 1 |
-o pid,user,comm | choose the columns: process ID, the user it runs as, and the command name |
What it does: asks the kernel "what is process number 1?"
PID USER COMMAND
1 root systemd- PID 1 is the first process the kernel started.
- USER root: it runs as the administrator, because it has to start everything else.
- COMMAND systemd: the init system on this machine is systemd. On a very old server you might see
initinstead.
2. Is the system healthy?
systemctl is-system-running| Part | Meaning |
|---|---|
systemctl | the tool for talking to systemd |
is-system-running | the question: "has the machine finished booting, and is everything OK?" |
running| Answer | Meaning |
|---|---|
running | booted completely, no failed services |
starting | still booting |
degraded | booted, but at least one service has failed. Run systemctl --failed to see which. |
degraded is worth remembering: it is often the first hint during an incident that something is broken.
3. List the running services
systemctl list-units --type=service --state=running --no-pager| Part | Meaning |
|---|---|
list-units | list the units systemd currently has loaded in memory |
--type=service | only services (not timers, mounts and so on) |
--state=running | only the ones running right now |
--no-pager | print everything at once instead of opening a scrollable viewer. Without it, long output opens in less, which you leave by pressing q. |
UNIT LOAD ACTIVE SUB DESCRIPTION
dbus.service loaded active running D-Bus System Message Bus
nginx.service loaded active running A high performance web server and a reverse proxy server
systemd-journald.service loaded active running Journal Service
3 loaded units listed.Read it one column at a time:
| Column | Meaning |
|---|---|
| UNIT | the unit's full name. Services end in .service. |
| LOAD | loaded means systemd found and understood its unit file. not-found or error means the file is missing or broken. |
| ACTIVE | the simple state: active, inactive or failed |
| SUB | the detailed state. For services: running, exited (did its job and finished) or dead (stopped). |
| DESCRIPTION | a human-friendly name, taken from the unit file |
This lab machine is minimal, so only three services run: dbus (lets programs talk to each other), systemd-journald (collects logs) and nginx (our web server). A real server usually shows 20 to 40.
Two related commands, worth trying:
systemctl list-units --type=service --all --no-pageralso shows services that are stopped.systemctl --failed --no-pagershows only failed units. Empty output (0 loaded units listed) is good news.
Save the list of running services into /root/running-services.txt.
Use the command from section 3 and add > /root/running-services.txt at the end. The > symbol sends the output into a file instead of the screen.
Expected result: cat /root/running-services.txt shows the table with nginx.service in it.
Hint: the commands, explained
systemctl list-units --type=service --state=running --no-pager > /root/running-services.txtWhat each part does
systemctl list-units --type=service --state=running: only services that are running now.--no-pager: print everything directly instead of openingless, which is needed when saving to a file with>.
Read a service's status
Find out whether nginx is running and whether it starts at boot.
A service has two separate states, and mixing them up is the most common systemd mistake:
- Is it running right now? This is the active state.
- Will it start automatically at the next boot? This is the enabled state.
A service can be running but not enabled (it will be gone after a reboot), or enabled but not running (it crashed, or someone stopped it). systemctl status shows both, plus the process and the latest logs, in one screen. It is usually the very first command we run when something is wrong.
1. The full status of one service
systemctl status nginx --no-pager| Part | Meaning |
|---|---|
status | show everything systemd knows about a unit |
nginx | the unit name. You can leave out .service, systemd adds it for you. |
--no-pager | print it all at once |
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled)
Active: active (running) since Tue 2026-11-24 14:47:19 IST; 2min 10s ago
Docs: man:nginx(8)
Process: 312 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 313 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 315 (nginx)
Tasks: 3 (limit: 9605)
Memory: 4.0M ()
CGroup: /system.slice/nginx.service
├─315 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
├─316 "nginx: worker process"
└─317 "nginx: worker process"
Nov 24 14:47:19 devopsshack systemd[1]: Starting nginx.service - A high performance web server...
Nov 24 14:47:19 devopsshack systemd[1]: Started nginx.service - A high performance web server...Line by line:
| Line | What it tells you |
|---|---|
| ● (first character) | a quick colour signal: green ● running, white ○ stopped, red × failed |
| Loaded: | where the unit file lives (/usr/lib/systemd/system/nginx.service, installed by the package), then enabled: it starts at boot. preset: enabled is only the distribution's default, you can ignore it. |
| Active: | active (running) right now, since when, and for how long. After a crash you would see failed here. |
| Docs: | where to read more: man nginx |
| Process: | helper commands that already ran and finished. ExecStartPre tested the config, ExecStart started nginx. status=0/SUCCESS means they worked. |
| Main PID: | the process ID of the service's main process: 315. You will use this number to send signals or look at the process with ps. |
| Tasks / Memory: | how many processes and threads it uses, and how much memory |
| CGroup: | every process that belongs to this service, as a tree. nginx has one master process that manages two worker processes that serve visitors. |
| The last lines | the newest log messages for this service, the same ones journalctl -u nginx shows |
2. Quick yes/no questions
When you only need one answer, for example inside a script or a health check, use these:
systemctl is-active nginx
systemctl is-enabled nginx| Command | The question it asks | Possible answers |
|---|---|---|
is-active | is it running now? | active, inactive, failed, activating |
is-enabled | will it start at boot? | enabled, disabled, static, masked |
active
enablednginx is running now and will start at boot.
These commands also set an exit code: 0 when the answer is yes (active, enabled), non-zero otherwise. That's what makes them useful in scripts:
systemctl is-active --quiet nginx && echo "web server is up"--quiet hides the word, so only the exit code is used.
3. See the unit file itself
systemctl cat nginx --no-pagerWhat it does: prints the unit file that defines the service, with its path as the first line. Here are the important parts:
# /usr/lib/systemd/system/nginx.service
[Unit]
Description=A high performance web server and a reverse proxy server
After=network-online.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
[Install]
WantedBy=multi-user.target[Unit]: the description, andAfter=: start only after the network is up.[Service]: how to run it.ExecStartPretests the config first,ExecStartis the real start command, andExecReloadis whatsystemctl reloadwill run (you'll use it in the next step).[Install]:WantedBy=multi-user.targetis whatenablehooks into: "start this during a normal boot".
You will write your own unit file in the next lab.
Find out whether nginx is running right now, and save the one-word answer to /root/nginx-state.txt.
Expected result: cat /root/nginx-state.txt prints active.
Hint: the commands, explained
systemctl is-active nginx > /root/nginx-state.txtWhat each part does
systemctl is-active nginx: print a single word:active,inactiveorfailed. It's ideal for scripts.>saves it.
Apply a config change with reload
Load a new nginx setting without stopping the web server.
Most services read their configuration file once, when they start. If you edit the file afterwards, the running service doesn't notice. You have to tell it, and there are two ways:
| restart | reload | |
|---|---|---|
| What happens | the service is stopped completely, then started again | the service re-reads its config while it keeps running |
| Visitors | connections are cut for a moment | nobody notices |
| Process ID | changes (it's a new process) | stays the same |
| Works for | every service | only services that support it (nginx, Apache, SSH, PostgreSQL do) |
So on a busy web server we reload whenever we can. And we always test the config first, because a broken config can stop the service from coming back.
The team has already written the change for you. It adds a response header that tells monitoring which version of the shop is live:
cat /etc/nginx/conf.d/shop-version.confadd_header X-Shop-Version 2 always;1. Prove the change is not live yet
curl -sI localhost| Part | Meaning |
|---|---|
curl | a command-line tool that makes web requests |
-s | silent: don't show a progress bar |
-I | only fetch the headers of the response, not the page itself |
localhost | this machine |
HTTP/1.1 200 OK
Server: nginx/1.24.0 (Ubuntu)
Content-Type: text/html
Content-Length: 615
Connection: keep-alive
Accept-Ranges: bytes200 OK means the page works, but there is no X-Shop-Version line. nginx is still running with the config it read when it started.
2. Note the current process ID
systemctl show -p MainPID --value nginx| Part | Meaning |
|---|---|
show | print systemd's raw properties of a unit (there are hundreds) |
-p MainPID | only the property called MainPID |
--value | print just the value, without MainPID= in front |
269Your number will be different. Write it down, and you'll compare it after the reload.
3. Test the configuration
nginx -tWhat it does: -t asks nginx to read all of its config files and check them without applying anything. Most services have something similar: sshd -t, apachectl configtest.
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successfulSafe to apply. If there were a mistake, for example a missing ;, you would see this instead and must fix the file before going further:
nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/conf.d/shop-version.conf:2
nginx: configuration file /etc/nginx/nginx.conf test failed4. Reload
systemctl reload nginxWhat it does: systemd runs the ExecReload command from the unit file you saw in the previous step. nginx starts new worker processes with the new config, and lets the old ones finish their current requests first.
It prints nothing when it works. On Linux, no news is good news. (If you see Job for nginx.service failed, run systemctl status nginx and journalctl -u nginx to find out why.)
5. Check the result
curl -sI localhost
systemctl show -p MainPID --value nginxHTTP/1.1 200 OK
Server: nginx/1.24.0 (Ubuntu)
...
X-Shop-Version: 2269The new header is there, and the main PID is the same number as before: nginx was never stopped. If you had used restart, the header would also be there, but the PID would be new and every connected visitor would have been dropped for a moment.
Apply the new nginx configuration without restarting nginx: test it, then reload.
Expected result: curl -sI localhost shows X-Shop-Version: 2, and nginx's main PID is unchanged.
Hint: the commands, explained
nginx -t && systemctl reload nginx&& runs the second command only if the first one succeeded, so a failed test stops the reload.
What each part does
nginx -t: test the nginx config. It printssyntax is okandtest is successful.&& systemctl reload nginx: only if the test passed, reload: nginx re-reads its config without dropping connections. A bad config never gets loaded.
Stop and disable for good
Switch nginx off now and make sure it stays off after a reboot.
Remember the two states from step 2: active (running now) and enabled (starts at boot). Each has its own pair of commands, and they do not affect each other:
| Command | Running now? | Starts at boot? |
|---|---|---|
systemctl start nginx | yes | unchanged |
systemctl stop nginx | no | unchanged |
systemctl enable nginx | unchanged | yes |
systemctl disable nginx | unchanged | no |
systemctl enable --now nginx | yes | yes |
systemctl disable --now nginx | no | no |
The classic mistake: someone runs only systemctl stop nginx, everything looks fine, and after the next reboot (a kernel update, a cloud maintenance window) nginx is running again.
1. Stop the service
systemctl stop nginx
systemctl status nginx --no-pagerWhat stop does: systemd asks nginx to shut down (it sends a signal, the same idea as kill), waits for it to finish, and if it doesn't stop within a few seconds, forces it. It prints nothing when it works.
○ nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled)
Active: inactive (dead) since Tue 2026-11-24 14:52:40 IST; 3s ago
Main PID: 269 (code=exited, status=0/SUCCESS)
Nov 24 14:52:40 devopsshack systemd[1]: Stopping nginx.service - A high performance web server...
Nov 24 14:52:40 devopsshack systemd[1]: nginx.service: Deactivated successfully.
Nov 24 14:52:40 devopsshack systemd[1]: Stopped nginx.service - A high performance web server...- The dot is now
○: stopped. Active: inactive (dead): not running.deadjust means "not running", nothing is broken.Main PID ... status=0/SUCCESS: it shut down cleanly.- But look at
Loaded: ... enabled: it is still enabled. Reboot now, and nginx comes back.
2. Disable it
systemctl disable nginxWhat disable does: removes the link that makes systemd start nginx during boot. It doesn't touch the running state at all.
Synchronizing state of nginx.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install disable nginx
Removed "/etc/systemd/system/multi-user.target.wants/nginx.service".- The first two lines are housekeeping for old-style start-up scripts. You can ignore them.
- The last line shows what "enabled" really is: a symbolic link (a shortcut) in
/etc/systemd/system/multi-user.target.wants/. At boot, systemd starts everything linked in that folder.enablecreates the link,disableremoves it.
3. See the links for yourself
ls -l /etc/systemd/system/multi-user.target.wants/What it does: lists the folder of services that start during a normal boot. -l shows the details, including where each link points.
total 0
lrwxrwxrwx 1 root root 39 Nov 24 09:17 shack-ready.service -> /etc/systemd/system/shack-ready.serviceThe line starting with l is a link (shack-ready is a helper of this lab machine). nginx.service is gone from the list. Before you disabled it, there was a line nginx.service -> /usr/lib/systemd/system/nginx.service.
4. Confirm both states
systemctl is-active nginx
systemctl is-enabled nginxinactive
disabledNot running now, and won't start at boot. That's what the team asked for. In one go, you could have used systemctl disable --now nginx.
To get rid of a service completely, so that nobody can start it even by accident, use systemctl mask nginx. It links the unit to /dev/null. systemctl unmask nginx undoes it. Use it for services that must never run, for example an old service that conflicts with a new one.
Make sure nginx is stopped now and disabled at boot.
Expected result: systemctl is-active nginx prints inactive, and systemctl is-enabled nginx prints disabled.
Hint: the commands, explained
systemctl disable --now nginxWhat each part does
systemctl disable: don't start nginx at boot (it removes the link inmulti-user.target.wants).--now: also stop it right now. Without--now, it would keep running until the next reboot.
Brilliant work!
You checked the health of a server, read a service's status like an on-call engineer, applied a config change without dropping a single visitor, and switched a service off properly.
Interview-ready takeaways:
- systemd is the init system: PID 1, the first process, which starts, watches and stops every service.
systemctlcontrols it. - A service has two independent states: active (running now, changed by
startandstop) and enabled (starts at boot, changed byenableanddisable).--nowdoes both at once. systemctl statusshows the unit file path, enabled state, active state, main PID, every process and the latest logs.is-activeandis-enabledgive one-word answers for scripts.- Reload re-reads config without stopping (same PID, no downtime); restart stops and starts (new PID). Always test the config first (
nginx -t). - "Enabled" is just a link in
/etc/systemd/system/multi-user.target.wants/.maskblocks a service completely.
Next: the Write Your Own systemd Service lab.
Understand what systemd is, read every line of systemctl status, apply a config change with reload, and learn the difference between stopping a service and disabling it, on a machine that boots real systemd.
You are on call for the shop's web server. First you check what is running and whether the nginx web server is healthy. Then the team asks you to apply a small nginx configuration change without dropping visitors. Finally, the website is moving to another machine, so nginx has to be switched off here for good, so it does not come back after the next reboot.