Systemd é um gerenciador de sistemas e serviços para Linux; um substituto para o processo init, que é compatível com os scripts init SysV e LSB e o comando systemctl é a principal ferramenta para gerenciar o systemd.
Tecnicamente, um serviço é um processo ou grupo de processos (comumente conhecidos como daemons) rodando continuamente em segundo plano, aguardando a chegada de solicitações (especialmente de clientes).
Dica: Se você usa com frequência esses comandos, pode criar um alias em seu arquivo ~/.bashrc
Visualizando Informações
Se você executar apenas systemctl verá essas informações
maria@debian11VM:~$ systemctl UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active waiting Arbitrary Executable File Formats File System Automount Point sys-devices-pci0000:00-0000:00:01.1-ata2-host1-target1:0:0-1:0:0:0-block-sr0.device loaded active plugged VBOX_CD-ROM sys-devices-pci0000:00-0000:00:03.0-net-enp0s3.device loaded active plugged 82540EM Gigabit Ethernet Controller (PRO/1000 MT Desktop Adapter) sys-devices-pci0000:00-0000:00:05.0-sound-card0-controlC0.device loaded active plugged /sys/devices/pci0000:00/0000:00:05.0/sound/card0/controlC0 sys-devices-pci0000:00-0000:00:0d.0-ata3-host2-target2:0:0-2:0:0:0-block-sda-sda1.device loaded active plugged VBOX_HARDDISK 1 sys-devices-pci0000:00-0000:00:0d.0-ata3-host2-target2:0:0-2:0:0:0-block-sda-sda2.device loaded active plugged VBOX_HARDDISK 2 sys-devices-pci0000:00-0000:00:0d.0-ata3-host2-target2:0:0-2:0:0:0-block-sda-sda5.device loaded active plugged VBOX_HARDDISK 5 sys-devices-pci0000:00-0000:00:0d.0-ata3-host2-target2:0:0-2:0:0:0-block-sda.device loaded active plugged VBOX_HARDDISK sys-devices-platform-serial8250-tty-ttyS0.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS0 sys-devices-platform-serial8250-tty-ttyS1.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS1 sys-devices-platform-serial8250-tty-ttyS2.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS2 sys-devices-platform-serial8250-tty-ttyS3.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS3 sys-module-configfs.device loaded active plugged /sys/module/configfs sys-module-fuse.device loaded active plugged /sys/module/fuse sys-subsystem-net-devices-enp0s3.device loaded active plugged 82540EM Gigabit Ethernet Controller (PRO/1000 MT Desktop Adapter) -.mount loaded active mounted Root Mount dev-hugepages.mount loaded active mounted Huge Pages File System dev-mqueue.mount loaded active mounted POSIX Message Queue File System run-user-1000.mount loaded active mounted /run/user/1000 sys-fs-fuse-connections.mount loaded active mounted FUSE Control File System
Vendo Serviços de Acordo com o Status no systemd
Os serviços podem estar com algum desses status:
- active ou ativo
- running ou executando
- exited ou terminado
- failed ou com falha
Para listar todos os serviços carregados em seu sistema (sejam active, running, exited ou com failed, use o subcomando list-units e a opção –type com o valor service.
Podemos executar
maria@debian11VM:~$ sudo systemctl list-units --type=service
ou assim
maria@debian11VM:~$ sudo systemctl --type=service
Veja o resultado como exemplo,
maria@debian11VM:~$ sudo systemctl --type=service UNIT LOAD ACTIVE SUB DESCRIPTION apache2.service loaded active running The Apache HTTP Server apparmor.service loaded active exited Load AppArmor profiles console-setup.service loaded active exited Set console font and keymap cron.service loaded active running Regular background program processing daemon dbus.service loaded active running D-Bus System Message Bus getty@tty1.service loaded active running Getty on tty1 ifup@enp0s3.service loaded active exited ifup for enp0s3 ifupdown-pre.service loaded active exited Helper to synchronize boot up for ifupdown keyboard-setup.service loaded active exited Set the console keyboard layout kmod-static-nodes.service loaded active exited Create list of static device nodes for the current kernel networking.service loaded active exited Raise network interfaces rsyslog.service loaded active running System Logging Service ssh.service loaded active running OpenBSD Secure Shell server systemd-journal-flush.service loaded active exited Flush Journal to Persistent Storage systemd-journald.service loaded active running Journal Service systemd-logind.service loaded active running User Login Management systemd-modules-load.service loaded active exited Load Kernel Modules systemd-random-seed.service loaded active exited Load/Save Random Seed systemd-remount-fs.service loaded active exited Remount Root and Kernel File Systems systemd-sysctl.service loaded active exited Apply Kernel Variables systemd-sysusers.service loaded active exited Create System Users systemd-timesyncd.service loaded active running Network Time Synchronization systemd-tmpfiles-setup-dev.service loaded active exited Create Static Device Nodes in /dev systemd-tmpfiles-setup.service loaded active exited Create Volatile Files and Directories systemd-udev-trigger.service loaded active exited Coldplug All udev Devices systemd-udevd.service loaded active running Rule-based Manager for Device Events and Files systemd-update-utmp.service loaded active exited Update UTMP about System Boot/Shutdown systemd-user-sessions.service loaded active exited Permit User Sessions user-runtime-dir@1000.service loaded active exited User Runtime Directory /run/user/1000 user@1000.service loaded active running User Manager for UID 1000 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. 30 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'.
Executando Todos os Serviços Carregados(Loaded)
Para listar todos os serviços carregados(loaded), mas ativos, em execução e aqueles que foram encerrados, você pode adicionar a opção –state com um valor ativo, como a seguir.
systemctl --type=service --state=active
Veja exemplo,
maria@debian11VM:~$ sudo systemctl --type=service --state=active UNIT LOAD ACTIVE SUB DESCRIPTION apache2.service loaded active running The Apache HTTP Server apparmor.service loaded active exited Load AppArmor profiles console-setup.service loaded active exited Set console font and keymap cron.service loaded active running Regular background program processing > dbus.service loaded active running D-Bus System Message Bus getty@tty1.service loaded active running Getty on tty1 ifup@enp0s3.service loaded active exited ifup for enp0s3 ifupdown-pre.service loaded active exited Helper to synchronize boot up for ifup> keyboard-setup.service loaded active exited Set the console keyboard layout kmod-static-nodes.service loaded active exited Create list of static device nodes for> networking.service loaded active exited Raise network interfaces rsyslog.service loaded active running System Logging Service ssh.service loaded active running OpenBSD Secure Shell server systemd-journal-flush.service loaded active exited Flush Journal to Persistent Storage systemd-journald.service loaded active running Journal Service systemd-logind.service loaded active running User Login Management systemd-modules-load.service loaded active exited Load Kernel Modules systemd-random-seed.service loaded active exited Load/Save Random Seed systemd-remount-fs.service loaded active exited Remount Root and Kernel File Systems systemd-sysctl.service loaded active exited Apply Kernel Variables systemd-sysusers.service loaded active exited Create System Users systemd-timesyncd.service loaded active running Network Time Synchronization systemd-tmpfiles-setup-dev.service loaded active exited Create Static Device Nodes in /dev systemd-tmpfiles-setup.service loaded active exited Create Volatile Files and Directories systemd-udev-trigger.service loaded active exited Coldplug All udev Devices systemd-udevd.service loaded active running Rule-based Manager for Device Events a> systemd-update-utmp.service loaded active exited Update UTMP about System Boot/Shutdown systemd-user-sessions.service loaded active exited Permit User Sessions user-runtime-dir@1000.service loaded active exited User Runtime Directory /run/user/1000 user@1000.service loaded active running User Manager for UID 1000
O comando ainda monsta, ao final, a seguinte descrição:
- LOAD = Reflete se a definição da unidade foi carregada corretamente.
- ACTIVE = O estado de ativação da unidade de alto nível, ou seja, generalização de SUB.
- SUB = O estado de ativação da unidade de baixo nível, os valores dependem do tipo de unidade.
30 unidades carregadas listadas.
Visualizando Serviços em Execução
para obter uma visão rápida de todos os serviços em execução(ou seja, todos os serviços carregados e em execução ativamente), execute o seguinte comando.
maria@debian11VM:~$ sudo systemctl --type=service --state=running UNIT LOAD ACTIVE SUB DESCRIPTION apache2.service loaded active running The Apache HTTP Server cron.service loaded active running Regular background program processing daemon dbus.service loaded active running D-Bus System Message Bus getty@tty1.service loaded active running Getty on tty1 rsyslog.service loaded active running System Logging Service ssh.service loaded active running OpenBSD Secure Shell server systemd-journald.service loaded active running Journal Service systemd-logind.service loaded active running User Login Management systemd-timesyncd.service loaded active running Network Time Synchronization systemd-udevd.service loaded active running Rule-based Manager for Device Events and Files user@1000.service loaded active running User Manager for UID 1000
Comment on “Linux: Usando SYSTEMD para ver Lista de Programas e Seus Status”