How to list all the services that are running under the Linux system systemd

Linux system provides a variety of system services (such as process management, log, syslog, cron, etc.) and network services (such as remote login, e-mail, printers, Web hosting, data storage, file transfers, domain name resolution (using DNS), Dynamic IP address assignment (use DHCP), and so on).

Technically, a service or a group of processes (commonly referred to as daemon) runs continuously in the background, waiting for a request (in particular a request from the client).

Linux supports different approach to managing service (start, stop, restart, start automatically when the system starts, etc.), usually through the process or service manager. Most modern Linux distributions now use the same process manager: systemd.

Systemd is the Linux system and service manager; alternatives to the init process, compatible with SysV and LSB init scripts, systemctl command is the primary tool for managing the systemd.

In this guide, we will show how all of the following services are running under the systemd in Linux.

Linux SystemD listed in the service running

When you run without any parameters systemctl command, it displays a list of all systemd unit loaded (for more information about systemd unit, please read the systemd documentation), including the service and display their status (whether it is active ).

# systemctl

How to list all the services that are running on Linux under systemd

To list all the services that are loaded on the system (whether it is active, running, quit or failure, use the list-units and sub-command --type switch, the value of service.

# systemctl list-units --type=service

or

# systemctl --type=service

How to list all the services that are running on Linux under systemd

To list all loaded but active service, including service and have withdrawn the service is running, you can add --state option, its value is active, as shown below.

# systemctl list-units --type=service --state=active

or

# systemctl --type=service --state=active

How to list all the services that are running on Linux under systemd

If you want to quickly view all the services that are running (that is, all loaded and running services), run the following command.

# systemctl list-units --type=service --state=running

or

# systemctl --type=service --state=running

How to list all the services that are running on Linux under systemd

If you regularly use a command, you can create ~ / .bashrc file an alias command, as shown, so you can easily call it.

# vim ~/.bashrc

In the alias list then add the following, as shown in the screenshot.

alias running_services='systemctl list-units  --type=service  --state=running'

How to list all the services that are running under the Linux system systemd

Save the changes in the file and close it. From now on, use the list "running_services" command to view all loaded on the server service is running.

# Running_services # use Tab completion

How to list all the services that are running under the Linux system systemd

In addition, an important aspect of the service is the port they use. To determine the daemon program process is listening on the port, you can use netstat or ss tool, as shown.

Flags -l which means print all the listening socket, -t displays all TCP connections, -u represent all UDP connections, -n means print digital port number (rather than the application name), - p represents the display name of the application.

# netstat -ltup | grep mysqld.service

or

# Ss -ltup | grip zabbix_agentd

The fifth column shows the socket: local address: port. In this case, the process zabbix_agentd is listening on port 10050.

Also, if your server is running a firewall service, which controls how to block or allow traffic from or from a selected service or port, you can use the ufw firewall-cmd or command to list open ports in the firewall service, or (depending on on the Linux distribution you are using), as shown below.

# firewall-cmd --list-services  [FirewallD]
# firewall-cmd --list-ports

$ sudo ufw status    [UFW Firewall]

to sum up

So far it is so! In this guide, we demonstrate how to view the running services under systemd under Linux. We also describe how to view and port services or open ports in the firewall system to check how the service is listening. Do you have any supplements or question? If so, please use the comments below form to contact us.

Guess you like

Origin www.linuxidc.com/Linux/2019-08/160441.htm