Systemctl is a command line utility that is used to manage systemd
services on Linux systems, and if you don't regularly manage Linux systems, you might find yourself guessing at the syntax before having to look it up.
So if you arrived here because that's you, here are the basics:
Check the status of a service
systemctl status servicename
The output will show the path of the loaded service, whether the service is active (running), where to see the documentation for the service (in the above example the command man cron
would load the manual for cron). It will also show the most recent log entries for the service.
Start a service
systemctl start servicename
Stop a service
systemctl stop servicename
Check for failed services
This will list all services that are in a failed state (i.e. they've crashed or errored and stopped). The simple command here is:
systemctl --failed
But this is equivalent to:
systemctl list-units --state=failed
Enable a service
Enabling a service means it will start automatically when the system next starts
systemctl enable servicename
Where as:
systemctl enable --now servicename
The above will enable the service for automatic start on next reboot but it will also immediately start the service too.
Disabling a service
This is the opposite of aboveādisabling a service will prevent it starting after the next reboot, disable --now
will do the same but also immediately stop the service.
systemctl disable servicename
systemctl disable --now servicename
What else?
These are some basic commands, but if there's anything you regularly forget, please leave a comment so I can add it here!