Linux check running services

How to Check Service Status in Linux

Systemd initialization system allows you not only to start and stop services but also to check their status and show information about them. Use the systemctl utility with the status command to get information about the service. For example, if you want to get the state of the Nginx web server, run this command:

sudo systemctl status nginx

Usually, the utility prints information with pagination because data does not fit the terminal window. If you want to disable pagination, use the —no-pager option:

sudo systemctl status nginx —no-pager

Let’s have a look at the information which is printed by this command:

  • Loaded — the loaded value means that the unit file was loaded successfully. Here you can see other values, for example, masked, when the unit is masked or not-found when the requested unit does not exist. Also in this line, you can find the path to the unit file.
  • Active — the current unit state and sub-state. If the unit is running you will see active (running) or inactive(dead) if nobody has started it since the last system boot. If something goes wrong, you will see the failed state.
  • Docs — the name of man pages for the service.
  • Process — service processes, their states, and exit codes.
  • Main PID — identifier of the main service process.
  • Tasks — number of tasks which are running for this service.
  • Memory — reflects how much RAM is used.
  • CPU — reflects the CPU usage.

If you want to get all possible values for the Loaded and Active fields, run this command:

After these information fields, you can see the service log. By default, it prints the last ten lines from the main service output. If you want to get more lines, use the —lines option. For example, use this command if you want to get the last 50 lines:

sudo systemctl status —lines=50 avahi-daemon

In rare cases, for example in no-pager mode, log lines may be ellipsized to fit the screen. You can use the -l or —full options to avoid this:

Читайте также:  Create usb boot from linux

sudo systemctl -l status avahi-daemon —no-pager

If you want to get all available logs, you should use the journalctl command with the -u option and service name. For example:

journalctl -eu nginx.service

The output starts from the end. You can use the arrow keys on your keyboard to scroll logs. Also, you can view the service state change history using the journalctl command with the -xeu options. For example:

journalctl -xeu nginx.service

You can find more information about service management in the previous article.

Found a mistake in the text? Let me know about that. Highlight the text with the mistake and press Ctrl+Enter.

Источник

How to List All Running Services Under Systemd in Linux

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).

List Systemctl Units in Linux

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.

# systemctl list-units --type=service OR # systemctl --type=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.

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

List All Active Running Services in Systemd

But to get a quick glance at all running services (i.e. all loaded and actively running services), run the following command.

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

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.

Читайте также:  Linux libstdc so 6

Then add the following line under the list of aliases as shown in the screenshot.

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

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.

# running_services #use the Tab completion

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 command 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 the application name.

# netstat -ltup | grep zabbix_agentd OR # ss -ltup | grep zabbix_agentd

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.

# firewall-cmd --list-services [FirewallD] # firewall-cmd --list-ports $ sudo ufw status [UFW Firewall]

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 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.

Источник

How to Check Services Running in Linux

Different operations are running in the background of Ubuntu and are not visible to the users. These services run for specific purposes and can only be managed by some utilities. One of these utilities is “systemctl” to start/stop services. These services make the processing unit of the computer busy, which consumes the battery health as well as slows down other programs.

Considering the importance of services, this post will provide the methods to check services on Linux. The outcomes of this article are:

Читайте также:  Test vulkan on linux

Method 1: How to Check Services Running in Linux Using “systemctl” Utility?

As discussed earlier, the “systemctl‘ utility is the most used to manage the services on Linux-based systems. Let’s see how it can be used to list down services:

List Down Machine Services

First of all, we are supposed to list down all the machine services using the systemctl command:

$ systemctl list-units --type=service --all

There are different states of the services, these can be loaded, running, or not found.

Check Running Services

To display all the running services, use the command:

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

All the services in a running state will be displayed on the screen.

List Down the Loaded Services

Similarly, to display all the loaded services, simply use the command:

$ systemctl list-units --type=service

Show the Enabled Services

Likewise, to display the enabled services, use the command:

$ systemctl list-unit-files --state=enabled

List Down Disabled Services

To display the disabled services, change the state in the above command:

$ systemctl list-unit-files --state=disabled

These are the different commands that can be used to display the status of the services using the systemctl utility.

Method 2: How to Check Services Running on Linux Using “service” Command?

Apart from the “systemctl” utility, another utility named “service” can also provide the list of services running in Linux.

List Down All Services

The following “service” command will list down all the services on the Linux system:

In the above figure, the services with the “+” sign are running on the system where the services with the “-” sign are not running on the system.

Check Running Services

To list down only the running services, use the command:

Check Only Stopped Services

Likewise, to display the services which are not running but are installed on the system, use the command:

In these ways, the running services can be checked on Ubuntu.

That’s all from this guide!

Conclusion

To check the services running on Linux, open the terminal and run the command “systemctl list-units –type=service –state=running”. The service command “service –status-all | grep ‘\[ + \]’” can also list all the running services on Linux. Apart from the running services, the “systemctl” utility and “service” command can also be used to list the stopped or all services. This post has provided all the possible commands to check services running in Linux.

TUTORIALS ON LINUX, PROGRAMMING & TECHNOLOGY

Источник

Оцените статью
Adblock
detector