systemctl Command: Start, Stop, Enable and Inspect Services

Learn how systemctl starts, stops, enables and inspects systemd services, and how to verify each change with is-active, is-enabled and status.

Tools Published 4 min read

Contents

systemctl is the command that controls services on Linux systems running systemd. This guide shows how to start and stop a service, make it start at boot, and check that each change took effect.

The examples use nginx as a stand-in service name. Replace it with any unit on your machine. Starting and stopping system services needs root, so prefix commands with sudo if you are not root.

Start, stop and restart a service with systemctl

start activates a unit and stop deactivates it. The man page notes that stop fails if the unit does not exist, or if the unit forbids manual stopping.

sudo systemctl start nginx
sudo systemctl stop nginx

restart stops and then starts a unit, and starts it if it was not running. try-restart restarts only units that are already running.

sudo systemctl restart nginx
sudo systemctl try-restart nginx

Reload versus daemon-reload

These two names are easy to confuse:

  • reload asks the service to reread its own configuration. It does not reread systemd unit files.
  • daemon-reload reruns generators, reloads all unit files and rebuilds the dependency tree. Run it after you edit a unit file.

reload-or-restart reloads units that support it and restarts the rest.

sudo systemctl reload nginx
sudo systemctl daemon-reload

Enable and disable at boot

enable creates the symlinks described in the unit’s [Install] section. It does not start the service. disable removes those symlinks and does not stop the service. Add --now to either command to also start or stop the unit in the same step.

sudo systemctl enable --now nginx
sudo systemctl disable --now nginx

Verify the result

Do not assume a command worked. Query the state instead.

is-active prints the state and exits with 0 if at least one listed unit is active. is-enabled prints the enablement state. It exits with 0 for states such as enabled, static and alias, and non-zero for disabled and masked. It exits with 4 if the unit is not found. Add --quiet to suppress the printed text when you only need the exit code in a script.

systemctl is-active nginx
systemctl is-enabled nginx
systemctl is-active --quiet nginx && echo "running"

Inspect with status and show

status prints the runtime state plus the most recent journal lines, 10 by default. Use --lines to change that and --full to avoid truncated lines. It covers only the current or most recent run of the unit.

systemctl status nginx
systemctl status nginx --lines=30 --full

The status output is meant for people. For scripts, use show, which prints machine-readable properties. -p limits the output to named properties and --value prints only the values.

systemctl show nginx -p ActiveState --value

To see the unit file itself, including drop-in overrides, use cat. It shows what is on disk, which can differ from what is loaded if you have not run daemon-reload.

systemctl cat nginx

List units

list-units shows units currently in memory. By default it lists only active units, units with pending jobs, and failed units. Add --all to include loaded but inactive ones, and -t to filter by type.

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

--failed is shorthand for --state=failed. To see which unit files are installed and whether each is enabled, use list-unit-files. Unlike list-units, it includes template units.

systemctl list-unit-files --type=service

Mask a service

mask links a unit to /dev/null, which blocks all activation, including manual starts and enabling. Use it when disable is not enough, for example when another unit might pull the service in. --now also stops it, and unmask reverses the change.

sudo systemctl mask --now nginx
sudo systemctl unmask nginx

If a service fails to start because its port is taken, see ss Command: List Listening Ports and Connections on Linux. To check whether a full disk is the cause, see Check disk usage on Linux with df, du and ncdu.

Sources

  1. systemctl(1) manual page, Linux man-pages project

#Systemctl #Systemd #Services #Units #Administration

This article was drafted with AI assistance, fact-checked against the sources listed above and reviewed by a human editor before publication. Spotted an error? See our corrections policy.