Introduction to Systemd
This article will discuss how to manage services in Systemd, a popular init system used in many Linux distributions. The systemctl
command is the primary tool for operating services in Systemd. With the systemctl
command, you can start, stop, restart, enable, and disable services, among many other actions.
Table of Contents
- Enabling Services
- Disabling Services
- Checking Service Status
- Disabling Services
- Listing Service Units
- Iterating Over Services
- Removing Services
- Conclusion
Enabling Services
Let’s start by enabling a service to be launched at system startup. To do this, use the following command:
The enable
command will configure the service to start automatically at boot time.
Disabling Services
To disable a service, use the following command:
The disable
command will prevent the service from starting automatically at boot time.
Checking Service Status
To check the status and active state of a service, use the following commands:
The status
command will give you information about the service’s status, including whether it is running. The is-active
command will inform you whether a system is an “active” or “inactive” service.
Listing Service Units
To list all active services, use the following command:
The list-units
command will give you a list of all currently active services on your system.
Iterating over Services
To iterate over a list of services and check whether they are enabled and active services, you can use the following script:
This script will list the services specified in the for loop and their active and enabled state.
Removing Services
To completely remove a service, you must stop it, disable it, remove its system files, and reload the Systemd daemon. You can use the following commands to do this:
Finally, to unmask a previously masked service, use the following command:
The unmask
command will restore the ability to start and enable the service.
Conclusion
In conclusion, Systemd provides a centralized and powerful way to manage services in Linux. With the systemctl command, you can perform many actions, including starting, stopping, restarting, enabling, disabling, and removing services. The above commands and scripts should help you begin managing services in Systemd.
Subscribe to Faizan Bashir
Get the latest posts delivered right to your inbox