Services: systemctl
A service is a program that runs in the background with no window and starts when the computer does; on Linux, systemd runs them, systemctl status shows whether one is running, and sudo systemctl start, stop, restart, enable and disable change it now or at every start-up.
Journeyman · Unix · Linux · Updated
After this lesson you can
- Check whether a service is running and starts at boot with systemctl status, is-active and is-enabled
- Choose between systemctl start, stop, restart, enable and disable for a job on a service
Key takeaways
- A service, or daemon, runs in the background with no window, such as a web server. systemd, the first program Linux starts, starts and looks after them.
- systemctl status cron shows whether a service is running, since when, its process ID and its latest log lines. It only looks; q quits.
- systemctl is-active and is-enabled answer in one word, which suits a script.
- sudo systemctl start, stop or restart changes a service now. enable and disable decide whether it starts at boot, and enable --now does both.
- Current Ubuntu in WSL runs systemd too. On a Mac, launchd does the same job, and brew services runs Homebrew's programs as services.
The book club's website has to answer at 3 a.m. on a Sunday, after a power cut, with nobody signed in. Starting it by hand in a terminal won't do: it stops when that terminal closes, and nobody is there to start it again when the power comes back. Programs like this are run as services, and on Linux one program looks after all of them. Anyone who runs a website, a game server for friends or a home media server uses these few commands, and they're the same on a cloud server at work.
Programs that run on their own
A service is a program that runs in the background with no window, waiting for work: a web server waits for visitors, and cron waits for the time to run a job. Unix calls such a program a daemon (read "DEE-mon"), which is why so many of their names end in d, such as rsyslogd and chronyd.
On Linux, systemd looks after them. It's the first program the computer runs, process number 1, and it starts every service at boot, can restart one that crashes, and stops them all at shutdown. systemctl (read "system control") is how you talk to it:
systemctl is-system-running
ps -p 1 -o pid,comm
running
PID COMMAND
1 systemd
running means systemd is up and no service has failed; degraded means it's up, but at least one service failed.
In WSL: current Ubuntu in WSL runs systemd, as above. If systemctl is-system-running says instead that the system wasn't booted with systemd, it's turned off: add the two lines [boot] and systemd=true to /etc/wsl.conf with sudo nano /etc/wsl.conf, run wsl --shutdown in Windows PowerShell, and open Ubuntu again.
Is it running? systemctl status
status only looks, so it needs no sudo:
systemctl status cron
● cron.service - Regular background program processing daemon
Loaded: loaded (/usr/lib/systemd/system/cron.service; enabled; preset: ena>
Active: active (running) since Mon 2026-11-09 14:31:11 UTC; 3min 35s ago
Invocation: b09526178b284398a761f610af302d87
Docs: man:cron(8)
Main PID: 309 (cron)
Tasks: 1 (limit: 77022)
Memory: 500K (peak: 1.7M)
CPU: 5ms
CGroup: /system.slice/cron.service
└─309 /usr/sbin/cron -f -P
Nov 09 14:31:11 laptop systemd[1]: Started cron.service - Regular background pr>
Nov 09 14:31:11 laptop (cron)[309]: cron.service: Referenced but unset environm>
Nov 09 14:31:11 laptop cron[309]: (CRON) INFO (pidfile fd = 3)
Nov 09 14:31:11 laptop cron[309]: (CRON) INFO (Running @reboot jobs)
lines 1-16/16 (END)
Four lines answer most questions. Loaded says enabled: it starts at every boot. Active says active (running), and since when; a service that crashed says failed. Main PID is its process ID. The last lines are its newest log lines, the same as journalctl -u cron (Reading System Logs). Press q to quit, as in journalctl.
For a script, two questions answer in one word:
systemctl is-active cron
systemctl is-enabled cron
active
enabled
The name must be one this computer has:
systemctl status nginx
Unit nginx.service could not be found.
nginx isn't installed on Sam's laptop. On the book club's server, systemctl status nginx shows the web server's own card, shaped like cron's.
Start, stop and restart
These change what's running, so they need sudo, and they're for a server you look after, not for trying on your laptop now:
sudo systemctl stop nginx
sudo systemctl start nginx
sudo systemctl restart nginx
stop turns the website off, for example before a big change. start turns it on. restart does both in one step, and it's the usual step after you change a program's settings file, because a program reads its settings when it starts. Each prints nothing when it works, so check with systemctl status nginx: Active shows a new "since" time. If a start fails, Active says failed, and the log lines under it, or journalctl -u nginx, say why.
Starting at boot: enable
start is for now; enable is for every time the computer starts. They're two separate switches, like a coffee maker's "brew now" button and its timer:
sudo systemctl enable nginx
sudo systemctl disable nginx
sudo systemctl enable --now nginx
enable makes it start at every boot, without starting it now. disable stops it starting at boot, without stopping it now. enable --now enables it and starts it in one step. The mistake people make is start without enable: the website works perfectly until the next power cut. systemctl is-enabled nginx tells you which you've got.
On a Mac, launchd does systemd's job, and launchctl list lists what it runs. Programs you installed with Homebrew run as services with brew services start nginx, and brew services list shows them.
Check yourself
2 questions to try on the lesson page.
So what
A service is how a program keeps running with nobody signed in. systemctl status tells you how it's doing, and restart and enable are the two you'll use most on any server.