Просмотр запущенных сервисов linux

How to list all enabled services from systemctl?

How can I list all enabled services from systemctl ? I know running systemctl command by itself lists all services, but I would like to only get the enabled ones.

Fascinating. The lowest rated answer is the most «correct» answer, even though it is clearly not the best answer. This excellent question (and its answers) is an interesting example of how systemd violates the long-standing (and brilliant) design principles of Unix & Co. @FelipeAlvarez complains that the most-accepted answer assumes systemd follows the unix design philosopy, but systemd/systemctl can do exactly what he wants (most experienced users will just consider that complete bloat). I begin to see more clearly why Linus Torvalds is so vehemently critical of systemd.

If you want to list «templated» services (blabla@instance.service), do not forget to add «—all» — thanks to @rafdouglas below.

9 Answers 9

systemctl list-unit-files | grep enabled will list all enabled ones.

If you want which ones are currently running, you need systemctl | grep running .

Use the one you’re looking for. Enabled, doesn’t mean it’s running. And running doesn’t mean it’s enabled. They are two different things.

Enabled means the system will run the service on the next boot. So if you enable a service, you still need to manually start it, or reboot and it will start.

Running means it’s actually running right now, but if it’s not enabled, it won’t restart when you reboot.

annoying to have to use an external tool (grep) to show this vital information. But thank you for showing us the way 🙂

@FelipeAlvarez Correct. But that’s how Linux works. Many small binaries that work well with each other. systemctl does what is asked, it lists services. There is no filtering command built-in to systemctl because grep already exists and can do that well with any program’s output. It’s how it’s always been 🙂

I agree and so it should be. But, systemd already tries to do SO much that I wonder why it can’t list enabled services?

systemctl | grep running do not list anything to me! Even if something is running is only listed as for his status like: enabled, disabled, masked, static

—state=

The argument should be a comma-separated list of unit LOAD , SUB , or ACTIVE states. When listing units, show only those in the specified states. Use —state=failed to show only failed units.

LOAD : Reflects whether the unit definition was properly loaded.
ACTIVE : The high-level unit activation state, i.e. generalization of SUB .
SUB : The low-level unit activation state, values depend on unit type.

Читайте также:  Linux uniq and sort

Though you can also use this to only show enabled units with:

systemctl list-unit-files --state=enabled 

If a unit is enabled that means that the system will start it on startup. Though setting something to enabled doesn’t actually also start it so you will need to do that manually, or reboot the system after setting it to enabled .

Источник

Управление сервисами в Linux. Команда systemctl

Systemd в Linux. Команда systemctl

Сервисы или службы — это программы, которые работают в системе Linux в фоновом режиме. Обычно они запускаются при загрузке системы. Большинство сервисов необходимы для полноценной работы системы, то есть они являются своего рода кирпичиками, из которых строится работающая система.

При запуске системы загружается целый ряд сервисов, которые включены для автозагрузки. Сервисы работают пока система запущена, и выгружаются при выключении системы.

Чаще всего в Linux дистрибутивах для инициализации сервисов используется демон Systemd. К Systemd-дистрибутивам относятся Ubuntu, Debian, Linux Mint, Fedora, openSUSE, Solus и другие.

Есть дистрибутивы, которые не используют Systemd. Вместо Systemd могут использоваться такие системы инициализации, как Upstart, SysV.

В качестве примеров сервисов можно привести: веб-сервер Apache, Network Manager, файрвол Ufw и другие.

Для управления сервисами (Systemd) используется утилита systemctl . Ниже мы рассмотрим основные команды данной утилиты.

Список сервисов

Чтобы просмотреть список всех сервисов можно воспользоваться командой:

Список всех сервисов Systemd

Данная команда пробегает по алфавитному списку всех доступных сервисов и выполняет для них команду status.

В выводе команды используются следующие обозначения:

  • [ + ] — запущенный сервис.
  • [ — ] — остановленный сервис.
  • [ ? ] — для данного сервиса отсутствует команда status.

Запуск сервиса

Для запуска сервиса используется команда systemctl start имя_сервиса

Останов сервиса

Для остановки сервиса используется команда systemctl stop имя_сервиса

Перезапуск сервиса

Перезапуск сервиса выполняется командой systemctl restart имя_сервиса

sudo systemctl restart ufw

Обычно перезапуск конкретного сервиса требуется, когда были изменены настройки данного сервиса.

Некоторые сервисы поддерживают «мягкую» перезагрузку. В этом случае сервис считывает связанные с ним файлы конфигурации, но не прерывает процесс сервиса. Для выполнения «мягкой» перезагрузки используется команда systemctl reload имя_сервиса . Не все сервисы поддерживают «мягкую» перезагрузку. Если она не поддерживается, то появится сообщение вида: Failed to reload ufw.service: Job type reload is not applicable for unit ufw.service.

Автозагрузка сервисов

Чтобы сервис стартовал (загружался) при запуске системы, его нужно включить в список автозагрузки. Для этого используется команда systemctl enable имя_сервиса

sudo systemctl enable ufw Synchronizing state of ufw.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable ufw

Чтобы включить сервис в автозапуск и сразу же запустить используется команда:

