X
X
X
X

Knowledge Base

HomepageKnowledge BaseServer Managementsystemctl Commands: Start, Stop and...

systemctl Commands: Start, Stop and Enable Linux Services and Read Logs

In short: systemctl commands let you manage services on Linux servers that use systemd. sudo systemctl restart nginx restarts a service, systemctl status nginx shows its state and its latest log lines, and sudo systemctl enable --now nginx starts the service and sets it to start automatically at boot. For a service's logs, use journalctl -u nginx.

What is systemctl?

systemctl is the command-line tool of systemd, the service manager used by current distributions such as Ubuntu, Debian, AlmaLinux and Rocky Linux. Background programs such as a web server, a database or SSH are defined in systemd as services (service units). You run the commands after connecting to your server over SSH. Commands that start, stop or reconfigure a service need administrator rights, so they are prefixed with sudo. Service names can differ between distributions; Apache, for example, runs as apache2 on Ubuntu and as httpd on AlmaLinux.

Basic systemctl commands

systemctl diagram: inactive, active (running) and failed states, start, stop, restart and enable commands with journalctl

The examples below use nginx as the service name; replace it with your own service. All options are listed in the systemctl manual page.

CommandWhat it does
sudo systemctl start nginxStarts the service
sudo systemctl stop nginxStops the service
sudo systemctl restart nginxStops and starts the service again
sudo systemctl reload nginxIf the service supports it, rereads its configuration without stopping the service
systemctl status nginxShows the state and the latest log lines
sudo systemctl enable nginxMakes the service start automatically at boot
sudo systemctl enable --now nginxEnables start at boot and starts the service right away
sudo systemctl disable nginxTurns off starting at boot
systemctl is-active nginxGives a short answer: is the service running?
systemctl is-enabled nginxGives a short answer: is it set to start at boot?
systemctl --failedLists all units in a failed state

Reading the service status

The key line in the output of systemctl status nginx is the Active: line. active (running) means the service is running, inactive (dead) means it was stopped, and failed means it exited with an error. Below that, the output shows the latest log lines of the service, which often hold the clue to the problem. If the output does not fit on the screen, it opens in a pager; scroll with the arrow keys and press q to exit.

Reading service logs with journalctl

For more log lines, use journalctl:

  • journalctl -u nginx -n 50: the last 50 log lines of the service.
  • journalctl -u nginx -f: follows new log lines live; press Ctrl+C to exit.
  • journalctl -u nginx --since today: only today's entries.
  • journalctl -u nginx -p err: only entries at error level or more severe.
  • journalctl -b -u nginx: entries since the server last booted.

Step by step: checking a service that is not working

If your site is down but you can still reach the server over SSH, checking the web server, PHP and database services first quickly shows which layer has the problem. Work through these steps:

  1. List failed services with systemctl --failed.
  2. Read the state and the latest log lines with systemctl status <service>.
  3. Look at the error in detail with journalctl -u <service> -n 50.
  4. Fix the problem. If the service has its own configuration test, run it before restarting.
  5. Restart the service with sudo systemctl restart <service> and check the status again.
  6. Make sure it starts at boot with systemctl is-enabled <service>. If the problem persists or the disk or memory is full, check resource usage or open a support ticket.

Things to keep in mind

  • Do not stop the SSH service: Stopping SSH on a remote server can cut off your own connection.
  • After editing a service file: Run sudo systemctl daemon-reload, then restart the service.
  • The mask command: systemctl mask makes a service impossible to start, even by hand. Do not use it by accident; you need unmask to undo it.
  • After updates: Check your services after package updates. Our guide to updating a Linux server has the details.

Frequently Asked Questions

What is the difference between restart and reload?

restart stops the service completely and starts it again, which can cause a short interruption. reload only rereads the configuration if the service supports it. If it does not, use restart.

Why is my service not running after a reboot?

The service may not be enabled to start at boot. Check with systemctl is-enabled; if the answer is disabled, run sudo systemctl enable.

Do systemctl commands work on every Linux server?

They work on distributions that use systemd. Current releases of Ubuntu, Debian, AlmaLinux and Rocky Linux all use systemd.

Can't find the information you are looking for?

Create a Support Ticket
Did you find it useful?
(2 times viewed / 0 people found it helpful)

Powered by WISECP
Top