Start, Stop, Restart, and Reload
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx
restart stops the service and starts it again, which drops open connections. reload asks the running service to read its configuration again without stopping; not every service supports it. When you are not sure, sudo systemctl reload-or-restart nginx picks the right one. The .service suffix can be left out.
Test a configuration before you restart, with the service's own check such as sudo nginx -t. Service names differ between families: SSH is ssh on Debian and Ubuntu and sshd on AlmaLinux and Rocky Linux.
Read the Status Output
systemctl status nginx
- Loaded: the path of the unit file and whether the service is enabled at boot.
- Active: the current state, such as active (running), inactive (dead), or failed, and since when.
- Main PID: the process ID of the main process.
- Tasks, Memory, CPU: what the service and its child processes use.
- CGroup: the processes that belong to the service.
- Log lines: the last few journal entries. For the full log, see the journalctl command.
Long output opens in a pager; press q to leave it, or add --no-pager. The exact lines vary a little between systemd versions.
Start at Boot: enable and disable
sudo systemctl enable nginx
sudo systemctl disable nginx
sudo systemctl enable --now nginx
sudo systemctl disable --now nginx
enable only sets up the start at boot; it does not start the service now. With --now, the same command also starts (or, with disable, stops) it.
Check a State in Scripts
| Command | Answers |
|---|---|
is-active nginx | active, inactive, failed |
is-enabled nginx | enabled, disabled, static, masked |
is-failed nginx | failed or another state |
Each one also sets its exit code, 0 for yes, so a script can test it quietly. One exception: is-enabled also returns 0 for a static unit, which has no boot setting of its own.
if systemctl is-active --quiet nginx; then echo "nginx is up"; fi
Find Failed Services
systemctl --failed
This lists every unit that failed. After you fix the cause and start the service again, sudo systemctl reset-failed clears old entries. To list all services and their states, see how to list services with systemctl.
Mask and Unmask
disable removes only the start at boot; another service or a person can still start the unit. mask links it to /dev/null, so it cannot be started at all until you unmask it:
sudo systemctl mask apache2
sudo systemctl unmask apache2
This helps when two services compete for the same port. Never mask the SSH service on a server you reach over SSH.
After Editing a Unit File
systemd keeps unit files in memory. After you add or change one in /etc/systemd/system/, reload them and restart the service:
sudo systemctl daemon-reload
sudo systemctl restart myapp
The status output warns when a unit file changed on disk and a reload is needed. How unit files are built is explained in systemd unit files.
Override Settings with systemctl edit
sudo systemctl edit nginx
This opens an editor for a drop-in file under /etc/systemd/system/nginx.service.d/. Settings you put there add to or replace those of the packaged unit and survive package updates, and systemd reloads the units when you save. For example:
[Service]
Restart=on-failure
RestartSec=5
Then restart the service. systemctl cat nginx shows the unit together with its drop-ins, and sudo systemctl revert nginx removes your overrides.
Power, User Services, and a Summary
sudo systemctl reboot and sudo systemctl poweroff restart or stop the machine, the same as the commands in how to reboot a Linux server. With --user, systemctl manages services of your own account, with unit files in ~/.config/systemd/user/ and no sudo.
| Command | Does |
|---|---|
status | Shows state and logs |
start, stop | Runs or stops now |
restart, reload | Applies new config |
enable, disable | Start at boot or not |
mask, unmask | Blocks or allows starts |
daemon-reload | Rereads unit files |
--failed | Lists failed units |
For the ideas behind all this, see what is systemd.