Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| elearning:workbooks:redhat:rh134:l101 [2024/10/21 12:17] – admin | elearning:workbooks:redhat:rh134:l101 [2024/10/21 15:02] (Version actuelle) – admin | ||
|---|---|---|---|
| Ligne 21: | Ligne 21: | ||
| * LAB #3 - at | * LAB #3 - at | ||
| * 3.1 - Le Répertoire / | * 3.1 - Le Répertoire / | ||
| + | * LAB #4 - Timers systemd | ||
| + | * 4.1 - systemd-tmpfiles-clean.timer | ||
| + | * 4.2 - Configurer le systemd-tmpfiles-clean.service | ||
| =====cron===== | =====cron===== | ||
| Ligne 350: | Ligne 353: | ||
| **Important** - La commande **batch** ou son alias **at -b** est utilisée pour exécuter des commandes au moment où la charge sur le système est en dessous un certain niveau. Par défaut la valeur est fixée à **1.5**. Cette valeur peut être modifiée par l' | **Important** - La commande **batch** ou son alias **at -b** est utilisée pour exécuter des commandes au moment où la charge sur le système est en dessous un certain niveau. Par défaut la valeur est fixée à **1.5**. Cette valeur peut être modifiée par l' | ||
| </ | </ | ||
| + | |||
| + | =====LAB #4 - Timers systemd===== | ||
| + | |||
| + | Depuis l' | ||
| + | |||
| + | ====4.1 - systemd-tmpfiles-clean.timer==== | ||
| + | |||
| + | Par exemple, afin d' | ||
| + | |||
| + | < | ||
| + | [root@redhat9 ~]# systemctl cat systemd-tmpfiles-clean.timer | ||
| + | # / | ||
| + | # SPDX-License-Identifier: | ||
| + | # | ||
| + | # 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=Daily Cleanup of Temporary Directories | ||
| + | Documentation=man: | ||
| + | ConditionPathExists=!/ | ||
| + | |||
| + | [Timer] | ||
| + | OnBootSec=15min | ||
| + | OnUnitActiveSec=1d | ||
| + | </ | ||
| + | |||
| + | Dans ce fichier on peut constater la section **[Timer]** qui continet deux directives : | ||
| + | |||
| + | * **OnBootSec=15min** - indique que le **systemd-tmpfiles-clean.service** est déclenché 15 minutes après le démarrage du système, | ||
| + | * **OnUnitActiveSec=1d** - indique que par la suite, le service est déclenché 24 heures après son dernier déclenchement. | ||
| + | |||
| + | Constatez donc que le **systemd-tmpfiles-clean.timer** soit bien activé et démarré : | ||
| + | |||
| + | < | ||
| + | [root@redhat9 ~]# systemctl status systemd-tmpfiles-clean.timer | ||
| + | ● systemd-tmpfiles-clean.timer - Daily Cleanup of Temporary Directories | ||
| + | | ||
| + | | ||
| + | Until: Mon 2024-10-21 11:56:07 CEST; 4h 1min ago | ||
| + | Trigger: Tue 2024-10-22 12:11:34 CEST; 20h left | ||
| + | | ||
| + | Docs: man: | ||
| + | | ||
| + | |||
| + | Oct 21 11:56:07 redhat9.ittraining.loc systemd[1]: Started Daily Cleanup of Temporary> | ||
| + | </ | ||
| + | |||
| + | Par contre le **status systemd-tmpfiles-clean.service** n'est ni activé, ni démarré : | ||
| + | |||
| + | < | ||
| + | [root@redhat9 ~]# systemctl status systemd-tmpfiles-clean.service | ||
| + | ○ systemd-tmpfiles-clean.service - Cleanup of Temporary Directories | ||
| + | | ||
| + | | ||
| + | TriggeredBy: | ||
| + | Docs: man: | ||
| + | | ||
| + | Process: 2174 ExecStart=systemd-tmpfiles --clean (code=exited, | ||
| + | Main PID: 2174 (code=exited, | ||
| + | CPU: 30ms | ||
| + | |||
| + | Oct 21 12:11:34 redhat9.ittraining.loc systemd[1]: Starting Cleanup of Temporary Dire> | ||
| + | Oct 21 12:11:34 redhat9.ittraining.loc systemd[1]: systemd-tmpfiles-clean.service: | ||
| + | Oct 21 12:11:34 redhat9.ittraining.loc systemd[1]: Finished Cleanup of Temporary Dire> | ||
| + | < | ||
| + | |||
| + | Ceci s' | ||
| + | |||
| + | < | ||
| + | [root@redhat9 ~]# systemctl list-unit-files | grep systemd-tmpfiles-clean.service | ||
| + | systemd-tmpfiles-clean.service | ||
| + | </ | ||
| + | |||
| + | La valeur **static** implique que l' | ||
| + | |||
| + | < | ||
| + | [root@redhat9 ~]# systemctl start systemd-tmpfiles-clean.service | ||
| + | |||
| + | [root@redhat9 ~]# systemctl status systemd-tmpfiles-clean.service | ||
| + | ○ systemd-tmpfiles-clean.service - Cleanup of Temporary Directories | ||
| + | | ||
| + | | ||
| + | TriggeredBy: | ||
| + | Docs: man: | ||
| + | | ||
| + | Process: 5713 ExecStart=systemd-tmpfiles --clean (code=exited, | ||
| + | Main PID: 5713 (code=exited, | ||
| + | CPU: 25ms | ||
| + | |||
| + | Oct 21 16:19:45 redhat9.ittraining.loc systemd[1]: Starting Cleanup of Temporary Dire> | ||
| + | Oct 21 16:19:45 redhat9.ittraining.loc systemd[1]: systemd-tmpfiles-clean.service: | ||
| + | Oct 21 16:19:45 redhat9.ittraining.loc systemd[1]: Finished Cleanup of Temporary Dire> | ||
| + | </ | ||
| + | |||
| + | Modifiez la valuer de **OnUnitActiveSec** en utilisant la commande suivante : | ||
| + | |||
| + | < | ||
| + | [root@redhat9 ~]# EDITOR=vim | ||
| + | |||
| + | [root@redhat9 ~]# export EDITOR | ||
| + | |||
| + | [root@redhat9 ~]# systemctl edit systemd-tmpfiles-clean.timer | ||
| + | ### Editing / | ||
| + | ### Anything between here and the comment below will become the new contents of the file | ||
| + | |||
| + | [Unit] | ||
| + | Description=Daily Cleanup of Temporary Directories | ||
| + | Documentation=man: | ||
| + | ConditionPathExists=!/ | ||
| + | |||
| + | [Timer] | ||
| + | OnBootSec=15min | ||
| + | OnUnitActiveSec=30min | ||
| + | |||
| + | |||
| + | ### Lines below this comment will be discarded | ||
| + | |||
| + | ### / | ||
| + | # # SPDX-License-Identifier: | ||
| + | # # | ||
| + | # # 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=Daily Cleanup of Temporary Directories | ||
| + | # Documentation=man: | ||
| + | # ConditionPathExists=!/ | ||
| + | # | ||
| + | # [Timer] | ||
| + | # OnBootSec=15min | ||
| + | # OnUnitActiveSec=1d | ||
| + | </ | ||
| + | |||
| + | Utilisez la commande **systemctl daemon-reload** afin que systemd recharge la configuration : | ||
| + | |||
| + | < | ||
| + | [root@redhat9 ~]# systemctl daemon-reload | ||
| + | </ | ||
| + | |||
| + | Visualisez le contenu du fichier | ||
| + | |||
| + | < | ||
| + | [root@redhat9 ~]# cat / | ||
| + | [Unit] | ||
| + | Description=Daily Cleanup of Temporary Directories | ||
| + | Documentation=man: | ||
| + | ConditionPathExists=!/ | ||
| + | |||
| + | [Timer] | ||
| + | OnBootSec=15min | ||
| + | OnUnitActiveSec=30min | ||
| + | </ | ||
| + | |||
| + | Constatez l' | ||
| + | |||
| + | < | ||
| + | [root@redhat9 ~]# systemctl status systemd-tmpfiles-clean.timer | ||
| + | ● systemd-tmpfiles-clean.timer - Daily Cleanup of Temporary Directories | ||
| + | | ||
| + | Drop-In: / | ||
| + | | ||
| + | | ||
| + | Until: Mon 2024-10-21 11:56:07 CEST; 4h 42min ago | ||
| + | Trigger: Mon 2024-10-21 16:49:45 CEST; 10min left | ||
| + | | ||
| + | Docs: man: | ||
| + | | ||
| + | | ||
| + | | ||
| + | |||
| + | Oct 21 11:56:07 redhat9.ittraining.loc systemd[1]: Started Daily Cleanup of Temporary Directories. | ||
| + | </ | ||
| + | |||
| + | ====4.2 - Configurer le systemd-tmpfiles-clean.service==== | ||
| + | |||
| + | Les fichiers de configuration du service sont lus de trois emplacements différents et dans l' | ||
| + | |||
| + | * **/ | ||
| + | * les fichiers dans ce répertoire configurent le service, | ||
| + | * **/ | ||
| + | * les fichiers dans ce répertoire sont volatiles et sont utilisés par des daemons afin de gérer peurs propres fichiers temporaires, | ||
| + | * **/ | ||
| + | ** les fichiers dans ce répertoire sont fournis par des paquets RPM. Il est **déconseillé** de les modifier. | ||
| + | |||
| + | < | ||
| + | [root@redhat9 ~]# ls -l / | ||
| + | total 4 | ||
| + | -rw-r--r--. 1 root root 117 Aug 21 13:54 sos.conf | ||
| + | |||
| + | [root@redhat9 ~]# cat / | ||
| + | # Ignore the contents of extracted sosreport directories. | ||
| + | # | ||
| + | # Type Path Mode User Group Age Argument | ||
| + | x / | ||
| + | </ | ||
| + | |||
| + | La signification de la letter **x** peut être consultée avec la commande suivante : | ||
| + | |||
| + | < | ||
| + | [root@redhat9 ~]# man tmpfiles.d | ||
| + | ... | ||
| + | SYNOPSIS | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | |||
| + | | ||
| + | | ||
| + | | ||
| + | ... | ||
| + | / | ||
| + | |||
| + | #Type Path Mode User Group Age | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | ... | ||
| + | </ | ||
| ----- | ----- | ||
| Copyright © 2024 Hugh Norris. | Copyright © 2024 Hugh Norris. | ||