- How to Manage and List Services in Linux
- Linux Services
- How to List Services in Linux
- Managing Linux Services
- Conclusion
- How to List Services in Linux
- Check and Listing linux services (systemd on Centos/RHEL 7.x)
- Listing services using Netstat Command
- Viewing /etc/services file
- Systemd services status check
- Checking the status of services in older systems (Centos/Rhel 6.x)
- How to List All Running Services Under Systemd in Linux
- Listing Running Services Under SystemD in Linux
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- How to List Systemd Services in Linux
- How to list active services in systemd
- List all the running systemd services
- List all loaded systemd services including the inactive ones
- List all the inactive systemd services
- List all the installed systemd services (even if they are not loaded)
- List all systemd services that will be run at each boot automatically
- Display the status of a particular systemd service
- Conclusion
How to Manage and List Services in Linux
Managing a Linux VPS is a critical and sometimes very difficult task if you don’t have the right tools. Often the difficulty lies in having to configure and maintain many resources and services. On a server, most resources are software making them a little easier to monitor. In this tutorial, you’ll learn all the Linux service basics, including how to manage, control, and list services in Linux.
Linux Services
A service is a program that runs in the background outside the interactive control of system users as they lack an interface. This in order to provide even more security, because some of these services are crucial for the operation of the operating system.
On the other hand, in systems like Unix or Linux, the services are also known as daemons. Sometimes the name of these services or daemons ends with the letter d. For example, sshd is the name of the service that handles SSH.
So, let us start to work and list services in Linux.
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.
Now we can list all services in Linux. To do it, run the command:
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:
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:
If the service is correctly configured, it will start. Now, if we want to stop it, we will use the following command:
Meanwhile, to check the status of a service we can use:
It is also possible to have a service run while the operating system is being loaded:
Or remove it from the initial load:
Finally, it is possible to verify which port is being used by a service. For this, we will use netstat.
To install it on Ubuntu, we just run:
If we are using CentOS 7:
Then, we run the following command:
The output will give us all the required network information.
Conclusion
Learning how to list services in Linux is easy and can greatly speed up troubleshooting! In this tutorial, we learned how to start, enable, disable, stop, and list all services in Linux! Now you can manage your Linux VPS like a pro.
Finally, we recommend you to read more about systemctl to learn all the in-depth uses. Happy developing!
Edward is an expert communicator with years of experience in IT as a writer, marketer, and Linux enthusiast. IT is a core pillar of his life, personal and professional. Edward’s goal is to encourage millions to achieve an impactful online presence. He also really loves dogs, guitars, and everything related to space.
Источник
How to List Services in Linux
In this article, I will show you how to list all running services on Linux. We will also check how to check the status of a service on a systemd system.
Let’s learn different commands used to list services on Centos/RHEL 7.x.
Check and Listing linux services (systemd on Centos/RHEL 7.x)
To list systemd services we will use systemctl command as below
Sample Output
To list active systemd services run
Sample Output
Another command you can use is
Sample Output
You can pipe the output to grep to search a more specific service as shown below
Output
Listing services using Netstat Command
Nestat command is a tool used for examining active network connections, interface statistics as well as the routing table. It’s available in all Linux distributions and here we will check how to list services using netstat command.
To check the services alongside the ports they are listening.
Output
Viewing /etc/services file
The /etc/services is an ASCII file that contains information about numerous services that client applications might use on the computer. Within the file is the service name, port number and protocol it uses, and any applicable aliases. ITO put t indicates whether a service is TCP or UDP and the name it goes by according to IANA. This information is helpful especially if you are unsure which service is running on which port by default.
To get a clearer picture, view the /etc/services file using a text editor of your choice.
Output
Systemd services status check
In newer versions of Linux, Systemd init is present. To check if a service is running, use the syntax below
Syntax
For example, to check if OpenSSH is running on your system, run
Output
Alternatively, you can use the syntax below to check if the service is active
In this case, to check if OpenSSH is active, execute
Output
Also, you can use the command below to check if a service is enabled
To check if OpenSSH is enabled, run
Output
Checking the status of services in older systems (Centos/Rhel 6.x)
For systems running SysV Init, you can check the status of services by running
For example, to check the status of OpenSSH, run
Output
You can also check all services by running
Output
We hope you found this article useful. Feel free to try out some of the systemd commands listed here.
Источник
How to List All Running Services Under Systemd in Linux
A Linux systems provide a variety of system services (such as process management, login, syslog, cron, etc.) and network services (such as remote login, e-mail, printers, web hosting, data storage, file transfer, domain name resolution (using DNS), dynamic IP address assignment (using DHCP), and much more).
Technically, a service is a process or group of processes (commonly known as daemons) running continuously in the background, waiting for requests to come in (especially from clients).
Linux supports different ways to manage (start, stop, restart, enable auto-start at system boot, etc.) services, typically through a process or service manager. Most if not all modern Linux distributions now use the same process manager: systemd.
Systemd is a system and service manager for Linux; a drop-in replacement for the init process, which is compatible with SysV and LSB init scripts and the systemctl command is the primary tool to manage systemd.
In this guide, we will demonstrate how to list all running services under systemd in Linux.
Listing Running Services Under SystemD in Linux
When you run the systemctl command without any arguments, it will display a list of all loaded systemd units (read the systemd documentation for more information about systemd units) including services, showing their status (whether active or not).
To list all loaded services on your system (whether active; running, exited or failed, use the list-units subcommand and —type switch with a value of service.
List All Services Under Systemd
And to list all loaded but active services, both running and those that have exited, you can add the —state option with a value of active, as follows.
List All Active Running Services in Systemd
But to get a quick glance of all running services (i.e all loaded and actively running services), run the following command.
List Running Services in Systemd
If you frequently use the previous command, you can create an alias command in your
/.bashrc file as shown, to easily invoke it.
Then add the following line under the list of aliases as shown in the screenshot.
Create a Alias for Long Command
Save the changes in the file and close it. And from now onwards, use the “running_services” command to view a list of all loaded, actively running services on your server.
View All Running Services
Besides, an important aspect of services is the port they use. To determine the port a daemon process is listening on, you can use the netstat or ss tools as shown.
Where the flag -l means print all listening sockets, -t displays all TCP connections, -u shows all UDP connections, -n means print numeric port numbers (instead of application names) and -p means show application name.
The fifth column shows the socket: Local Address:Port. In this case, the process zabbix_agentd is listening on port 10050.
Determine Process Port
Also, if your server has a firewall service running, which controls how to block or allow traffic to or from selected services or ports, you can list services or ports that have been opened in the firewall, using the firewall-cmd or ufw command (depending on the Linux distributions you are using) as shown.
List Open Services and Ports on Firewall
That’s all for now! In this guide, we demonstrated how to view running services under systemd in Linux. We also covered how to check the port a service is listening on and how to view services or ports opened in the system firewall. Do you have any additions to make or questions? If yes, reach us using the comment form below.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник
How to List Systemd Services in Linux
While systemd solves many problems with system management, it is also confusing sometimes.
Even a simple task like listing systemd services could send you thinking.
In this article, I’ll show you how to list systemd services. I’ll also explain the output so that it is easier for you to understand the different states of the services.
I presume that you have some knowledge of systemd but even if you don’t, it should be fine.
How to list active services in systemd
systemd services are managed by the systemctl command. If you run systemctl without any arguments, it invokes the default list-units sub-command and it lists various types of systemd units like services, sockets, targets etc.
But your aim is to list the services so you specify the unit type with —type flag like this:
Did you notice that I didn’t specify the list-units sub-command because it is the default? If you want to follow the convention, you may specify that as well. I prefer it this way and I’ll follow this convention in the rest of the tutorial.
In both cases the output will be the same. By default, this command shows only loaded and active services in alphabetical order:
Let me explain the output:
- UNIT : name of the systemd unit.
- LOAD : whether the unit configuration file has been parsed by systemd.
- ACTIVE : high level state of the unit.
- SUB : low level state of the unit. An active unit can be in the running state or exited state. This value depends on the service type.
As you can see, you could list the loaded services on your Linux system. But an active systemd service could be running or could be exited (after running successfully).
List all the running systemd services
The active state can also have a sub-status like running, exited etc. You can use the same —state flag with the sub-state.
To list the running systemd services, use the —state=running flag like this:
Here’s a sample output for my system showing some of the running systemd services:
List all loaded systemd services including the inactive ones
By default, the systemctl command only displays the loaded and active units.
If you want to list all the loaded services including the inactive ones, use the —all flag:
You can now see even the inactive services:
List all the inactive systemd services
If you want to see only the inactive services, you can combine various flags like —all and —state like this:
As you can see in the output, it displays all the inactive systemd services:
List all the installed systemd services (even if they are not loaded)
Every systemd unit, be it service or socket or any other unit, has a unit file which
Here’s what you should see:
Explaining each state type will be too lengthy and is not in the scope of this article. Maybe I’ll write about it in the future.
List all systemd services that will be run at each boot automatically
To see all the systemd services that will run automatically every time your system boots, use this command:
Are you confused with the enabled state? That’s normal. Many new user confuse an enabled system service with a running service.
However, an enabled systemd service means that the service will be activated automatically when the system boots.
Do you notice the Vendor Preset? It was also present in the previous example.
Vendor preset defines the automatic behavior of the systemd unit when a program is installed.
Suppose you installed a new program XYZ. This XYZ has a systemd service called xyz.service with vendor preset enabled. This means that after installing the program, when you boot the system, this xyz.service will be activated automatically at the boot time.
If the vendor preset is disabled, you’ll have to manually set it to enable. Once it is enabled, it starts automatically each boot.
Display the status of a particular systemd service
So far, you have seen various ways of listing services. But nothing focuses on a single service.
You can get detailed information on a systemd service using the status sub-command of systemctl. Tab completion works with this command.
Here’s an example with the network manager service:
You can see that it provides plenty of useful information like the state of the service, man page of the service, memory it consumes, process id etc. It also shows the last few journald logs for the service.
If you want to check whether a service is active or not in a shell script, you can use the is-active sub-command. The output is 0 for active.
Similarly, if you want to check whether a service is enabled (set to start automatically at boot time), you can use is-enabled sub-command. Output is 0 for enabled service.
Conclusion
I think you now have a better understanding on listing systemd services. I do hope you learned a few new things about systemd and systemctl command.
Don’t hesitate to provide your feedback, questions or suggestions in the comment section.
Источник