The systemctl command

Control the systemd system and service manager 28 examples from the lessons of the IVski Linux Playground — try them in the terminal next to them.

Options in the examples

--now
When used with enable, disable, mask, or reenable, also start/stop/try-restart the units after the specified unit file operations succeed.

Subcommands in the examples

systemctl status
Show runtime status information about the whole system or about one or more units followed by most recent log data from the journal.
systemctl restart
Stop and then start one or more units specified on the command line.
systemctl enable
Enable one or more units or unit instances.
systemctl reload
Asks all units listed on the command line to reload their configuration.
systemctl daemon-reload
Reload the systemd manager configuration.
systemctl disable
Disables one or more units.
systemctl is-active
Check whether any of the specified units are active (i.e. running).
systemctl is-enabled
Checks whether any of the specified unit files are enabled (as with enable).
systemctl list-units
List units that systemd currently has in memory.
systemctl start
Start (activate) one or more units specified on the command line.
systemctl stop
Stop (deactivate) one or more units specified on the command line.
systemctl cat
Show backing files of one or more units.
systemctl list-unit-files
List unit files installed on the system, in combination with their enablement state (as reported by is-enabled).
systemctl mask
Mask one or more units, as specified on the command line.

Examples

systemctl status nginx
systemctl status sshd
systemctl list-units --type=service
systemctl list-units --type=service --state=running
systemctl list-unit-files --type=service
systemctl is-enabled nginx
systemctl is-active nginx
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx

Stop then start

sudo systemctl reload nginx

Reload config without dropping connections

sudo systemctl enable nginx

Start automatically on boot

sudo systemctl disable nginx

Don't start on boot (doesn't stop it now)

sudo systemctl enable --now nginx

Enable AND start immediately

sudo systemctl mask nginx

Prevents it from being started at all, even manually

sudo systemctl unmask nginx

Allows it again

sudo systemctl daemon-reload
sudo systemctl enable --now myapp

Enable + start

systemctl status myapp

Verify

systemctl status worker

"activating (auto-restart)" = a crash loop

systemctl cat worker

The unit file: what runs, and as which user?

sudo systemctl restart worker
systemctl status PID

Which service started that process?

sudo systemctl stop SERVICE

Free port 80

sudo systemctl disable SERVICE

…and keep it free after a reboot

systemctl status shop-api

Is the app running at all?

sudo nginx -t && sudo systemctl reload nginx

after a change to nginx's configuration

sudo systemctl restart shop-api

after a change to the app's configuration

Lessons that use systemctl

Related commands