In easy terms, a service is a program or application in Linux that runs or expects to run in the background. That is, it is running without the need for the user to be aware of it all the time.
Generally, a Linux service has the following characteristics:
- No graphical interface. That is, users cannot interact with them through an interface.
- The services are started with the system. Of course, in this case, I refer to the system services. Third-party services such as MySQL can be configured to start or not with the system.
- When running in the background, they wait for a signal to start a certain task.
These features are not restrictive to all services but it gives you a general idea of what they are.
At this point, you are probably wondering what some of the Linux services are. Well, some services are:
And many more applications are managed through a service.
Service management on Linux
The most important and modern distributions have migrated to systemd to manage system services. systemd has a command called systemctl with which you can perform basic tasks.
Normally, you want to know which are the system services, and for that, you just need to run in a terminal:
sudo systemctl list-units --type service
As you can see, you need root permissions for this.
You will get an output similar to this.
UNIT LOAD ACTIVE SUB DESCRIPTION accounts-daemon.service loaded active running Accounts Service acpid.service loaded active running ACPI event daemon alsa-restore.service loaded active exited Save/Restore Sound Card State apache2.service loaded active running The Apache HTTP Server apparmor.service loaded active exited Load AppArmor profiles avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack
Some key points of the screen output obtained
- UNIT: Name of the service
- LOAD: To know if it is loaded in the memory
- ACTIVE: State in which it is (High level) can be active, reloading, inactive, failed, activating, deactivating.
- SUB: State of activation (Low level) can be in one of the following states: dead, closed, failed, inactive or running.
- Description: Brief description of the service
By default, this command shows only the active services, but you can further expand the output by showing all of them, including the inactive ones.
sudo systemctl list-units --type service --all
The handling of the services as such is simple. If you want to start one, just follow this syntax
sudo systemctl start [service]
sudo systemctl start apache2
Occasionally, you may want to stop the service
sudo systemctl stop [service]
Or restart it to apply some changes to the tool’s settings
sudo systemctl restart [service]
Occasionally, you may want to reload the configuration of the service or the application that manages it.
sudo systemctl reload [service].
Earlier I told you about services that start with the system, if you want one to do so then
sudo systemctl enable [service]
If a service already starts with the system you want to disable it then run
sudo systemctl disable [service].
Finally, you can check the status of a service with the command
sudo systemctl status [service]
This last command is one of the most commonly used because it monitors the operation of applications associated with a service.