How to List Services With the systemctl Linux Command

Updated

systemctl list services

systemctl list-units --type=service lists every loaded service; add --state=running to see only the running ones, systemctl --failed for units that failed to start, and systemctl is-enabled name.service to check whether one starts at boot. To keep a service running after a crash, put Restart=always with RestartSec=5 in the unit file’s [Service] section — not a cron job.

A cron job that runs every hour and restarts a service if systemctl is-active --quiet reports it stopped is strictly worse than Restart=always in the unit file: it checks once an hour (up to 59 minutes of downtime before it even notices), it can fail silently with no built-in alert, and systemd already does this natively. Skip the cron script. Add to the unit file instead:

[Service]
Restart=always
RestartSec=5

then systemctl daemon-reload && systemctl restart myservice. systemd detects the exit immediately and restarts within RestartSec, with no polling interval and no separate cron job to keep working — per the systemd.service manual, Restart=always restarts the service regardless of whether it exited cleanly, was terminated by a signal, or hit a timeout, and RestartSec= configures the time to sleep before restarting.

None of the systemctl commands on this page were run — those below are quoted from systemd’s own documentation, not executed output. Treat command syntax as citation, not a transcript.

CPUShares is the wrong property name

CPUShares, as in systemctl set-property httpd.service CPUShares=1024, is the cgroup v1 (legacy hierarchy) property name. Per systemd’s own systemd.resource-control manual, options for the legacy control group hierarchy — including CPUShares= — are “now fully deprecated… Please switch to the unified cgroup hierarchy.” Current systemd, on any distro shipping cgroup v2 by default (every mainstream distro’s default since around 2021), uses CPUWeight:

systemctl set-property httpd.service CPUWeight=100

CPUWeight takes a value from 1 to 10000 (default 100), not the older 2–262144 range CPUShares used — a value of 1024 means something completely different under the new property than it did under the old one. This isn’t a cosmetic rename; reusing the old number would silently misconfigure the weight.

Listing and filtering services

systemctl list-units --type=service               # all loaded service units
systemctl list-units --type=service --state=running
systemctl list-units --type=service | grep ssh
systemctl --failed                                 # units that failed to start
systemctl is-enabled nginx.service                  # starts at boot?
systemctl status nginx.service -l                   # full status + recent logs

For remote hosts, systemctl -H user@host list-units --type=service works over SSH if you have access and permissions there — no separate remote-management protocol required.

Restricting a service’s filesystem access

Periodically listing running services and checking for anything unexpected is sound advice. Combine it with ProtectSystem=strict in the unit file, which makes the entire filesystem read-only to that service except paths it explicitly needs — reducing what a compromised service process can modify.

Start at boot and restart after a crash

To check whether a service starts at boot, use systemctl is-enabled service_name.service. To make a service restart itself after a crash, use Restart=always with RestartSec= in the unit file’s [Service] section. Not a cron job.

For related process- and CPU-monitoring commands, see checking CPU speed and model.

Photo of author
Sudhir P. founded HeatWare.com in 1999 and has built and operated it full-stack ever since; it is now used by more than 88,000 people. He writes here about the PostgreSQL, MySQL, Linux and DevOps work that keeps it running. Articles are rewritten only after the commands in them have actually been run, and the verification scripts are published alongside them so anyone can check the claims. Reach him at blog@heatware.net.