El utilitario systemctl
permite controlar el gestor de inicio y servicios systemd.
Listar servicios
Para listar los servicios activos, simplemente ejecutar systemctl list-units
.
Si se desea filtrar, es posible emplear una expresión regular, por ejemplo:
root@www:~# systemctl list-units php* UNIT LOAD ACTIVE SUB DESCRIPTION php7.3-fpm.service loaded active running The PHP 7.3 FastCGI Process Manager phpsessionclean.timer loaded active waiting Clean PHP session files every 30 mins 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. 2 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'.
Si se desean listar todas las unidades, activas e inactivas, agregar la opción -a
:
root@www:~# systemctl -a list-units php* UNIT LOAD ACTIVE SUB DESCRIPTION php7.3-fpm.service loaded active running The PHP 7.3 FastCGI Process Manager phpsessionclean.service loaded inactive dead Clean php session files phpsessionclean.timer loaded active waiting Clean PHP session files every 30 mins 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. 3 loaded units listed. To show all installed unit files use 'systemctl list-unit-files'.
Si se desean listar todos los servicios instalados (habilitados y deshabilitados), ejecutar:
root@www:~# systemctl -a list-unit-files php* UNIT FILE STATE php7.0-fpm.service disabled php7.2-fpm.service disabled php7.3-fpm.service enabled phpsessionclean.service static phpsessionclean.timer enabled 5 unit files listed.
Ahora bien, systemd llama “units” (unidades) a los servicios, pero una unidad puede ser también un socket, un dispositivo, un timer, etc. (consultar la página de manual “systemd” para conocer todos los tipos de unidades).
Si se desea listar absolutamente todas las unidades, ejecutar: systemctl --all
.
Para listar sólo las unidades que corresponden con servicios, es necesario filtrar por tipo de unidad empleando la opción -t service
:
root@www:~# systemctl -a -t service list-units php* UNIT LOAD ACTIVE SUB DESCRIPTION php7.3-fpm.service loaded active running The PHP 7.3 FastCGI Process Manager phpsessionclean.service loaded inactive dead Clean php session files 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. 2 loaded units listed. To show all installed unit files use 'systemctl list-unit-files'.
Consultar el estado de un servicio
Para consultar el estado de un servicio se debe emplear el subcomando status
con el nombre de la unidad como parámetro (al revés que el utilitario service
):
root@www:~# systemctl status php7.3-fpm.service ● php7.3-fpm.service - The PHP 7.3 FastCGI Process Manager Loaded: loaded (/lib/systemd/system/php7.3-fpm.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2020-11-19 17:35:26 -03; 4 days ago Docs: man:php-fpm7.3(8) Process: 24438 ExecStopPost=/usr/lib/php/php-fpm-socket-helper remove /run/php/php-fpm.sock /etc/php/7.3/fpm/pool.d/www.conf 7 Process: 24483 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/7.3/fpm/pool.d/www.conf Main PID: 24462 (php-fpm7.3) Status: "Processes active: 0, idle: 20, Requests: 363350, slow: 0, Traffic: 5.3req/sec" Tasks: 21 (limit: 4915) CGroup: /system.slice/php7.3-fpm.service ├─ 9842 php-fpm: pool www.linuxito.com ├─16069 php-fpm: pool blog.linuxito.com ├─16267 php-fpm: pool blog.linuxito.com ├─16392 php-fpm: pool www.linuxito.com ├─17013 php-fpm: pool www.linuxito.com ├─18461 php-fpm: pool www.linuxito.com ├─18466 php-fpm: pool www.linuxito.com ├─18499 php-fpm: pool www.linuxito.com ├─18501 php-fpm: pool www.linuxito.com ├─19446 php-fpm: pool www.linuxito.com ├─19449 php-fpm: pool www.linuxito.com ├─24462 php-fpm: master process (/etc/php/7.3/fpm/php-fpm.conf) ├─24475 php-fpm: pool blog.linuxito.com ├─24476 php-fpm: pool blog.linuxito.com ├─24477 php-fpm: pool blog.linuxito.com ├─24481 php-fpm: pool www ├─24482 php-fpm: pool www ├─24531 php-fpm: pool blog.linuxito.com ├─24573 php-fpm: pool www.linuxito.com ├─24584 php-fpm: pool blog.linuxito.com └─25902 php-fpm: pool blog.linuxito.com Nov 19 17:35:26 www.linuxito.com systemd[1]: Starting The PHP 7.3 FastCGI Process Manager... Nov 19 17:35:26 www.linuxito.com systemd[1]: Started The PHP 7.3 FastCGI Process Manager.
Referencias
man systemctl
man systemd