systemctl” command interacts with systemd to manage services, also known as units, in your system by providing options like listing, starting, stopping, restarting, reloading, etc.
|Description||Managing Systemd Services and Units|
|Root or Sudo Privileges||Yes|
|Host System and Architecture||Ubuntu 22.10 (x64)|
|OS Compatibility||Ubuntu, Manjaro, Fedora, etc.|
The following command will list all the running and stopped systemd services.
$ systemctl list-unit-files
List All Running Services
The following command will only list the running systemd services with the help of the grep command.
$ systemctl list-unit-files | grep enabled
Or you can execute the following command to get the list of running services in the tree hierarchy.
$ systemctl status
List of Failed Services
In some cases, the systemd services get interrupted by another running process or a configuration error that you can list using the following command.
$ systemctl --failed
Start/Stop/Restart/Reload a Services
Specify the systemd service name to start the service.
$ sudo systemctl start [SERVICE-NAME]
To stop the existing running service, place its unit name in the following command.
$ sudo systemctl stop [SERVICE-NAME]
If you want to restart your service, pass the unit name to the following command.
$ sudo systemctl restart [SERVICE-NAME]
Don’t forget to consider that the above command will prevent your users from accessing your service if you are restarting a service like Apache or NGINX.
If you made a minor configuration change, reload the service instead of restarting by using the following command.
$ sudo systemctl reload [SERVICE-NAME]
Check the Status of Service
To check the status of a service, specify its unit name in the following command.
$ systemctl status [SERVICE-NAME]
Find the Service is Enabled
Issue the following command to find out if the service is enabled (an enabled service will automatically start on boot).
$ systemctl is-enabled [SERVICE-NAME]
Auto start Service on Boot
If you want to start your service automatically on system boot, then enable it using the following command.
$ sudo systemctl enable [SERVICE-NAME]
Disable Auto Start Service
If you want to disable an existing enabled service that automatically starts on system boot, then issue the following command.
$ sudo systemctl disable [SERVICE-NAME]
If you made any changes to your system or added a systemd service, then execute the following command to reload the systemd daemon for scanning new or changed services.
$ systemctl daemon-reload
That’s all for now, Bye bye.