systemd Basics: Check, Start, Stop & Enable Services Beginner 30 min
Lab overview

systemd Basics: Check, Start, Stop & Enable Services

30 min 4 checked steps Beginner
The situation

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.

By the end of this lab you will be able to
  • 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

WordMeaningExample
Servicea program that runs in the background, usually for as long as the machine is on (also called a daemon)the nginx web server
Unitanything systemd manages. A service is one kind of unit. Others are timers, mounts and targets.nginx.service
Unit filea 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?
  • journalctl reads 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.

The steps
1
Meet systemd and list servicesSave the list of running services to a file.
2
Read a service's statusFind out whether nginx is running and whether it starts at boot.
3
Apply a config change with reloadLoad a new nginx setting without stopping the web server.
4
Stop and disable for goodSwitch nginx off now and make sure it stays off after a reboot.
How this lab works
  1. Press Start lab. You get your own Ubuntu machine on the right, just for you.
  2. Read each step. Commands with a ▶ Run button can be sent to the terminal in one click, but typing them yourself helps you remember.
  3. 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.
  4. Stuck? Open the hint. Nothing you do here can break anything real.
Step 1 of 4

Meet systemd and list services

Objective

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

bash
ps -p 1 -o pid,user,comm
PartMeaning
ps"process status": shows information about running processes
-p 1only show the process whose ID is 1
-o pid,user,commchoose the columns: process ID, the user it runs as, and the command name

What it does: asks the kernel "what is process number 1?"

text
    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 init instead.

2. Is the system healthy?

bash
systemctl is-system-running
PartMeaning
systemctlthe tool for talking to systemd
is-system-runningthe question: "has the machine finished booting, and is everything OK?"
text
running
AnswerMeaning
runningbooted completely, no failed services
startingstill booting
degradedbooted, 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

bash
systemctl list-units --type=service --state=running --no-pager
PartMeaning
list-unitslist the units systemd currently has loaded in memory
--type=serviceonly services (not timers, mounts and so on)
--state=runningonly the ones running right now
--no-pagerprint everything at once instead of opening a scrollable viewer. Without it, long output opens in less, which you leave by pressing q.
text
  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:

ColumnMeaning
UNITthe unit's full name. Services end in .service.
LOADloaded means systemd found and understood its unit file. not-found or error means the file is missing or broken.
ACTIVEthe simple state: active, inactive or failed
SUBthe detailed state. For services: running, exited (did its job and finished) or dead (stopped).
DESCRIPTIONa 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-pager also shows services that are stopped.
  • systemctl --failed --no-pager shows 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
text
systemctl list-units --type=service --state=running --no-pager > /root/running-services.txt

What each part does

  • systemctl list-units --type=service --state=running: only services that are running now.
  • --no-pager: print everything directly instead of opening less, which is needed when saving to a file with >.
Step 2 of 4

Read a service's status

Objective

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:

  1. Is it running right now? This is the active state.
  2. 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

bash
systemctl status nginx --no-pager
PartMeaning
statusshow everything systemd knows about a unit
nginxthe unit name. You can leave out .service, systemd adds it for you.
--no-pagerprint it all at once
text
● 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:

LineWhat 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 linesthe 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:

bash
systemctl is-active nginx
systemctl is-enabled nginx
CommandThe question it asksPossible answers
is-activeis it running now?active, inactive, failed, activating
is-enabledwill it start at boot?enabled, disabled, static, masked
text
active
enabled

nginx 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:

text
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

bash
systemctl cat nginx --no-pager

What it does: prints the unit file that defines the service, with its path as the first line. Here are the important parts:

text
# /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, and After=: start only after the network is up.
  • [Service]: how to run it. ExecStartPre tests the config first, ExecStart is the real start command, and ExecReload is what systemctl reload will run (you'll use it in the next step).
  • [Install]: WantedBy=multi-user.target is what enable hooks 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
text
systemctl is-active nginx > /root/nginx-state.txt

What each part does

  • systemctl is-active nginx: print a single word: active, inactive or failed. It's ideal for scripts. > saves it.
Step 3 of 4

Apply a config change with reload

Objective

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:

restartreload
What happensthe service is stopped completely, then started againthe service re-reads its config while it keeps running
Visitorsconnections are cut for a momentnobody notices
Process IDchanges (it's a new process)stays the same
Works forevery serviceonly 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:

bash
cat /etc/nginx/conf.d/shop-version.conf
text
add_header X-Shop-Version 2 always;

1. Prove the change is not live yet

bash
curl -sI localhost
PartMeaning
curla command-line tool that makes web requests
-ssilent: don't show a progress bar
-Ionly fetch the headers of the response, not the page itself
localhostthis machine
text
HTTP/1.1 200 OK
Server: nginx/1.24.0 (Ubuntu)
Content-Type: text/html
Content-Length: 615
Connection: keep-alive
Accept-Ranges: bytes

200 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

bash
systemctl show -p MainPID --value nginx
PartMeaning
showprint systemd's raw properties of a unit (there are hundreds)
-p MainPIDonly the property called MainPID
--valueprint just the value, without MainPID= in front
text
269

Your number will be different. Write it down, and you'll compare it after the reload.

3. Test the configuration

bash
nginx -t

What 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.

text
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Safe to apply. If there were a mistake, for example a missing ;, you would see this instead and must fix the file before going further:

text
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 failed

4. Reload

bash
systemctl reload nginx

What 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

bash
curl -sI localhost
systemctl show -p MainPID --value nginx
text
HTTP/1.1 200 OK
Server: nginx/1.24.0 (Ubuntu)
...
X-Shop-Version: 2
text
269

The 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
text
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 prints syntax is ok and test 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.
Step 4 of 4

Stop and disable for good

Objective

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:

CommandRunning now?Starts at boot?
systemctl start nginxyesunchanged
systemctl stop nginxnounchanged
systemctl enable nginxunchangedyes
systemctl disable nginxunchangedno
systemctl enable --now nginxyesyes
systemctl disable --now nginxnono

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

bash
systemctl stop nginx
systemctl status nginx --no-pager

What 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.

text
○ 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. dead just 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

bash
systemctl disable nginx

What disable does: removes the link that makes systemd start nginx during boot. It doesn't touch the running state at all.

text
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. enable creates the link, disable removes it.

3. See the links for yourself

bash
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.

text
total 0
lrwxrwxrwx 1 root root 39 Nov 24 09:17 shack-ready.service -> /etc/systemd/system/shack-ready.service

The 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

bash
systemctl is-active nginx
systemctl is-enabled nginx
text
inactive
disabled

Not 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
text
systemctl disable --now nginx

What each part does

  • systemctl disable: don't start nginx at boot (it removes the link in multi-user.target.wants).
  • --now: also stop it right now. Without --now, it would keep running until the next reboot.
Lab complete

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. systemctl controls it.
  • A service has two independent states: active (running now, changed by start and stop) and enabled (starts at boot, changed by enable and disable). --now does both at once.
  • systemctl status shows the unit file path, enabled state, active state, main PID, every process and the latest logs. is-active and is-enabled give 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/. mask blocks a service completely.

Next: the Write Your Own systemd Service lab.

root@devopsshack offline

Your Linux machine is ready to launch

Starting gives you a private Ubuntu server for up to 45 minutes. It is deleted when you finish.

Feedback