Ceci est une ancienne révision du document !
Table des matières
Version : 2024.01
Dernière mise-à-jour : 2024/09/26 12:14
RH12412 - Contrôle des services et des démons
Contenu du Module
- RH12412 - Contrôle des services et des démons
- Contenu du Module
- Systemd
- LAB #1 - La Commande systemctl
- LAB #2 - Fichiers de Configuration
- 2.1 - Fichiers de Configuration par Défaut
- 2.2 - Surchargement des Fichiers de Configuration par Défaut
- LAB #3 - La Commande systemd-analyze
- LAB #4 - Les Cibles Systemd
- 4.1 - Contrôler les dépendances d'une Cible
- 4.2 - La Cible par Défaut
- LAB #5 - Gestion des Services
- 5.1 - Gestion des Instances Uniques
- 5.2 - Gestion d'Instances Multiples
- 5.3 - Interdire la Modification du Statut d'un Service
Systemd
Les systèmes de démarrage antérieurs à Systemd, SysVinit et Upstart, étaient des systèmes de démarrage séquentiels.
Systemd essaie, par contre, de démarrer autant de services en parallèle que possible. Ceci est rendu possible car la majorité d'architectures matérielles modernes sont multi-cœurs. Si un service dépend d'un autre qui n'est pas encore démarré ce premier est mis en attente dans une mémoire tampon. Qui plus est, les services qui ne sont pas nécessaires au démarrage de la machine, tel cups, ne sont démarrés ultérieurement que si nécessaire. Lors de démarrage, les partitions sont montées en parallèle. Dernièrement, Systemd remplace les scripts de démarrage traditionnels avec des binaires compilés, beaucoup plus rapides que leur prédécesseurs.
Au lieu de parler de scripts de démarrage et de niveaux d'exécution, Systemd utilise la terminologie Unités (Units) et Cibles (Targets). Une Unité peut être :
- .automount - active la fonctionalité d'automount.
- .device - expose une périphérique dans systemd.
- .mount - contrôle quand et comment les systèmes de fichiers sont montés.
- .path - active un service quand il y a un accès à un fichier ou répertoire sous surveillance par le système.
- .service - démarre, arrête, redémarre ou recharge un service.
- .scope - gère des services.
- .slice - regroupe des Unités dans une arborescence afin de limiter des ressources en utilisant des CGroups.
- .snapshot - un état sauvegardé du gestionnaire Systemd.
- .socket - permet aux Unités d'utiliser des sockets pour la communication inter-processus.
- .swap - encapsule une périphérique ou un fichier swap.
- .timer - déclenche l'activation d'autres Unités en utilisant des minuteurs de Systemd.
- .target - regroupe des Unités multiples afin qu'elles puissent être démarrées en même temps. Par exemple network.target regroupe toutes les Unités nécessaires pour démarrer toutes les interfaces réseaux en même temps.
Une Cible est en quelque sorte une grande étape dans le démarrage du système :
- halt.target - arrête le système.
- poweroff.target - arrête le système et coupe le courant.
- shutdown.target - arrête le système.
- rescue.target - démarre le système en mode single-user (seul root peut s'y connecter). Tous les systèmes de fichiers sont montés mais le réseau n'est pas démarré.
- emergency.target - démarre le système en mode single-user (seul root peut s'y connecter). Uniquement le système de fichiers racine est monté en mode lecture seule. Le réseau n'est pas démarré.
- multi-user.target - démarre le système en mode multi-utilisateur avec tous les systèmes de fichiers montés et le service network démarré.
- graphical.target - démarre le système en multi-user.target puis démarre l'interface graphique.
- hibernate.target - sauvegarde l'état courant sur disque et arrête le système. Quand le système est démarré, l'état est restauré.
- reboot.target - redémarre le système.
Systemd utilise des Cibles d'une manière similaire à ce que SysVinit utilise des niveaux d'exécution. Pour rendre la transition plus facile, il existe des Cibles qui “simulent” les niveaux d'exécution de SysVinit :
[root@centos8 ~]# ls -l /usr/lib/systemd/system/runlevel* lrwxrwxrwx. 1 root root 15 Apr 7 16:55 /usr/lib/systemd/system/runlevel0.target -> poweroff.target lrwxrwxrwx. 1 root root 13 Apr 7 16:55 /usr/lib/systemd/system/runlevel1.target -> rescue.target lrwxrwxrwx. 1 root root 17 Apr 7 16:55 /usr/lib/systemd/system/runlevel2.target -> multi-user.target lrwxrwxrwx. 1 root root 17 Apr 7 16:55 /usr/lib/systemd/system/runlevel3.target -> multi-user.target lrwxrwxrwx. 1 root root 17 Apr 7 16:55 /usr/lib/systemd/system/runlevel4.target -> multi-user.target lrwxrwxrwx. 1 root root 16 Apr 7 16:55 /usr/lib/systemd/system/runlevel5.target -> graphical.target lrwxrwxrwx. 1 root root 13 Apr 7 16:55 /usr/lib/systemd/system/runlevel6.target -> reboot.target /usr/lib/systemd/system/runlevel1.target.wants: total 0 /usr/lib/systemd/system/runlevel2.target.wants: total 0 /usr/lib/systemd/system/runlevel3.target.wants: total 0 /usr/lib/systemd/system/runlevel4.target.wants: total 0 /usr/lib/systemd/system/runlevel5.target.wants: total 0
LAB #1 - La Commande systemctl
Pour visualiser la liste des Unités, il convient d'utiliser la commande systemctl avec l'option list-units :
[root@centos8 ~]# systemctl list-units 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 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.device loaded active plugged 82801AA AC'97 Audio Controller 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-sda3.device loaded active plugged VBOX_HARDDISK 3 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-pci0000:00-0000:00:0d.0-ata4-host3-target3:0:0-3:0:0:0-block-sdb-sdb1.device loaded active plugged VBOX_HARDDISK 1 sys-devices-pci0000:00-0000:00:0d.0-ata4-host3-target3:0:0-3:0:0:0-block-sdb-sdb10.device loaded active plugged VBOX_HARDDISK 10 sys-devices-pci0000:00-0000:00:0d.0-ata4-host3-target3:0:0-3:0:0:0-block-sdb-sdb11.device loaded active plugged VBOX_HARDDISK my_ext4 sys-devices-pci0000:00-0000:00:0d.0-ata4-host3-target3:0:0-3:0:0:0-block-sdb-sdb12.device loaded active plugged VBOX_HARDDISK 12 sys-devices-pci0000:00-0000:00:0d.0-ata4-host3-target3:0:0-3:0:0:0-block-sdb-sdb2.device loaded active plugged VBOX_HARDDISK 2 sys-devices-pci0000:00-0000:00:0d.0-ata4-host3-target3:0:0-3:0:0:0-block-sdb-sdb3.device loaded active plugged VBOX_HARDDISK 3 sys-devices-pci0000:00-0000:00:0d.0-ata4-host3-target3:0:0-3:0:0:0-block-sdb-sdb4.device loaded active plugged VBOX_HARDDISK 4 sys-devices-pci0000:00-0000:00:0d.0-ata4-host3-target3:0:0-3:0:0:0-block-sdb-sdb5.device loaded active plugged VBOX_HARDDISK 5 sys-devices-pci0000:00-0000:00:0d.0-ata4-host3-target3:0:0-3:0:0:0-block-sdb-sdb6.device loaded active plugged VBOX_HARDDISK 6 sys-devices-pci0000:00-0000:00:0d.0-ata4-host3-target3:0:0-3:0:0:0-block-sdb-sdb7.device loaded active plugged VBOX_HARDDISK 7 sys-devices-pci0000:00-0000:00:0d.0-ata4-host3-target3:0:0-3:0:0:0-block-sdb-sdb8.device loaded active plugged VBOX_HARDDISK 8 sys-devices-pci0000:00-0000:00:0d.0-ata4-host3-target3:0:0-3:0:0:0-block-sdb-sdb9.device loaded active plugged VBOX_HARDDISK 9 sys-devices-pci0000:00-0000:00:0d.0-ata4-host3-target3:0:0-3:0:0:0-block-sdb.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-devices-virtual-block-dm\x2d0.device loaded active plugged /sys/devices/virtual/block/dm-0 sys-devices-virtual-block-dm\x2d1.device loaded active plugged /sys/devices/virtual/block/dm-1 sys-devices-virtual-net-virbr0.device loaded active plugged /sys/devices/virtual/net/virbr0 sys-devices-virtual-net-virbr0\x2dnic.device loaded active plugged /sys/devices/virtual/net/virbr0-nic sys-module-configfs.device loaded active plugged /sys/module/configfs sys-subsystem-net-devices-enp0s3.device loaded active plugged 82540EM Gigabit Ethernet Controller (PRO/1000 MT Desktop Adapter) sys-subsystem-net-devices-virbr0.device loaded active plugged /sys/subsystem/net/devices/virbr0 sys-subsystem-net-devices-virbr0\x2dnic.device loaded active plugged /sys/subsystem/net/devices/virbr0-nic -.mount loaded active mounted Root Mount boot.mount loaded active mounted /boot 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-kernel-config.mount loaded active mounted Kernel Configuration File System sys-kernel-debug.mount loaded active mounted Kernel Debug File System sys-kernel-tracing.mount loaded active mounted /sys/kernel/tracing var-lib-nfs-rpc_pipefs.mount loaded active mounted RPC Pipe File System cups.path loaded active running CUPS Scheduler systemd-ask-password-plymouth.path loaded active waiting Forward Password Requests to Plymouth Directory Watch systemd-ask-password-wall.path loaded active waiting Forward Password Requests to Wall Directory Watch init.scope loaded active running System and Service Manager session-96.scope loaded active running Session 96 of user trainee atd.service loaded active running Job spooling tools auditd.service loaded active running Security Auditing Service avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack chronyd.service loaded active running NTP client/server crond.service loaded active running Command Scheduler cups.service loaded active running CUPS Scheduler dbus.service loaded active running D-Bus System Message Bus dracut-shutdown.service loaded active exited Restore /run/initramfs on shutdown firewalld.service loaded active running firewalld - dynamic firewall daemon lines 1-57
Pour consulter la liste des Unités inactifs, utilisez la commande suivante :
[root@centos8 ~]# systemctl list-units --all | grep inactive | more ● boot.automount not-found inactive dead boot.automount proc-fs-nfsd.mount loaded inactive dead NFSD configuration filesystem proc-sys-fs-binfmt_misc.mount loaded inactive dead Arbitrary Executable File Formats File System sys-fs-fuse-connections.mount loaded inactive dead FUSE Control File System ● sysroot.mount not-found inactive dead sysroot.mount tmp.mount loaded inactive dead Temporary Directory (/tmp) var-lib-machines.mount loaded inactive dead Virtual Machine and Container Storage systemd-ask-password-console.path loaded inactive dead Dispatch Password Requests to Console Directory Watch ● apparmor.service not-found inactive dead apparmor.service auth-rpcgss-module.service loaded inactive dead Kernel Module supporting RPCSEC_GSS cpupower.service loaded inactive dead Configure CPU power related settings ● display-manager.service not-found inactive dead display-manager.service dm-event.service loaded inactive dead Device-mapper event daemon dnf-makecache.service loaded inactive dead dnf makecache dracut-cmdline.service loaded inactive dead dracut cmdline hook dracut-initqueue.service loaded inactive dead dracut initqueue hook dracut-mount.service loaded inactive dead dracut mount hook dracut-pre-mount.service loaded inactive dead dracut pre-mount hook dracut-pre-pivot.service loaded inactive dead dracut pre-pivot and cleanup hook dracut-pre-trigger.service loaded inactive dead dracut pre-trigger hook dracut-pre-udev.service loaded inactive dead dracut pre-udev hook ebtables.service loaded inactive dead Ethernet Bridge Filtering tables emergency.service loaded inactive dead Emergency Shell initrd-cleanup.service loaded inactive dead Cleaning Up and Shutting Down Daemons initrd-parse-etc.service loaded inactive dead Reload Configuration from the Real Root initrd-switch-root.service loaded inactive dead Switch Root initrd-udevadm-cleanup-db.service loaded inactive dead Cleanup udevd DB ● ip6tables.service not-found inactive dead ip6tables.service ● ipset.service not-found inactive dead ipset.service ● iptables.service not-found inactive dead iptables.service iscsi-onboot.service loaded inactive dead Special handling of early boot iSCSI sessions iscsi.service loaded inactive dead Login and scanning of iSCSI devices iscsid.service loaded inactive dead Open-iSCSI iscsiuio.service loaded inactive dead iSCSI UserSpace I/O driver ldconfig.service loaded inactive dead Rebuild Dynamic Linker Cache libvirt-guests.service loaded inactive dead Suspend/Resume Running libvirt Guests libvirtd.service loaded inactive dead Virtualization daemon loadmodules.service loaded inactive dead Load legacy module configuration ● lvm2-activation.service not-found inactive dead lvm2-activation.service lvm2-lvmpolld.service loaded inactive dead LVM2 poll daemon mdmonitor.service loaded inactive dead Software RAID monitoring and management microcode.service loaded inactive dead Load CPU microcode update ● network.service not-found inactive dead network.service nfs-blkmap.service loaded inactive dead pNFS block layout mapping daemon nfs-convert.service loaded inactive dead Preprocess NFS configuration convertion nfs-idmapd.service loaded inactive dead NFSv4 ID-name mapping service nfs-mountd.service loaded inactive dead NFS Mount Daemon nfs-server.service loaded inactive dead NFS server and services nfs-utils.service loaded inactive dead NFS server and client services nfsdcld.service loaded inactive dead NFSv4 Client Tracking Daemon nftables.service loaded inactive dead Netfilter Tables ● ntpd.service not-found inactive dead ntpd.service ● ntpdate.service not-found inactive dead ntpdate.service plymouth-switch-root.service loaded inactive dead Plymouth switch root service rc-local.service loaded inactive dead /etc/rc.d/rc.local Compatibility rescue.service loaded inactive dead Rescue Shell rpc-gssd.service loaded inactive dead RPC security service for NFS client and server --More--
Les points noirs au début de certaines lignes dans la sortie ci-dessus sont en réalité des points blancs à l'écran. Ces points impliquent que le service, la cible ou l'unité spécifié n'a pas été trouvé sur le système. Par exemple :
[root@centos8 ~]# systemctl status ntpd Unit ntpd.service could not be found.
Pour consulter la liste des Unités ainsi que leurs statuts, utilisez la commande suivante :
[root@centos8 ~]# systemctl list-unit-files | more UNIT FILE STATE proc-sys-fs-binfmt_misc.automount static -.mount generated boot.mount generated dev-hugepages.mount static dev-mqueue.mount static proc-fs-nfsd.mount static proc-sys-fs-binfmt_misc.mount static sys-fs-fuse-connections.mount static sys-kernel-config.mount static sys-kernel-debug.mount static tmp.mount disabled var-lib-machines.mount static var-lib-nfs-rpc_pipefs.mount static cups.path enabled systemd-ask-password-console.path static systemd-ask-password-plymouth.path static systemd-ask-password-wall.path static session-96.scope transient arp-ethers.service disabled atd.service enabled auditd.service enabled auth-rpcgss-module.service static autovt@.service enabled avahi-daemon.service enabled blk-availability.service disabled chrony-dnssrv@.service static chrony-wait.service disabled chronyd.service enabled cockpit-motd.service static cockpit-wsinstance-http-redirect.service static cockpit-wsinstance-http.service static cockpit-wsinstance-https-factory@.service static cockpit-wsinstance-https@.service static cockpit.service static console-getty.service disabled container-getty@.service static cpupower.service disabled crond.service enabled cups-browsed.service disabled cups.service enabled dbus-org.fedoraproject.FirewallD1.service enabled dbus-org.freedesktop.Avahi.service enabled dbus-org.freedesktop.hostname1.service static dbus-org.freedesktop.import1.service static dbus-org.freedesktop.locale1.service static dbus-org.freedesktop.login1.service static dbus-org.freedesktop.machine1.service static dbus-org.freedesktop.nm-dispatcher.service enabled dbus-org.freedesktop.portable1.service static dbus-org.freedesktop.timedate1.service enabled dbus.service static debug-shell.service disabled dm-event.service static dnf-makecache.service static dnsmasq.service disabled dracut-cmdline.service static --More--
Pour visualiser les Unités d'un type spécifique, il convient d'utiliser l'option -t :
[root@centos8 ~]# systemctl list-unit-files -t mount UNIT FILE STATE -.mount generated boot.mount generated dev-hugepages.mount static dev-mqueue.mount static proc-fs-nfsd.mount static proc-sys-fs-binfmt_misc.mount static sys-fs-fuse-connections.mount static sys-kernel-config.mount static sys-kernel-debug.mount static tmp.mount disabled var-lib-machines.mount static var-lib-nfs-rpc_pipefs.mount static 12 unit files listed.
Dans la colonne STATE on voit les mots static et generated.
- STATE = static
- Ceci implique que l'Unité ne peut ni être démarrée, ni être arrêtée par l'administrateur. Le démarrage et l'arrêt d'une telle Unité est effectué par le système. En règle générale, les Unités dont le STATE est static sont des dépendances d'autres Unité
- STATE = generated
- Ceci implique que le fichier a été généré automatiquement en utilisant les informations dans le fichier /etc/fstab lors du démarrage du système. Dans le cas d'un point de montage, l'exécutable respopnsable de la génération du fichier est /lib/systemd/system-generators/systemd-fstab-generator :
[root@centos8 ~]# ls -l /lib/systemd/system-generators/systemd-fstab-generator -rwxr-xr-x. 1 root root 46096 Apr 7 16:56 /lib/systemd/system-generators/systemd-fstab-generator
Il existe aussi d'autres exécutables responsables de la génération d'autres fichiers :
[root@centos8 ~]# ls -l /lib/systemd/system-generators total 508 -rwxr-xr-x. 1 root root 504 Jan 4 11:25 kdump-dep-generator.sh -r-xr-xr-x. 1 root root 134976 Aug 17 2020 lvm2-activation-generator -rwxr-xr-x. 1 root root 67792 Jul 20 2020 nfs-server-generator -rwxr-xr-x. 1 root root 38216 Jul 20 2020 rpc-pipefs-generator -rwxr-xr-x. 1 root root 743 Apr 23 2020 selinux-autorelabel-generator.sh -rwxr-xr-x. 1 root root 33504 Apr 7 16:56 systemd-cryptsetup-generator -rwxr-xr-x. 1 root root 16648 Apr 7 16:56 systemd-debug-generator -rwxr-xr-x. 1 root root 46096 Apr 7 16:56 systemd-fstab-generator -rwxr-xr-x. 1 root root 17064 Apr 7 16:56 systemd-getty-generator -rwxr-xr-x. 1 root root 29432 Apr 7 16:56 systemd-gpt-auto-generator -rwxr-xr-x. 1 root root 12568 Apr 7 16:56 systemd-hibernate-resume-generator -rwxr-xr-x. 1 root root 12368 Apr 7 16:56 systemd-rc-local-generator -rwxr-xr-x. 1 root root 12408 Apr 7 16:56 systemd-system-update-generator -rwxr-xr-x. 1 root root 33544 Apr 7 16:56 systemd-sysv-generator -rwxr-xr-x. 1 root root 17024 Apr 7 16:56 systemd-veritysetup-generator
Les options de la commande systemctl sont :
[root@centos8 ~]# systemctl --help systemctl [OPTIONS...] {COMMAND} ... Query or send control commands to the systemd manager. -h --help Show this help --version Show package version --system Connect to system manager --user Connect to user service manager -H --host=[USER@]HOST Operate on remote host -M --machine=CONTAINER Operate on local container -t --type=TYPE List units of a particular type --state=STATE List units with particular LOAD or SUB or ACTIVE state -p --property=NAME Show only properties by this name -a --all Show all properties/all units currently in memory, including dead/empty ones. To list all units installed on the system, use the 'list-unit-files' command instead. --failed Same as --state=failed -l --full Don't ellipsize unit names on output -r --recursive Show unit list of host and local containers --reverse Show reverse dependencies with 'list-dependencies' --job-mode=MODE Specify how to deal with already queued jobs, when queueing a new job --show-types When showing sockets, explicitly show their type --value When showing properties, only print the value -i --ignore-inhibitors When shutting down or sleeping, ignore inhibitors --kill-who=WHO Who to send signal to -s --signal=SIGNAL Which signal to send --now Start or stop unit in addition to enabling or disabling it --dry-run Only print what would be done -q --quiet Suppress output --wait For (re)start, wait until service stopped again --no-block Do not wait until operation finished --no-wall Don't send wall message before halt/power-off/reboot --no-reload Don't reload daemon after en-/dis-abling unit files --no-legend Do not print a legend (column headers and hints) --no-pager Do not pipe output into a pager --no-ask-password Do not ask for system passwords --global Enable/disable/mask unit files globally --runtime Enable/disable/mask unit files temporarily until next reboot -f --force When enabling unit files, override existing symlinks When shutting down, execute action immediately --preset-mode= Apply only enable, only disable, or all presets --root=PATH Enable/disable/mask unit files in the specified root directory -n --lines=INTEGER Number of journal entries to show -o --output=STRING Change journal output mode (short, short-precise, short-iso, short-iso-precise, short-full, short-monotonic, short-unix, verbose, export, json, json-pretty, json-sse, cat) --firmware-setup Tell the firmware to show the setup menu on next boot --plain Print unit dependencies as a list instead of a tree lines 1-57
LAB #2 - Fichiers de Configuration
2.1 - Fichiers de Configuration par Défaut
Les fichiers de configuration des Cibles et fichiers de configuration des Unités installés par des paquets se trouvent dans le répertoire /usr/lib/systemd/system :
[root@centos8 ~]# pkg-config systemd --variable=systemdsystemunitdir /usr/lib/systemd/system
[root@centos8 ~]# ls -l /usr/lib/systemd/system | more total 1464 -rw-r--r--. 1 root root 275 Apr 26 2020 arp-ethers.service -rw-r--r--. 1 root root 222 May 11 2019 atd.service -rw-r--r--. 1 root root 1512 Apr 23 2020 auditd.service -rw-r--r--. 1 root root 628 Jul 20 2020 auth-rpcgss-module.service lrwxrwxrwx. 1 root root 14 Apr 7 16:55 autovt@.service -> getty@.service -rw-r--r--. 1 root root 1044 Nov 16 2020 avahi-daemon.service -rw-r--r--. 1 root root 870 Nov 16 2020 avahi-daemon.socket -rw-r--r--. 1 root root 956 Apr 7 16:54 basic.target drwxr-xr-x. 2 root root 6 Apr 7 16:55 basic.target.wants -r--r--r--. 1 root root 408 Aug 17 2020 blk-availability.service -rw-r--r--. 1 root root 419 Jun 22 2018 bluetooth.target -rw-r--r--. 1 root root 455 Apr 7 16:54 boot-complete.target -rw-r--r--. 1 root root 209 Nov 19 2019 chrony-dnssrv@.service -rw-r--r--. 1 root root 138 Nov 19 2019 chrony-dnssrv@.timer -rw-r--r--. 1 root root 491 Nov 19 2019 chronyd.service -rw-r--r--. 1 root root 472 May 10 2019 chrony-wait.service -rw-r--r--. 1 root root 222 Aug 24 2020 cockpit-motd.service -rw-r--r--. 1 root root 835 Aug 24 2020 cockpit.service -rw-r--r--. 1 root root 373 Aug 24 2020 cockpit.socket -rw-r--r--. 1 root root 251 Aug 24 2020 cockpit-wsinstance-http-redirect.service -rw-r--r--. 1 root root 233 Aug 24 2020 cockpit-wsinstance-http-redirect.socket -rw-r--r--. 1 root root 221 Aug 24 2020 cockpit-wsinstance-http.service -rw-r--r--. 1 root root 165 Aug 24 2020 cockpit-wsinstance-https-factory@.service -rw-r--r--. 1 root root 244 Aug 24 2020 cockpit-wsinstance-https-factory.socket -rw-r--r--. 1 root root 215 Aug 24 2020 cockpit-wsinstance-http.socket -rw-r--r--. 1 root root 264 Aug 24 2020 cockpit-wsinstance-https@.service -rw-r--r--. 1 root root 478 Aug 24 2020 cockpit-wsinstance-https@.socket -rw-r--r--. 1 root root 1082 Apr 7 16:55 console-getty.service -rw-r--r--. 1 root root 1263 Apr 7 16:55 container-getty@.service -rw-r--r--. 1 root root 294 Apr 8 15:21 cpupower.service -rw-r--r--. 1 root root 356 Nov 8 2019 crond.service -rw-r--r--. 1 root root 465 Jun 22 2018 cryptsetup-pre.target -rw-r--r--. 1 root root 412 Jun 22 2018 cryptsetup.target lrwxrwxrwx. 1 root root 13 Apr 7 16:55 ctrl-alt-del.target -> reboot.target -rw-r--r--. 1 root root 234 Oct 4 2017 cups-browsed.service -r--r--r--. 1 root root 142 Jun 15 2020 cups.path -r--r--r--. 1 root root 248 Jun 15 2020 cups.service -r--r--r--. 1 root root 136 Jun 15 2020 cups.socket lrwxrwxrwx. 1 root root 25 Apr 7 16:55 dbus-org.freedesktop.hostname1.service -> systemd-hostnamed.service lrwxrwxrwx. 1 root root 23 Apr 7 16:55 dbus-org.freedesktop.import1.service -> systemd-importd.service lrwxrwxrwx. 1 root root 23 Apr 7 16:55 dbus-org.freedesktop.locale1.service -> systemd-localed.service lrwxrwxrwx. 1 root root 22 Apr 7 16:55 dbus-org.freedesktop.login1.service -> systemd-logind.service lrwxrwxrwx. 1 root root 24 Apr 7 16:55 dbus-org.freedesktop.machine1.service -> systemd-machined.service lrwxrwxrwx. 1 root root 25 Apr 7 16:55 dbus-org.freedesktop.portable1.service -> systemd-portabled.service lrwxrwxrwx. 1 root root 25 Apr 7 16:55 dbus-org.freedesktop.timedate1.service -> systemd-timedated.service -rw-r--r--. 1 root root 380 Apr 7 12:08 dbus.service -rw-r--r--. 1 root root 102 Apr 7 12:08 dbus.socket drwxr-xr-x. 2 root root 6 Apr 7 16:55 dbus.target.wants -rw-r--r--. 1 root root 1084 Apr 7 16:55 debug-shell.service lrwxrwxrwx. 1 root root 16 Apr 7 16:55 default.target -> graphical.target drwxr-xr-x. 2 root root 6 Apr 7 16:55 default.target.wants -rw-r--r--. 1 root root 750 Jun 22 2018 dev-hugepages.mount -rw-r--r--. 1 root root 665 Jun 22 2018 dev-mqueue.mount -r--r--r--. 1 root root 345 Aug 17 2020 dm-event.service -r--r--r--. 1 root root 248 Aug 17 2020 dm-event.socket -rw-r--r--. 1 root root 457 Jun 2 2020 dnf-makecache.service --More--
Certains fichiers de configuration sont créés à la volée dans le répertoire /run/systemd/system lors du runtime puis ils sont détruits quand le système n'en a plus besoin :
[root@centos8 ~]# ls -l /run/systemd/system/ total 0
Les fichiers de configuration des Unités crées par les utilisateurs doivent être mis dans le répertoire /usr/lib/systemd/user :
[root@centos8 ~]# pkg-config systemd --variable=systemduserunitdir /usr/lib/systemd/user
Important : De cette façon les fichiers dans /usr/lib/systemd/user surchargent les fichiers dans le répertoire /run/systemd/system qui surchargent les fichiers dans le répertoire /usr/lib/systemd/system.
Prenons le cas du service sshd qui est configuré par le fichier /usr/lib/systemd/system/sshd.service :
[root@centos8 ~]# cat /usr/lib/systemd/system/sshd.service [Unit] Description=OpenSSH server daemon Documentation=man:sshd(8) man:sshd_config(5) After=network.target sshd-keygen.target Wants=sshd-keygen.target [Service] Type=notify EnvironmentFile=-/etc/crypto-policies/back-ends/opensshserver.config EnvironmentFile=-/etc/sysconfig/sshd ExecStart=/usr/sbin/sshd -D $OPTIONS $CRYPTO_POLICY ExecReload=/bin/kill -HUP $MAINPID KillMode=process Restart=on-failure RestartSec=42s [Install] WantedBy=multi-user.target
Dans le fichier on peut noter la présence des lignes suivantes dans la section [Unit] :
- Description=OpenSSH server daemon,
- Cette directive est utilisée pour donner une courte description des fonctionnalités de l'Unité,
- Documentation=man:sshd(8) man:sshd_config(5),
- Cette directive stipule les chapitres des manuels et les URLs contenant de l'information en relation avec l'Unité,
- After=network.target sshd-keygen.target,
- Cette directive indique les cibles qui devraient être atteintes et les Unités qui devraient être démarrées avant l'Unité sshd. Par contre, cette directive ne spécifie pas une dépendance,
- Wants=sshd-keygen.target,
- Cette directive stipule une dépendance douce. Autrement dit, Systemd essayera de démarrer l'Unité sshd-keygen.target mais si ce démarrage est en échec, l'Unité sshd sera démarré.
Dans le fichier on peut aussi noter la présence des lignes suivantes dans la section [Service] :
- Type=notify,
- Cette directive indique que le service informera Systemd quand son démarrage a terminé,
- ExecStart=/usr/sbin/sshd -D $OPTIONS $CRYPTO_POLICY,
- Cette directive définit l'exécutable à lancer,
- ExecReload=/bin/kill -HUP $MAINPID,
- Cette directive indique la commande necéssaire pour redémarrer le service,
- KillMode=process,
- Cette directive indique comment les processus du service doivent être arrêtés. La valeur de process implique l'utilisation de SIGTERM suivi par SIGHUP,
- Restart=on-failure,
- Cette ligne indique que le service doit être re-démarré en cas d'arrêt de celui-ci.
- RestartSec=42s,
- Cette directive stipule le temps d'attente entre l'arrêt du service et le redémarrage par Systemd,
Dernièrement on note la présence de la ligne suivante dans la section [Install] :
- WantedBy=multi-user.target,
- Cette directive indique la Cible dans laquelle le service doit être démarré. La présence de cette directive crée un lien symbolique dans le répertoire /etc/systemd/system/multi-user.target.wants qui pointe vers ce fichier.
Pour consulter l'ensemble des directives de configuration ainsi que leurs valeurs d'une Unité, il convient d'utiliser la commande systemctl show en spécifiant l'Unité concernée :
[root@centos8 ~]# systemctl show sshd Type=notify Restart=on-failure NotifyAccess=main RestartUSec=42s TimeoutStartUSec=1min 30s TimeoutStopUSec=1min 30s RuntimeMaxUSec=infinity WatchdogUSec=0 WatchdogTimestamp=Thu 2021-06-03 15:09:54 EDT WatchdogTimestampMonotonic=12502561 PermissionsStartOnly=no RootDirectoryStartOnly=no RemainAfterExit=no GuessMainPID=yes MainPID=902 ControlPID=0 FileDescriptorStoreMax=0 NFileDescriptorStore=0 StatusErrno=0 Result=success UID=[not set] GID=[not set] NRestarts=0 ExecMainStartTimestamp=Thu 2021-06-03 15:09:54 EDT ExecMainStartTimestampMonotonic=12446178 ExecMainExitTimestampMonotonic=0 ExecMainPID=902 ExecMainCode=0 ExecMainStatus=0 ExecStart={ path=/usr/sbin/sshd ; argv[]=/usr/sbin/sshd -D $OPTIONS $CRYPTO_POLICY ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 } ExecReload={ path=/bin/kill ; argv[]=/bin/kill -HUP $MAINPID ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 } Slice=system.slice ControlGroup=/system.slice/sshd.service MemoryCurrent=6270976 CPUUsageNSec=[not set] EffectiveCPUs= EffectiveMemoryNodes= TasksCurrent=1 IPIngressBytes=18446744073709551615 IPIngressPackets=18446744073709551615 IPEgressBytes=18446744073709551615 IPEgressPackets=18446744073709551615 Delegate=no CPUAccounting=no CPUWeight=[not set] StartupCPUWeight=[not set] CPUShares=[not set] StartupCPUShares=[not set] CPUQuotaPerSecUSec=infinity CPUQuotaPeriodUSec=infinity AllowedCPUs= AllowedMemoryNodes= IOAccounting=no IOWeight=[not set] StartupIOWeight=[not set] BlockIOAccounting=no BlockIOWeight=[not set] lines 1-57
Pour consulter la liste des dépendances d'une Unité, il convient d'utiliser systemctl list-dependancies en spécifiant l'Unité concernée :
[root@centos8 ~]# systemctl list-dependencies sshd.service sshd.service ● ├─system.slice ● ├─sshd-keygen.target ● │ ├─sshd-keygen@ecdsa.service ● │ ├─sshd-keygen@ed25519.service ● │ └─sshd-keygen@rsa.service ● └─sysinit.target ● ├─dev-hugepages.mount ● ├─dev-mqueue.mount ● ├─dracut-shutdown.service ● ├─import-state.service ● ├─iscsi-onboot.service ● ├─kmod-static-nodes.service ● ├─ldconfig.service ● ├─loadmodules.service ● ├─lvm2-lvmpolld.socket ● ├─lvm2-monitor.service ● ├─nis-domainname.service ● ├─plymouth-read-write.service ● ├─plymouth-start.service ● ├─proc-sys-fs-binfmt_misc.automount ● ├─rngd.service ● ├─selinux-autorelabel-mark.service ● ├─sys-fs-fuse-connections.mount ● ├─sys-kernel-config.mount ● ├─sys-kernel-debug.mount ● ├─systemd-ask-password-console.path ● ├─systemd-binfmt.service ● ├─systemd-firstboot.service ● ├─systemd-hwdb-update.service ● ├─systemd-journal-catalog-update.service ● ├─systemd-journal-flush.service ● ├─systemd-journald.service ● ├─systemd-machine-id-commit.service ● ├─systemd-modules-load.service ● ├─systemd-random-seed.service ● ├─systemd-sysctl.service ● ├─systemd-sysusers.service ● ├─systemd-tmpfiles-setup-dev.service ● ├─systemd-tmpfiles-setup.service ● ├─systemd-udev-trigger.service ● ├─systemd-udevd.service ● ├─systemd-update-done.service ● ├─systemd-update-utmp.service ● ├─cryptsetup.target ● ├─local-fs.target ● │ ├─-.mount ● │ ├─boot.mount ● │ └─systemd-remount-fs.service ● └─swap.target ● └─dev-disk-by\x2duuid-c8bb3f47\x2dd67f\x2d4b21\x2db781\x2d766899dc83d4.swap
2.2 - Surchargement des Fichiers de Configuration par Défaut
Les fichiers de configuration par défaut peuvent aussi être surchargés par des fichiers dans d'autres répertoires :
[root@centos8 ~]# pkg-config systemd --variable=systemdsystemunitpath /etc/systemd/system:/etc/systemd/system:/run/systemd/system:/usr/local/lib/systemd/system:/usr/lib/systemd/system:/usr/lib/systemd/system:/lib/systemd/system
[root@centos8 ~]# ls -l /etc/systemd/system total 4 drwxr-xr-x. 2 root root 31 May 8 2020 basic.target.wants lrwxrwxrwx. 1 root root 41 May 8 2020 dbus-org.fedoraproject.FirewallD1.service -> /usr/lib/systemd/system/firewalld.service lrwxrwxrwx. 1 root root 44 Jun 3 14:02 dbus-org.freedesktop.Avahi.service -> /usr/lib/systemd/system/avahi-daemon.service lrwxrwxrwx. 1 root root 57 May 8 2020 dbus-org.freedesktop.nm-dispatcher.service -> /usr/lib/systemd/system/NetworkManager-dispatcher.service lrwxrwxrwx. 1 root root 41 May 8 2020 dbus-org.freedesktop.timedate1.service -> /usr/lib/systemd/system/timedatex.service lrwxrwxrwx. 1 root root 37 May 8 2020 default.target -> /lib/systemd/system/multi-user.target drwxr-xr-x. 2 root root 32 May 8 2020 getty.target.wants drwxr-xr-x. 2 root root 4096 Jun 3 14:02 multi-user.target.wants drwxr-xr-x. 2 root root 48 May 8 2020 network-online.target.wants drwxr-xr-x. 2 root root 33 Apr 19 12:07 nfs-blkmap.service.requires drwxr-xr-x. 2 root root 33 Apr 19 12:07 nfs-idmapd.service.requires drwxr-xr-x. 2 root root 33 Apr 19 12:07 nfs-mountd.service.requires drwxr-xr-x. 2 root root 33 Apr 19 12:07 nfs-server.service.requires drwxr-xr-x. 2 root root 26 Jun 3 14:02 printer.target.wants drwxr-xr-x. 2 root root 52 Apr 19 12:07 remote-fs.target.wants drwxr-xr-x. 2 root root 33 Apr 19 12:07 rpc-gssd.service.requires drwxr-xr-x. 2 root root 33 Apr 19 12:07 rpc-statd-notify.service.requires drwxr-xr-x. 2 root root 33 Apr 19 12:07 rpc-statd.service.requires drwxr-xr-x. 2 root root 260 Jun 3 14:02 sockets.target.wants drwxr-xr-x. 2 root root 235 Apr 19 12:07 sysinit.target.wants lrwxrwxrwx. 1 root root 39 May 8 2020 syslog.service -> /usr/lib/systemd/system/rsyslog.service lrwxrwxrwx. 1 root root 9 May 11 2019 systemd-timedated.service -> /dev/null drwxr-xr-x. 2 root root 34 May 8 2020 timers.target.wants
LAB #3 - La Commande systemd-analyze
Pour avoir une évaluation du temps de démarrage, il convient d'utiliser la commande suivante :
[root@centos8 ~]# systemd-analyze Startup finished in 1.665s (kernel) + 6.977s (initrd) + 8.458s (userspace) = 17.101s multi-user.target reached after 5.528s in userspace
L'option blame de la commande systemd-analyze permet de voir le temps de démarrage de chaque Unité afin de pourvoir se concentrer sur les plus lentes :
[root@centos8 ~]# systemd-analyze blame 4.080s dracut-initqueue.service 3.257s kdump.service 1.727s tuned.service 1.415s initrd-switch-root.service 1.393s NetworkManager-wait-online.service 1.116s systemd-machined.service 1.111s dracut-cmdline.service 850ms sssd.service 791ms vdo.service 713ms firewalld.service 622ms lvm2-monitor.service 605ms polkit.service 508ms chronyd.service 434ms avahi-daemon.service 426ms systemd-logind.service 417ms netcf-transaction.service 410ms dracut-pre-udev.service 295ms libvirtd.service 275ms dnf-makecache.service 243ms systemd-udevd.service 221ms systemd-journald.service 196ms systemd-tmpfiles-setup.service 151ms dracut-pre-pivot.service 139ms sysroot.mount 139ms systemd-update-utmp-runlevel.service 122ms systemd-vconsole-setup.service 110ms lvm2-pvscan@8:25.service 98ms systemd-udev-trigger.service 82ms gssproxy.service 81ms cups.service 79ms initrd-parse-etc.service 77ms NetworkManager.service 72ms lvm2-pvscan@8:23.service 69ms systemd-user-sessions.service 68ms lvm2-pvscan@8:22.service 67ms unbound-anchor.service 66ms rsyslog.service 62ms boot.mount 56ms sshd.service 54ms smartd.service 54ms systemd-fsck@dev-disk-by\x2duuid-2ae4c035\x2d9244\x2d458c\x2d82c5\x2da49ae169cdb6.service 53ms user@1000.service 52ms auditd.service 51ms plymouth-quit.service 49ms rngd-wake-threshold.service 46ms import-state.service 46ms systemd-tmpfiles-setup-dev.service 43ms ksmtuned.service 42ms plymouth-quit-wait.service 42ms var-lib-nfs-rpc_pipefs.mount 42ms rpc-statd-notify.service 38ms plymouth-switch-root.service 37ms systemd-remount-fs.service 37ms plymouth-start.service 33ms dev-disk-by\x2duuid-c8bb3f47\x2dd67f\x2d4b21\x2db781\x2d766899dc83d4.swap 33ms systemd-tmpfiles-clean.service 31ms dev-hugepages.mount lines 1-57
L'option critical-chain de la commande systemd-analyze permet de voir l'enchaînement des événements qui amènent au chargement de l'Unité qui est passée en argument :
[root@centos8 ~]# systemd-analyze critical-chain sshd.service The time after the unit is active or started is printed after the "@" character. The time the unit takes to start is printed after the "+" character. sshd.service +56ms └─network.target @3.799s └─NetworkManager.service @3.719s +77ms └─network-pre.target @3.718s └─firewalld.service @3.004s +713ms └─polkit.service @2.397s +605ms └─basic.target @2.392s └─sockets.target @2.392s └─sssd-kcm.socket @2.391s └─sysinit.target @2.379s └─systemd-update-utmp.service @2.370s +8ms └─auditd.service @2.317s +52ms └─systemd-tmpfiles-setup.service @2.118s +196ms └─import-state.service @2.070s +46ms └─local-fs.target @2.069s └─boot.mount @2.006s +62ms └─systemd-fsck@dev-disk-by\x2duuid-2ae4c035\x2d9244\x2d458c\x2d82c5\x2da49ae169cdb6.service @1.943s +54ms └─local-fs-pre.target @1.942s └─lvm2-monitor.service @1.319s +622ms └─dm-event.socket @1.317s └─-.mount └─system.slice └─-.slice
Les options de la commande systemd-analyze sont :
[root@centos7 ~]# systemd-analyze --help systemd-analyze [OPTIONS...] {COMMAND} ... Process systemd profiling information -h --help Show this help --version Show package version --system Connect to system manager --user Connect to user service manager --order When generating a dependency graph, show only order --require When generating a dependency graph, show only requirement --from-pattern=GLOB, --to-pattern=GLOB When generating a dependency graph, filter only origins or destinations, respectively --fuzz=TIMESPAN When printing the tree of the critical chain, print also services, which finished TIMESPAN earlier, than the latest in the branch. The unit of TIMESPAN is seconds unless specified with a different unit, i.e. 50ms --no-pager Do not pipe output into a pager Commands: time Print time spent in the kernel before reaching userspace blame Print list of running units ordered by time to init critical-chain Print a tree of the time critical chain of units plot Output SVG graphic showing service initialization dot Output dependency graph in dot(1) format set-log-level LEVEL Set logging threshold for systemd dump Output state serialization of service manager
LAB #4 - Les Cibles Systemd
Chaque Cible est décrite par un fichier de configuration :
[root@centos8 ~]# cat /usr/lib/systemd/system/graphical.target # SPDX-License-Identifier: LGPL-2.1+ # # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. [Unit] Description=Graphical Interface Documentation=man:systemd.special(7) Requires=multi-user.target Wants=display-manager.service Conflicts=rescue.service rescue.target After=multi-user.target rescue.service rescue.target display-manager.service AllowIsolate=yes
Dans ce fichier on peut noter la présence des lignes suivantes :
- Requires=multi-user.target,
- Cette ligne indique que le graphical.target ne peut pas être atteint si le multi-user.target n'a pas été atteint au préalable,
- After=multi-user.target rescue.service rescue.target display-manager.service,
- Cette ligne indique le multi-user.target et rescue.target doivent d'abord être atteints et que les services rescue.service et display-manager.service doivent d'abord être démarrés,
- Conflicts=rescue.service rescue.target,
- Cette ligne indique la Cible et le service en conflits avec le graphical.target,
- Wants=display-manager.service,
- Cette ligne indique quel service doit être démarré.
4.1 - Contrôler les dépendances d'une Cible
Les dépendances d'une Cible peuvent être consultées en utilisant la commande systemctl list-dependencies :
[root@centos8 ~]# systemctl list-dependencies multi-user.target multi-user.target ● ├─atd.service ● ├─auditd.service ● ├─avahi-daemon.service ● ├─chronyd.service ● ├─crond.service ● ├─cups.path ● ├─cups.service ● ├─dbus.service ● ├─dnf-makecache.timer ● ├─firewalld.service ● ├─irqbalance.service ● ├─kdump.service ● ├─ksm.service ● ├─ksmtuned.service ● ├─libstoragemgmt.service ● ├─libvirtd.service ● ├─mcelog.service ● ├─mdmonitor.service ● ├─netcf-transaction.service ● ├─NetworkManager.service ● ├─plymouth-quit-wait.service ● ├─plymouth-quit.service ● ├─rpcbind.service ● ├─rsyslog.service ● ├─smartd.service ● ├─sshd.service ● ├─sssd.service ● ├─systemd-ask-password-wall.path ● ├─systemd-logind.service ● ├─systemd-update-utmp-runlevel.service ● ├─systemd-user-sessions.service ● ├─tuned.service ● ├─vdo.service ● ├─basic.target ● │ ├─-.mount ● │ ├─microcode.service ● │ ├─paths.target ● │ ├─slices.target ● │ │ ├─-.slice ● │ │ └─system.slice ● │ ├─sockets.target ● │ │ ├─avahi-daemon.socket ● │ │ ├─cups.socket ● │ │ ├─dbus.socket ● │ │ ├─dm-event.socket ● │ │ ├─iscsid.socket ● │ │ ├─iscsiuio.socket ● │ │ ├─libvirtd-ro.socket ● │ │ ├─libvirtd.socket ● │ │ ├─rpcbind.socket ● │ │ ├─sssd-kcm.socket ● │ │ ├─systemd-coredump.socket ● │ │ ├─systemd-initctl.socket ● │ │ ├─systemd-journald-dev-log.socket ● │ │ ├─systemd-journald.socket ● │ │ ├─systemd-udevd-control.socket lines 1-57
Les points noirs au début de chaque ligne dans la sortie ci-dessus peuvent être de trois couleurs différentes :
- Vert implique que le service, la cible ou l'unité est activé et démarré.
- Blanc implique le service, la cible ou l'unité est inactif.
- Rouge implique que le service, la cible ou l'unité n'a pas démarré à cause d'une erreur fatale.
Pour visualiser les Unités en état d'erreur fatale, utilisez la commande systemctl –failed :
[root@centos8 ~]# systemctl --failed 0 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'.
Les dépendances sont créés sous la forme de liens symboliques dans les répertoires /etc/systemd/system/multi-user.target.wants et /usr/lib/systemd/system/multi-user.target.wants :
[root@centos8 ~]# ls -l /etc/systemd/system/multi-user.target.wants total 0 lrwxrwxrwx. 1 root root 35 May 8 2020 atd.service -> /usr/lib/systemd/system/atd.service lrwxrwxrwx. 1 root root 38 May 8 2020 auditd.service -> /usr/lib/systemd/system/auditd.service lrwxrwxrwx. 1 root root 44 Jun 3 14:02 avahi-daemon.service -> /usr/lib/systemd/system/avahi-daemon.service lrwxrwxrwx. 1 root root 39 May 8 2020 chronyd.service -> /usr/lib/systemd/system/chronyd.service lrwxrwxrwx. 1 root root 37 May 8 2020 crond.service -> /usr/lib/systemd/system/crond.service lrwxrwxrwx. 1 root root 33 Jun 3 14:02 cups.path -> /usr/lib/systemd/system/cups.path lrwxrwxrwx. 1 root root 36 Jun 3 14:02 cups.service -> /usr/lib/systemd/system/cups.service lrwxrwxrwx. 1 root root 43 May 8 2020 dnf-makecache.timer -> /usr/lib/systemd/system/dnf-makecache.timer lrwxrwxrwx. 1 root root 41 May 8 2020 firewalld.service -> /usr/lib/systemd/system/firewalld.service lrwxrwxrwx. 1 root root 42 May 8 2020 irqbalance.service -> /usr/lib/systemd/system/irqbalance.service lrwxrwxrwx. 1 root root 37 May 8 2020 kdump.service -> /usr/lib/systemd/system/kdump.service lrwxrwxrwx. 1 root root 35 Apr 19 12:07 ksm.service -> /usr/lib/systemd/system/ksm.service lrwxrwxrwx. 1 root root 40 Apr 19 12:07 ksmtuned.service -> /usr/lib/systemd/system/ksmtuned.service lrwxrwxrwx. 1 root root 46 May 8 2020 libstoragemgmt.service -> /usr/lib/systemd/system/libstoragemgmt.service lrwxrwxrwx. 1 root root 40 Apr 19 12:07 libvirtd.service -> /usr/lib/systemd/system/libvirtd.service lrwxrwxrwx. 1 root root 38 May 8 2020 mcelog.service -> /usr/lib/systemd/system/mcelog.service lrwxrwxrwx. 1 root root 41 May 8 2020 mdmonitor.service -> /usr/lib/systemd/system/mdmonitor.service lrwxrwxrwx. 1 root root 49 Apr 19 12:07 netcf-transaction.service -> /usr/lib/systemd/system/netcf-transaction.service lrwxrwxrwx. 1 root root 46 May 8 2020 NetworkManager.service -> /usr/lib/systemd/system/NetworkManager.service lrwxrwxrwx. 1 root root 41 Apr 19 12:07 nfs-client.target -> /usr/lib/systemd/system/nfs-client.target lrwxrwxrwx. 1 root root 40 May 8 2020 remote-fs.target -> /usr/lib/systemd/system/remote-fs.target lrwxrwxrwx. 1 root root 39 Apr 19 12:07 rpcbind.service -> /usr/lib/systemd/system/rpcbind.service lrwxrwxrwx. 1 root root 39 May 8 2020 rsyslog.service -> /usr/lib/systemd/system/rsyslog.service lrwxrwxrwx. 1 root root 38 May 8 2020 smartd.service -> /usr/lib/systemd/system/smartd.service lrwxrwxrwx. 1 root root 36 May 8 2020 sshd.service -> /usr/lib/systemd/system/sshd.service lrwxrwxrwx. 1 root root 36 May 8 2020 sssd.service -> /usr/lib/systemd/system/sssd.service lrwxrwxrwx. 1 root root 37 May 8 2020 tuned.service -> /usr/lib/systemd/system/tuned.service lrwxrwxrwx. 1 root root 35 May 8 2020 vdo.service -> /usr/lib/systemd/system/vdo.service [root@centos8 ~]# ls -l /usr/lib/systemd/system/multi-user.target.wants total 0 lrwxrwxrwx. 1 root root 15 Apr 7 12:08 dbus.service -> ../dbus.service lrwxrwxrwx. 1 root root 15 Apr 7 16:55 getty.target -> ../getty.target lrwxrwxrwx. 1 root root 24 Oct 6 2020 plymouth-quit.service -> ../plymouth-quit.service lrwxrwxrwx. 1 root root 29 Oct 6 2020 plymouth-quit-wait.service -> ../plymouth-quit-wait.service lrwxrwxrwx. 1 root root 33 Apr 7 16:55 systemd-ask-password-wall.path -> ../systemd-ask-password-wall.path lrwxrwxrwx. 1 root root 25 Apr 7 16:55 systemd-logind.service -> ../systemd-logind.service lrwxrwxrwx. 1 root root 39 Apr 7 16:55 systemd-update-utmp-runlevel.service -> ../systemd-update-utmp-runlevel.service lrwxrwxrwx. 1 root root 32 Apr 7 16:55 systemd-user-sessions.service -> ../systemd-user-sessions.service
4.2 - La Cible par Défaut
Consulter la Cible par Défaut
Pour consulter la cible par défaut, il convient d'utiliser la commande systemctl get-default :
[root@centos8 ~]# systemctl get-default multi-user.target
La Cible par défaut est représentée par le lien symbolique /etc/systemd/system/default.target :
[root@centos8 ~]# ls -l /etc/systemd/system/default.target lrwxrwxrwx. 1 root root 37 May 8 2020 /etc/systemd/system/default.target -> /lib/systemd/system/multi-user.target
Modifier la Cible par Défaut
Pour modifier la Cible par défaut avec une prise en compte lors du prochain démarrage, il convient d'utiliser la commande systemctl set-default :
[root@centos8 ~]# systemctl set-default graphical.target Removed /etc/systemd/system/default.target. Created symlink /etc/systemd/system/default.target → /usr/lib/systemd/system/graphical.target. [root@centos8 ~]# ls -l /etc/systemd/system/default.target lrwxrwxrwx. 1 root root 40 Jun 6 08:11 /etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target [root@centos8 ~]# systemctl set-default multi-user.target Removed /etc/systemd/system/default.target. Created symlink /etc/systemd/system/default.target → /usr/lib/systemd/system/multi-user.target. [root@centos8 ~]# ls -l /etc/systemd/system/default.target lrwxrwxrwx. 1 root root 41 Jun 6 08:11 /etc/systemd/system/default.target -> /usr/lib/systemd/system/multi-user.target
Modifier la Cible en Cours
Il est possible de modifier la cible actuellement en cours en utilisant la commande systemctl isolate :
[root@centos8 ~]# systemctl isolate rescue [root@centos8 ~]# systemctl list-units --type target | egrep "eme|res|gra|mul" | head -1 rescue.target loaded active active Rescue Mode [root@centos8 ~]# runlevel 3 1 [root@centos8 ~]# who -r run-level 1 2021-06-15 04:22 last=3
[root@centos8 ~]# systemctl isolate multi-user [root@centos8 ~]# systemctl list-units --type target | egrep "eme|res|gra|mul" | head -1 multi-user.target loaded active active Multi-User System [root@centos8 ~]# runlevel 1 3 [root@centos8 ~]# who -r run-level 3 2021-06-15 04:24 last=1
LAB #5 - Gestion des Services
5.1 - Gestion des Instances Uniques
Commencez par installer le paquet httpd :
[root@centos8 ~]# dnf install httpd
Pour obtenir le détail sur un service donné, il convient d'utiliser la commande systemctl status :
[root@centos8 ~]# systemctl status httpd.service ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: inactive (dead) Docs: man:httpd.service(8)
Dans le cas du service httpd ci-dessus, on peut constater que le statut est disabled. Le statut peut être une de 2 valeurs :
- disabled - le service ne démarrera pas lors du prochain démarrage du système.
- enabled - le service démarrera lors du prochain démarrage du système.
Il est possible de vérifier le statut en utilisant le commande systemctl is-enabled :
[root@centos8 ~]# systemctl is-enabled httpd.service disabled
Pour rendre le statut enabled, il convient d'utiliser la commande systemctl enable :
[root@centos8 ~]# systemctl enable httpd.service Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service. [root@centos8 ~]# systemctl is-enabled httpd.service enabled [root@centos8 ~]# systemctl status httpd.service ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: inactive (dead) Docs: man:httpd.service(8)
Dans le cas du service httpd ci-dessus, on peut maintenant constater que l'état est inactive (dead). L'état peut être une de 7 valeurs :
- inactive (dead) - le service est arrêté.
- active(running - le service est démarré avec un ou plusieurs processus.
- active(exited) - le service a terminé une configuration unique.
- active(waiting) - le service est démarré mais en attente d'un évènement.
- activating - le service est en cours d'activation.
- deactivating - le service est en cours de désactivation.
- failed - le service a rencontré une erreur fatale.
Il est possible de vérifier l'état en utilisant le commande systemctl is-active :
[root@centos8 ~]# systemctl is-active httpd.service inactive
Pour rendre l'état active(running), utilisez la commande suivante :
[root@centos8 ~]# systemctl start httpd.service
Vérifiez ensuite l'état du service :
[root@centos8 ~]# systemctl is-active httpd.service active [root@centos8 ~]# systemctl status httpd.service ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Sun 2021-06-06 15:33:06 EDT; 14s ago Docs: man:httpd.service(8) Main PID: 34382 (httpd) Status: "Running, listening on: port 80" Tasks: 213 (limit: 23719) Memory: 36.3M CGroup: /system.slice/httpd.service ├─34382 /usr/sbin/httpd -DFOREGROUND ├─34383 /usr/sbin/httpd -DFOREGROUND ├─34384 /usr/sbin/httpd -DFOREGROUND ├─34385 /usr/sbin/httpd -DFOREGROUND └─34386 /usr/sbin/httpd -DFOREGROUND Jun 06 15:33:05 centos8.ittraining.loc systemd[1]: Starting The Apache HTTP Server... Jun 06 15:33:06 centos8.ittraining.loc systemd[1]: Started The Apache HTTP Server. Jun 06 15:33:06 centos8.ittraining.loc httpd[34382]: Server configured, listening on: port 80
Pour arrêter une Unité de service, utilisez la commande suivante :
[root@centos8 ~]# systemctl stop httpd.service [root@centos8 ~]# systemctl status httpd.service ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: inactive (dead) since Sun 2021-06-06 23:58:04 EDT; 8s ago Docs: man:httpd.service(8) Process: 34382 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=0/SUCCESS) Main PID: 34382 (code=exited, status=0/SUCCESS) Status: "Running, listening on: port 80" Jun 06 15:33:05 centos8.ittraining.loc systemd[1]: Starting The Apache HTTP Server... Jun 06 15:33:06 centos8.ittraining.loc systemd[1]: Started The Apache HTTP Server. Jun 06 15:33:06 centos8.ittraining.loc httpd[34382]: Server configured, listening on: port 80 Jun 06 23:58:02 centos8.ittraining.loc systemd[1]: Stopping The Apache HTTP Server... Jun 06 23:58:04 centos8.ittraining.loc systemd[1]: httpd.service: Succeeded. Jun 06 23:58:04 centos8.ittraining.loc systemd[1]: Stopped The Apache HTTP Server.
Pour désactiver un service au prochain démarrage du système, utilisez l'option disable :
[root@centos8 ~]# systemctl disable httpd.service Removed /etc/systemd/system/multi-user.target.wants/httpd.service. [root@centos8 ~]# systemctl status httpd.service ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: inactive (dead) Docs: man:httpd.service(8) Jun 06 15:33:05 centos8.ittraining.loc systemd[1]: Starting The Apache HTTP Server... Jun 06 15:33:06 centos8.ittraining.loc systemd[1]: Started The Apache HTTP Server. Jun 06 15:33:06 centos8.ittraining.loc httpd[34382]: Server configured, listening on: port 80 Jun 06 23:58:02 centos8.ittraining.loc systemd[1]: Stopping The Apache HTTP Server... Jun 06 23:58:04 centos8.ittraining.loc systemd[1]: httpd.service: Succeeded. Jun 06 23:58:04 centos8.ittraining.loc systemd[1]: Stopped The Apache HTTP Server.
5.2 - Gestion d'Instances Multiples
Systemd permet l'utilisation des gabarits (templates) des fichiers de configuration des Unités. De cette façon il est possible de faire coexister deux ou plusieurs instances du même service. Un gabarit est reconnaissable par le caractère @ qui est placé juste avant le point dans le nom du fichier :
[root@centos8 ~]# cat /usr/lib/systemd/system/httpd@.service # This is a template for httpd instances. # See httpd@.service(8) for more information. [Unit] Description=The Apache HTTP Server After=network.target remote-fs.target nss-lookup.target Documentation=man:httpd@.service(8) [Service] Type=notify Environment=LANG=C Environment=HTTPD_INSTANCE=%i ExecStartPre=/bin/mkdir -m 710 -p /run/httpd/instance-%i ExecStartPre=/bin/chown root.apache /run/httpd/instance-%i ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND -f conf/%i.conf ExecReload=/usr/sbin/httpd $OPTIONS -k graceful -f conf/%i.conf # Send SIGWINCH for graceful stop KillSignal=SIGWINCH KillMode=mixed PrivateTmp=true [Install] WantedBy=multi-user.target
Une instance créée à partir de ce gabarit devrait avoir un nom sous la forme suivante :
httpd@<nom_instance>.service
Dans ce fichier on peut constater l'utilisation d'un identifier sous la forme de %i. Les identifiers sont de deux types - un dit échappé où les caractères non-ASCII alphanumérique sont remplacés par escapes de type langage C et l'autre non-échappé :
- %n : est remplacé par le nom complet échappé de l'Unité.
- %N : est remplacé par le nom complet non-échappé de l'Unité.
- %p : est remplacé par le préfixe échappé de l'Unité, c'est-à-dire la partie avant le caractère @.
- %P : est remplacé par le préfixe non-échappé de l'Unité, c'est-à-dire la partie avant le caractère @.
- %i : est remplacé par le nom de l'instance échappé de l'Unité, c'est-à-dire la partie après le caractère @ et avant le point.
- %I : est remplacé par le nom de l'instance non-échappé de l'Unité, c'est-à-dire la partie après le caractère @ et avant le point.
- %f : est remplacé par le préfixe non-échappé ou le nom de l'instance non-échappé préfixé par le caractère /.
- %c : est remplacé par le CGroup de l'Unité sans le chemin /sys/fs/cgroup/systemd/.
- %u : est remplacé par le nom de l'utilisateur responsable de l'exécution de l'Unité.
- %U : est remplacé par l'UID de l'utilisateur responsable de l'exécution de l'Unité.
- %H : est remplacé par le nom d'hôte sur lequel est exécuté l'Unité.
- %% : est remplacé“ par le caractère %.
Créez maintenant deux copies du fichier /usr/lib/systemd/system/httpd@.service :
[root@centos8 ~]# cp /usr/lib/systemd/system/httpd@.service /usr/lib/systemd/system/httpd@instance01.service [root@centos8 ~]# cp /usr/lib/systemd/system/httpd@.service /usr/lib/systemd/system/httpd@instance02.service
Créez deux copies du fichier /etc/httpd/conf/httpd.conf :
[root@centos8 ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/instance01.conf [root@centos8 ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/instance02.conf
Editez la directive Listen du fichier /etc/httpd/conf/instance01.conf et ajoutez la directive PidFile :
[root@centos8 ~]# vi /etc/httpd/conf/instance01.conf [root@centos8 ~]# more /etc/httpd/conf/instance01.conf # # This is the main Apache HTTP server configuration file. It contains the # configuration directives that give the server its instructions. # See <URL:http://httpd.apache.org/docs/2.4/> for detailed information. # In particular, see # <URL:http://httpd.apache.org/docs/2.4/mod/directives.html> # for a discussion of each configuration directive. # # See the httpd.conf(5) man page for more information on this configuration, # and httpd.service(8) on using and configuring the httpd service. # # Do NOT simply read the instructions in here without understanding # what they do. They're here only as hints or reminders. If you are unsure # consult the online docs. You have been warned. # # Configuration and logfile names: If the filenames you specify for many # of the server's control files begin with "/" (or "drive:/" for Win32), the # server will use that explicit path. If the filenames do *not* begin # with "/", the value of ServerRoot is prepended -- so 'log/access_log' # with ServerRoot set to '/www' will be interpreted by the # server as '/www/log/access_log', where as '/log/access_log' will be # interpreted as '/log/access_log'. # # ServerRoot: The top of the directory tree under which the server's # configuration, error, and log files are kept. # # Do not add a slash at the end of the directory path. If you point # ServerRoot at a non-local disk, be sure to specify a local disk on the # Mutex directive, if file-based mutexes are used. If you wish to share the # same ServerRoot for multiple httpd daemons, you will need to change at # least PidFile. # ServerRoot "/etc/httpd" # # Listen: Allows you to bind Apache to specific IP addresses and/or # ports, instead of the default. See also the <VirtualHost> # directive. # # Change this to Listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses. # #Listen 12.34.56.78:80 Listen 8008 PidFile /var/run/httpd/instance01.pid # # Dynamic Shared Object (DSO) Support # # To be able to use the functionality of a module which was built as a DSO you # have to place corresponding `LoadModule' lines at this location so the # directives contained in it are actually available _before_ they are used. # Statically compiled modules (those listed by `httpd -l') do not need # to be loaded here. # # Example: # LoadModule foo_module modules/mod_foo.so --More--(19%)
Editez la directive Listen du fichier /etc/httpd/conf/instance02.conf et ajoutez la directive PidFile :
[root@centos8 ~]# vi /etc/httpd/conf/instance02.conf [root@centos8 ~]# more /etc/httpd/conf/instance02.conf # # This is the main Apache HTTP server configuration file. It contains the # configuration directives that give the server its instructions. # See <URL:http://httpd.apache.org/docs/2.4/> for detailed information. # In particular, see # <URL:http://httpd.apache.org/docs/2.4/mod/directives.html> # for a discussion of each configuration directive. # # See the httpd.conf(5) man page for more information on this configuration, # and httpd.service(8) on using and configuring the httpd service. # # Do NOT simply read the instructions in here without understanding # what they do. They're here only as hints or reminders. If you are unsure # consult the online docs. You have been warned. # # Configuration and logfile names: If the filenames you specify for many # of the server's control files begin with "/" (or "drive:/" for Win32), the # server will use that explicit path. If the filenames do *not* begin # with "/", the value of ServerRoot is prepended -- so 'log/access_log' # with ServerRoot set to '/www' will be interpreted by the # server as '/www/log/access_log', where as '/log/access_log' will be # interpreted as '/log/access_log'. # # ServerRoot: The top of the directory tree under which the server's # configuration, error, and log files are kept. # # Do not add a slash at the end of the directory path. If you point # ServerRoot at a non-local disk, be sure to specify a local disk on the # Mutex directive, if file-based mutexes are used. If you wish to share the # same ServerRoot for multiple httpd daemons, you will need to change at # least PidFile. # ServerRoot "/etc/httpd" # # Listen: Allows you to bind Apache to specific IP addresses and/or # ports, instead of the default. See also the <VirtualHost> # directive. # # Change this to Listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses. # #Listen 12.34.56.78:80 Listen 8009 PidFile /var/run/httpd/instance02.pid # # Dynamic Shared Object (DSO) Support # # To be able to use the functionality of a module which was built as a DSO you # have to place corresponding `LoadModule' lines at this location so the # directives contained in it are actually available _before_ they are used. # Statically compiled modules (those listed by `httpd -l') do not need # to be loaded here. # # Example: # LoadModule foo_module modules/mod_foo.so --More--(19%)
Démarrez les deux services :
[root@centos8 ~]# systemctl start httpd@instance01.service [root@centos8 ~]# systemctl status httpd@instance01.service ● httpd@instance01.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd@instance01.service; disabled; vendor preset: disabled) Active: active (running) since Mon 2021-06-07 01:40:43 EDT; 7s ago Docs: man:httpd@.service(8) Process: 43854 ExecStartPre=/bin/chown root.apache /run/httpd/instance-instance01 (code=exited, status=0/SUCCESS) Process: 43852 ExecStartPre=/bin/mkdir -m 710 -p /run/httpd/instance-instance01 (code=exited, status=0/SUCCESS) Main PID: 43856 (httpd) Status: "Started, listening on: port 8008" Tasks: 213 (limit: 23719) Memory: 43.6M CGroup: /system.slice/system-httpd.slice/httpd@instance01.service ├─43856 /usr/sbin/httpd -DFOREGROUND -f conf/instance01.conf ├─43857 /usr/sbin/httpd -DFOREGROUND -f conf/instance01.conf ├─43858 /usr/sbin/httpd -DFOREGROUND -f conf/instance01.conf ├─43859 /usr/sbin/httpd -DFOREGROUND -f conf/instance01.conf └─43860 /usr/sbin/httpd -DFOREGROUND -f conf/instance01.conf Jun 07 01:40:43 centos8.ittraining.loc systemd[1]: Starting The Apache HTTP Server... Jun 07 01:40:43 centos8.ittraining.loc systemd[1]: Started The Apache HTTP Server. Jun 07 01:40:43 centos8.ittraining.loc httpd[43856]: Server configured, listening on: port 8008 [root@centos8 ~]# systemctl start httpd@instance02.service [root@centos8 ~]# systemctl status httpd@instance02.service ● httpd@instance02.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd@instance02.service; disabled; vendor preset: disabled) Active: active (running) since Mon 2021-06-07 01:36:45 EDT; 4min 24s ago Docs: man:httpd@.service(8) Process: 43568 ExecStartPre=/bin/chown root.apache /run/httpd/instance-instance02 (code=exited, status=0/SUCCESS) Process: 43566 ExecStartPre=/bin/mkdir -m 710 -p /run/httpd/instance-instance02 (code=exited, status=0/SUCCESS) Main PID: 43569 (httpd) Status: "Running, listening on: port 8009" Tasks: 213 (limit: 23719) Memory: 43.6M CGroup: /system.slice/system-httpd.slice/httpd@instance02.service ├─43569 /usr/sbin/httpd -DFOREGROUND -f conf/instance02.conf ├─43571 /usr/sbin/httpd -DFOREGROUND -f conf/instance02.conf ├─43572 /usr/sbin/httpd -DFOREGROUND -f conf/instance02.conf ├─43573 /usr/sbin/httpd -DFOREGROUND -f conf/instance02.conf └─43574 /usr/sbin/httpd -DFOREGROUND -f conf/instance02.conf Jun 07 01:36:45 centos8.ittraining.loc systemd[1]: Starting The Apache HTTP Server... Jun 07 01:36:45 centos8.ittraining.loc systemd[1]: Started The Apache HTTP Server. Jun 07 01:36:45 centos8.ittraining.loc httpd[43569]: Server configured, listening on: port 8009
5.3 - Interdire la Modification du Statut d'un Service
Il est possible d'interdire la modification en utilisant la commande systemctl mask:
[root@centos8 ~]# systemctl status httpd.service ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: inactive (dead) Docs: man:httpd.service(8) Jun 07 18:27:25 centos8.ittraining.loc httpd[58535]: Server configured, listening on: port 80 Jun 07 18:27:29 centos8.ittraining.loc systemd[1]: Stopping The Apache HTTP Server... Jun 07 18:27:30 centos8.ittraining.loc systemd[1]: httpd.service: Succeeded. Jun 07 18:27:30 centos8.ittraining.loc systemd[1]: Stopped The Apache HTTP Server. Jun 07 18:27:32 centos8.ittraining.loc systemd[1]: Starting The Apache HTTP Server... Jun 07 18:27:32 centos8.ittraining.loc systemd[1]: Started The Apache HTTP Server. Jun 07 18:27:32 centos8.ittraining.loc httpd[58760]: Server configured, listening on: port 80 Jun 07 18:27:34 centos8.ittraining.loc systemd[1]: Stopping The Apache HTTP Server... Jun 07 18:27:36 centos8.ittraining.loc systemd[1]: httpd.service: Succeeded. Jun 07 18:27:36 centos8.ittraining.loc systemd[1]: Stopped The Apache HTTP Server. [root@centos8 ~]# systemctl mask httpd.service Created symlink /etc/systemd/system/httpd.service → /dev/null. [root@centos8 ~]# systemctl enable httpd.service Failed to enable unit: Unit file /etc/systemd/system/httpd.service is masked. [root@centos8 ~]# systemctl start httpd.service Failed to start httpd.service: Unit httpd.service is masked.
Pour autoriser de nouveau les modifications, il convient d'utiliser la commande systemctl unmask :
[root@centos8 ~]# systemctl unmask httpd.service Removed /etc/systemd/system/httpd.service. [root@centos8 ~]# systemctl enable httpd.service Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service. [root@centos8 ~]# systemctl start httpd.service [root@centos8 ~]# systemctl status httpd.service ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2021-06-07 18:30:59 EDT; 5s ago Docs: man:httpd.service(8) Main PID: 59101 (httpd) Status: "Started, listening on: port 80" Tasks: 213 (limit: 23719) Memory: 39.4M CGroup: /system.slice/httpd.service ├─59101 /usr/sbin/httpd -DFOREGROUND ├─59102 /usr/sbin/httpd -DFOREGROUND ├─59103 /usr/sbin/httpd -DFOREGROUND ├─59104 /usr/sbin/httpd -DFOREGROUND └─59105 /usr/sbin/httpd -DFOREGROUND Jun 07 18:30:59 centos8.ittraining.loc systemd[1]: Starting The Apache HTTP Server... Jun 07 18:30:59 centos8.ittraining.loc systemd[1]: Started The Apache HTTP Server. Jun 07 18:31:00 centos8.ittraining.loc httpd[59101]: Server configured, listening on: port 80
Arrêt du Système
Sous RHEL / CentOS 8 les commandes halt, poweroff, reboot et shutdown sont des liens symboliques vers /bin/systemctl :
[root@centos8 ~]# ls -l /usr/sbin/shutdown /usr/sbin/halt /usr/sbin/poweroff /usr/sbin/reboot lrwxrwxrwx. 1 root root 16 Apr 7 16:55 /usr/sbin/halt -> ../bin/systemctl lrwxrwxrwx. 1 root root 16 Apr 7 16:55 /usr/sbin/poweroff -> ../bin/systemctl lrwxrwxrwx. 1 root root 16 Apr 7 16:55 /usr/sbin/reboot -> ../bin/systemctl lrwxrwxrwx. 1 root root 16 Apr 7 16:55 /usr/sbin/shutdown -> ../bin/systemctl
La manière recommendée d'utiliser ces commandes est donc :
- systemctl halt
- systemctl poweroff
- systemctl reboot
- systemctl shutdown
Il est cependant toujours possibles d'utiliser les commandes halt, poweroff, reboot et shutdown.
La Commande shutdown
Lors de l'arrêt de la machine, Linux procède, entre autre, aux tâches suivantes :
- Il previent les utilisateurs,
- Il arrête tous les services,
- Il inscrit toutes les données sur disque,
- Il démonte les systèmes de fichiers.
La commande utilisée pour arrêter le système est la commande shutdown :
shutdown [-t sec] [-HPrhkc] heure [message]
Options de la commande
Les options de cette commande sont :
[root@centos8 ~]# shutdown --help shutdown [OPTIONS...] [TIME] [WALL...] Shut down the system. --help Show this help -H --halt Halt the machine -P --poweroff Power-off the machine -r --reboot Reboot the machine -h Equivalent to --poweroff, overridden by --halt -k Don't halt/power-off/reboot, just send warnings --no-wall Don't send wall message before halt/power-off/reboot -c Cancel a pending shutdown
L'option heure peut prendre plusieurs valeurs :
Valeur | Description |
---|---|
hh:mm | L'heure à laquelle l'opération aura lieu |
+m | Nombre de minutes avant que l'opération aura lieu. Si aucune valeur n'est spécifiée, la valeur par défaut est +1 |
now | L'opération est immédiate. now est un alias de +0 |
Important : Si l'opération est programmée pour dans moins de 5 minutes, les connexions supplémentaires sont interdites, y comprises les tentatives de connexion de root.
L'option -t est utilisée pour accorder un temps de grâce :
[root@centos8 ~]# date && shutdown -t 60 -k Mon Jun 7 18:58:26 EDT 2021 Shutdown scheduled for Mon 2021-06-07 18:59:26 EDT, use 'shutdown -c' to cancel.
La Commande reboot
Cette commande redémarre le système.
Options de la commande
Les options de cette commande sont :
[root@centos8 ~]# reboot --help reboot [OPTIONS...] [ARG] Reboot the system. --help Show this help --halt Halt the machine -p --poweroff Switch off the machine --reboot Reboot the machine -f --force Force immediate halt/power-off/reboot -w --wtmp-only Don't halt/power-off/reboot, just write wtmp record -d --no-wtmp Don't write wtmp record --no-wall Don't send wall message before halt/power-off/reboot
La Commande halt
Cette commande arrête le système.
Options de la commande
Les options de cette commande sont :
[root@centos8 ~]# halt --help halt [OPTIONS...] Halt the system. --help Show this help --halt Halt the machine -p --poweroff Switch off the machine --reboot Reboot the machine -f --force Force immediate halt/power-off/reboot -w --wtmp-only Don't halt/power-off/reboot, just write wtmp record -d --no-wtmp Don't write wtmp record --no-wall Don't send wall message before halt/power-off/reboot
La Commande poweroff
Cette commande arrête le système et coupe l'alimentation électrique.
Options de la commande
Les options de cette commande sont :
[root@centos8 ~]# poweroff --help poweroff [OPTIONS...] Power off the system. --help Show this help --halt Halt the machine -p --poweroff Switch off the machine --reboot Reboot the machine -f --force Force immediate halt/power-off/reboot -w --wtmp-only Don't halt/power-off/reboot, just write wtmp record -d --no-wtmp Don't write wtmp record --no-wall Don't send wall message before halt/power-off/reboot
Copyright © 2024 Hugh Norris.