Чтобы удалить сервис из автозагрузки, используется команда systemctl disable имя_сервиса

sudo systemctl disable ufw

systemctl enable disable

Статус сервиса

Для вывода информации (статуса) сервиса используется команда systemctl status имя_сервиса

systemctl status

Чтобы проверить, запущен ли в данный момент сервис, используется команда systemctl is-active имя_сервиса

systemctl is-active ufw acive

Чтобы проверить, включен ли сервис для автозапуска при загрузке системы, используется команда systemctl is-enabled имя_сервиса

systemctl is-enabled ufw enabled

systemctl is-enabled is-active

Заключение

Мы рассмотрели наиболее часто используемые команды утилиты systemctl. Полный список команд и опций утилиты systemctl можно получить, выполнив:

Читайте также:  Изменить размер экрана линукс

Источник

How to List Running Services in Linux

How to List Running Services in Linux

In simpler terms, a Linux service is a server’s response to a request that performs a specific task. It is an application or a program that generally executes in the background.

As a user, you are mostly unaware of all the services running in the background because there are plenty of them.

You might have run through the term daemon most probably while working or learning about services. Daemon is a non-interactive program that runs in the background and strictly does not provide any interfaces for the user to control it.

Some of the common characteristics of a Linux service are:

  • There is no GUI(Graphical User Interface).
  • Most of the native services start along with the start of the OS.
  • Some services wait for an interrupt or a signal to get started.

Some common examples of Linux services are mysql, apparmor, httpd and nfs.

Table of Contents

Detecting the System Manger

Detecting the system manager of your Linux system is the elementary step to listing the running services. This step is essential as the commands for listing the services are based on the system manager.

The system manager is the first process that starts in your system. So, you can use the following command to list the first process in the system.

The output looks like this if the system manager is systemd.

PID TTY TIME CMD 1 ? 00:00:02 systemd

systemd is used in the newer Linux distributions.

If the system manager used is SysV , the output looks like this.

PID TTY TIME CMD 1 ? 00:00:02 init

SysV is also known as init or initialization. It was used in early Linux distributions, and lately, it has been replaced by systemd .

Thus, you can find the system manager from the CMD column of the outputs above. According to the service manager present, you can use the respective methods.

Listing Services in the systemd Service Manager

There are a couple of ways to list the running services when the system manager is systemd , and let’s explore each of them.

Using the systemctl Command

You can use the systemctl command to list the services in your Linux system.

Using the list-units subcommand with the —type=service option will list all the services. It includes active, failed, active (exited), and active (running) services.

systemctl list-units --type=service

The output of the above command is shown below.

Notes/Articles/list running services in linux/list_service_1.png

In the output above, you can notice several columns. Let’s get to know what they represent.

UNIT: It is an object that starts, stops and manages the services.

LOAD: It states whether the particular unit is correctly loaded.

Читайте также:  Copy all directory contents linux

ACTIVE: It is a high-level state that determines whether the unit is active.

SUB: It represents the low-level activation state of the unit.

DESCRIPTION: It describes the task that the unit performs.

In the sections below, you will learn to list the services according to their states. Some of the systemd states are active, inactive, activating, deactivating, failed, not-found, dead, etc.

Listing the ACTIVE Services using the systemctl Command

You can use specific options and the systemctl command to filter the services. With the —state option, you can set the state of the services. For example, if you want only the active services listed, you can use the following command.

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

We have used the —state option with the value active to denote only the active services. In the output below, you can see the active status of all the units.

Notes/Articles/list running services in linux/list_service_2.png

Listing the FAILED Services using the systemctl Command

Similarly, you can list only the failed services with the following command.

systemctl list-units --type=service --state=failed

Notes/Articles/list running services in linux/list_service_3.png

Listing the running Services using the systemctl Command

To list only the running services, use the following command.

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

Notes/Articles/list running services in linux/list_service_4.png

A running service has an active value for the ACTIVE state and a running value for the SUB state.

Listing the exited Services using the systemctl Command

Exited services are the one-shot type of services which does their job and are closed. The following command can be used to list the exited services.

systemctl list-units --type=service --state=exited

Notes/Articles/list running services in linux/list_service_5.png

The ACTIVE state holds the value active for exited service, while the SUB state has the value exited.

Listing Services in the SysV Service Manager

In this section, you will learn a few ways of listing the system’s services that use the SysV service manager.

Listing the Services with service Command

In the system with the SysV service manager, you can use the service command to list all the services.

The output of the command is shown below.

Notes/Articles/list running services in linux/list_service_6.png

The symbols in the brackets represent the status of the services.

  • : It represents the services that are stopped.
  • +: It represents the services that are running.
  • ?: It represents the services without the status command.

To list only the running services, you can use the following command.

service --status-all | grep running

Listing Services with the ls Command

Another way you can list the services of init scripts is using the ls command. Using the ls command on the directory containing the init scripts does the job. The init scripts are located in the path /etc/init.d. An example is shown below.

The output of the above command is shown below.

Notes/Articles/list running services in linux/list_service_7.png

Conclusion

In this tutorial, you learned to identify the system manager used in your Linux system. Thus, you grasped the idea of using the various commands to list the Linux services.

Источник

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