Systemctl
Updated on 28 Dec 2018
Starting and stopping services
To start a systemd service, executing instructions in the service’s unit file, use the start command. If you are running as a non-root user, you will have to use sudo since this will affect the state of the operating system:
sudo systemctl start application
To stop a currently running service, you can use the stop command instead:
sudo systemctl stop application
Restarting and reloading
To restart a running service, you can use the restart command:
sudo systemctl restart application
If the application in question is able to reload its configuration files (without restarting), you can issue the reload command to initiate that process:
sudo systemctl reload application
Enabling and disabling services
The above commands are useful for starting or stopping commands during the current session. To tell systemd to start services automatically at boot, you must enable them.
To start a service at boot, use the enable command:
sudo systemctl enable application
This will create a symbolic link from the system’s copy of the service file (in /etc/systemd/system) into the location on disk where systemd looks for autostart files (usually /etc/systemd/system/some_target.target.wants. We will go over what a target is later in this guide).
To disable the service from starting automatically, you can type:
sudo systemctl disable application
This will remove the symbolic link that indicated that the service should be started automatically.
Keep in mind that enabling a service does not start it in the current session. If you wish to start the service and enable it at boot, you will have to issue both the start and enable commands.
Checking service status
You can check the status of a service with the following command
sudo systemctl status application
There are also methods for checking for specific states. For instance, to check to see if a unit is currently active (running), you can use the is-active command:
systemctl is-active application
This will return the current unit state, which is usually active or inactive. To see if the unit is enabled, you can use the is-enabled command:
systemctl is-enabled application
You can also check to see the dependencies that your service relies on.
sudo systemctl list-dependencies application