Command for services in linux machine
How to List Services in Linux
Let’s look at a potential scenario. While running your Linux system, you can no longer access localhost. Chances are that the HTTP service was disabled, and causing the problem.
To troubleshoot issues like this one and many others, it’s good to know how to list all services in Linux.
Fortunately, CentOS and Ubuntu – two of the most popular operating systems in their areas – share systemd. That means that the commands we are going to present are compatible with both systems.
First, we have to connect to our server using SSH. If you’re having trouble, check out our PuTTY tutorial.
Once inside, we need to be the root user to list service in Linux.
su
Now we can list all services in Linux. To do it, run the command:
sudo systemctl list-unit-files --type service --all
When the command is run, we will see all the services that are on the system. However, we will also see that some have a defined status. Let’s learn what all these mean.
- Enabled services are currently running. They usually have no problems.
- Disabled services are not active but can be activated at any time without a problem.
- Masked services won’t run unless we take that property away from them.
- Static services will only be used in case another service or unit needs it.
- Finally, there are services generated through a SysV or LSB initscript with systemd generator.
In case we want to know only the services that are active, we have to use a command together with grep, like so:
sudo systemctl | grep running
Managing Linux Services
Now it is time to learn how to manage a specific service. Note that each service represents software that works differently. In this tutorial, we will only show how to start, check the status of and stop services – the basic controls
To start a service on Linux, we need to run the following command:
sudo systemctl start [service_name]
If the service is correctly configured, it will start. Now, if we want to stop it, we will use the following command:
sudo systemctl stop [service_name]
Meanwhile, to check the status of a service we can use:
sudo systemctl status [service_name]
It is also possible to have a service run while the operating system is being loaded:
sudo systemctl enable [service_name]
Or remove it from the initial load:
sudo systemctl disable [service_name]
Comments
Post a Comment