start/stop/restart act right now; enable/disable decide whether the service starts at boot.
systemctl status tells you whether a service is running or failed, with the latest few log lines.
enable --now does both at once; mask blocks a service completely, so use it carefully.
After this article you can control a service on Ubuntu 24.04 LTS (systemd 255) with systemctl: check its status, start, stop and restart it, and set it to start when the machine boots.
If you are not yet familiar with units, first read systemd and unit files on Ubuntu 24.04: how services are described and started.
An Ubuntu 24.04 machine and an account with sudo.
The examples use two service names: systemd-resolved.service (built in, only for viewing) and hello.service (a service you wrote yourself, assuming you created it as in the previous article).
Replace them with your real service names.
You can drop the .service suffix: systemctl status hello and systemctl status hello.service are the same.
Steps
systemctl status systemd-resolved
The output has a few notable parts: the Loaded: line shows which unit file is in use and whether the service is enabled (enabled); the Active: line shows active (running), inactive (dead) or failed; below are the latest few log lines.
If the output opens in a scrolling pager, press q to quit, or add --no-pager.
Three shorter commands, handy in scripts:
systemctl is-active hello # prints active, inactive, failed...
systemctl is-enabled hello # prints enabled, disabled, masked...
systemctl list-units --failed # lists units in the failed state
sudo systemctl start hello
sudo systemctl stop hello
These two commands only affect the current run: after the machine reboots, the service goes back to following its enable/disable setting.
sudo systemctl restart hello
sudo systemctl reload hello
sudo systemctl reload-or-restart hello
restart stops and starts again: there is a short interruption.
reload asks the program itself to re-read its configuration without stopping, but it only works if the service declares how to reload (ExecReload=).
reload-or-restart reloads if possible, otherwise restarts; useful when you are not sure.
Keep two easily confused things apart: systemctl daemon-reload reloads systemd's unit files, while reload reloads the service's own configuration.
sudo systemctl enable hello
sudo systemctl disable hello
enable creates the links described by the [Install] section of the unit file but does not start the service right away. To enable and start in one go, use the --now flag:
sudo systemctl enable --now hello
sudo systemctl disable --now hello
The second form both removes start-at-boot and stops the service immediately.
sudo systemctl mask hello
sudo systemctl unmask hello
mask makes the unit impossible to start, even when another unit asks for it or you type start.
Warning: only mask a service when you understand it; masking a system service by mistake can stop the features that depend on it. If that happens, unmask is the way back.
When a service fails, systemd remembers the failed state. After you have fixed the problem, clear that mark with:
sudo systemctl reset-failed hello
Try a small cycle with hello:
sudo systemctl enable --now hello
systemctl is-active hello # expected: active
systemctl is-enabled hello # expected: enabled
sudo systemctl restart hello
systemctl status hello --no-pager
If status shows active (running) with a fresh start time after the restart, everything is right.
To see details of why something failed, read the logs as described in the next article on journalctl.
Failed to enable unit: Unit file hello.service does not exist: the name is wrong or the file is not yet in /etc/systemd/system/; run sudo systemctl daemon-reload after creating the file.
Access denied or an authentication prompt: you are missing sudo for a command that changes state.
A service is enabled yet does not start at boot: enable does not start it now; check systemctl is-enabled and the logs of that boot.
failed right after restart: read the logs; the usual cause is a wrong path in ExecStart= or a broken configuration.
Restarting over and over: Restart=always can hide a real fault; systemd also has a limit on the number of attempts, and when it is exceeded the service goes to failed.
Remember two groups of commands: start/stop/restart/reload for what happens now, enable/disable for what happens at boot, and --now to combine them.
Use status, is-active and is-enabled to learn the state, and use mask only when you truly need it.