How To Use systemctl Command

In this article, we want to teach you How To Use the systemctl command.

SystemD is an init system that is used in some Linux to control and manage the user workspace as well as management services and processes.

Since 2015, many popular Linux distributions introduced SystemD as their init system.

Working with the systemctl command

systemctl, like other Linux commands, has different parameters.

In the rest of the article, we will discuss the type of structure for entering the systemctl command and explain its different parameters.

Systemctl command structure

The syntax of the systemctl command is like this:

systemctl [Parameter] application.suffix

As you can see, it is a simple command and for using it, you don’t need to enter any special parameter or phrase.

In the parameter section, you can specify the activity type of a service like a stop or a start.

You can enter the name of a specific service such as MySQL or Apache in the application section.

Finally, in the suffix section, you can enter the unit you want to control like the service or socket.

Note: The systemctl command will have other capabilities such as socket control, device, etc., other than service, which in this article only deals with services.

Start service with systemctl

To start a service on Linux, you should use the start parameter.

systemctl start application.service

As you can see, after the systemctl command, the start parameter is written and at the end, the service name is written.

For example, you can start the Apache service with the following command:

systemctl start apache2.service
systemctl start apache2

Note: You do not need to enter the word service at the end of the service name to start or the other operations on the service. And as you can see in the example above, both commands start the apache2 service.

Stop service with systemctl

To stop a service on Linux, you should use the stop parameter with the systemctl command.

systemctl stop application.service

For example:

systemctl stop apache2.service
systemctl stop apache

Restart service with systemctl

The restart parameter is used to completely restart a service.

systemctl restart application.service

For example:

systemctl restart apache2.service
systemctl restart apache2

Reload service with systemctl

Reloading the service is done with the reload parameter.

systemctl reload application.service

For example:

systemctl reload apache.service
systemctl reload apache

Note: The difference between reloading and restarting is that restart stops the entire service and restarts, but reload only calls the configuration file and the service continues to run. In general, the reload will be faster than the restart.

If you do not know whether to use reload or restart when reloading a service, you can use the reload-or-restart parameter.

systemctl reload-or-restart apache2.service

Activation of service in a startup with systemctl

To activate a service in a startup and start a service automatically after each reboot, you must use the enable parameter with the systemctl command.

systemctl enable application.service

For example:

systemctl enable apache2.service
systemctl enable apache2

By entering the above command, a shortcut command is created in the systemd directory, and after each time, the systemd reboot will start all the shortcuts in the systemd directory.

Disable service in a startup with systemctl command

You can use the disable parameter to deactivate a service so as not to start after reboot.

systemctl disable application.service

For example:

systemctl disable apache2.service
systemctl disable apache2

Get the status of a service with the systemctl command

You can use the status parameter with the systemctl command to get the status of a service.

systemctl status application.service

For example:

systemctl status apache2.service
systemctl status apache

Check the start status of the service

You can use the is-active parameter with the systemctl command to check the start status of the service.

systemctl is-active application.service

For example:

systemctl is-active apache2.service
systemstl is-active apache2

Check whether the service is active or inactive

The is-enable parameter is used to check whether the service is enabled or disabled, which will be related to the automatic start of the service after reboot.

systemctl is-enable application.service

For example:

systemctl is-enable apache2.service
systemctl is-enable apache2

View a list of all active systemD services

To see the list of all running services, the list-units parameter is used, which should be entered as follows:

systemctl list-units

Now if you want to get a more complete list of all services with more details, you can use the following command:

systemctl list-units --all

If you want to display a list of all inactive units, use the following command:

systemctl list-units --all --state=inactive

Conclusion

At this point, you learn how to use the main parameters of the systemctl command.

Hope you enjoy this part of our Linux Tutorials.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!