How to Start, Stop and Enable Services on Linux with systemctl

systemctl: the remote control for services — Start, stop, enable, and find what's crashed.

A web server, a database, SSH, Docker — the useful things on a server all run as services: programs that start at boot and keep running in the background. systemctl is the remote control for them. Learn five subcommands and you can manage anything.

Quick reference

TaskCommand
Is it running?systemctl status nginx
Start / stop / restartsudo systemctl start nginx (or stop, restart)
Reload config without a restartsudo systemctl reload nginx
Start at bootsudo systemctl enable nginx
Don't start at bootsudo systemctl disable nginx
Enable and start nowsudo systemctl enable --now nginx
List everything that's failedsystemctl --failed

1. Check a service

systemctl status ssh

The important line is Active: — active (running) is good, inactive (dead) means it's stopped, failed means it crashed. The last few log lines are shown underneath, which is usually enough to see why. Press q to get out.

2. Start, stop, restart

sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx

restart stops and starts. Some services support reload, which re-reads the config without dropping connections — use it for Nginx after editing a site file.

3. Enable and disable

Starting a service only lasts until the next reboot. To make it start automatically every time:

sudo systemctl enable nginx

disable undoes it. enable --now enables and starts in one go — you'll see it in almost every install guide.

Note that enabled and running are separate: a service can be running now but not enabled (it won't survive a reboot), or enabled but stopped.

4. What's running?

systemctl list-units --type=service
systemctl --failed

The second one is the first thing to run when "something's not working" — it lists services that have crashed.

5. Logs for a service

journalctl -u nginx -n 50
journalctl -u nginx -f

-n 50 shows the last 50 lines; -f follows new ones. More on logs in the next tutorial.

Run your own script as a service

Say you have a script at /home/john/bot.py that should run all the time. Create a service file:

sudo nano /etc/systemd/system/bot.service

[Unit]
Description=My bot
After=network.target

[Service]
User=john
WorkingDirectory=/home/john
ExecStart=/usr/bin/python3 /home/john/bot.py
Restart=on-failure

[Install]
WantedBy=multi-user.target

Then:

sudo systemctl daemon-reload
sudo systemctl enable --now bot

Restart=on-failure restarts it if it crashes. daemon-reload is needed whenever you create or edit a service file.

Troubleshooting

"Unit nginx.service not found." It isn't installed, or the name is different. systemctl list-unit-files | grep -i name to find it.

Status says "failed". Run journalctl -u name -n 50 for the reason — usually a config typo or a port already in use.

Changes to a service file do nothing. You forgot sudo systemctl daemon-reload.

It runs when you start it but not after reboot. You started it but didn't enable it.

Wrapping up

status to look, start/stop/restart to control, enable to survive reboots, --failed to find trouble, and journalctl -u to read why. Everything that runs in the background on your server answers to those commands.

Call us