Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
utilisateurs:draco31.fr:brouillon [Le 13/11/2010, 23:35] draco31.fr Tests Box |
utilisateurs:draco31.fr:brouillon [Le 19/08/2012, 23:16] (Version actuelle) draco31.fr |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== Ceci est ma page BROUILLON !! ====== | + | ====== ∴☆★ Ceci est ma page BROUILLON !! ★☆∴ ====== |
- | ===== Test box ===== | + | ===== NUT & upsmon & upssched ===== |
- | ==== Page imprimantes ==== | + | ==== Monitorer les événements de l'UPS avec upsmon ==== |
- | * v0 -- Version Frombenny, page imprimante : | + | === Configuration par défaut === |
- | <box 100% center #FFFFFF><box 100px round left #dcf0ea>**[[:imprimantes_brother|Brother]]**</box> | + | Par défaut, toutes les types d’événements sont associés aux directives **SYSLOG** (écriture dans ''/var/log/syslog'') et **WALL** (notification aux utilisateurs par les terminaux). |
- | <box 100px round left #dcf0ea>**[[:tutoriel/installer_imprimante_canon|Canon]]**</box> | + | <note warning>FIXME Sous Ubuntu, la notification par la commande **''wall''** ne semble pas fonctionner !</note> |
- | <box 100px round left #dcf0ea>**[[:tutoriel/installer_imprimante_compaq|Compaq]]**</box> | + | |
- | <box 100px round left #dcf0ea>**[[:tutoriel/installer_imprimante_dell| Dell]]**</box> | + | |
- | <box 100px round left #dcf0ea>**[[:tutoriel/installer_imprimante_epson|Epson]]**</box> | + | |
- | <box 100px round left #dcf0ea>**[[:tutoriel/installer_imprimante_hp|HP]]**</box> | + | |
- | <box 150px round left #dcf0ea>**[[:tutoriel/installer_imprimante_konica|Konica/Minolta]]**</box> | + | |
- | <box 100px round left #dcf0ea>**[[:tutoriel/installer_imprimante_lexmark|Lexmark]]**</box> | + | |
- | <box 100px round left #dcf0ea>**[[:tutoriel/installer_imprimante_ricoh|Ricoh]]**</box> | + | |
- | <box 100px round left #dcf0ea>**[[:tutoriel/installer_imprimante_samsung|Samsung]]**</box> | + | |
- | <box 100px round left #dcf0ea>**[[:tutoriel/installer_imprimante_xerox|Xerox]]**</box></box> | + | |
- | Texte ... | + | Le fichier **''/etc/nut/upsmon''** contient donc les lignes suivantes : |
+ | <file> | ||
+ | NOTIFYFLAG ONLINE SYSLOG+WALL | ||
+ | NOTIFYFLAG ONBATT SYSLOG+WALL | ||
+ | NOTIFYFLAG LOWBATT SYSLOG+WALL | ||
+ | NOTIFYFLAG FSD SYSLOG+WALL | ||
+ | NOTIFYFLAG COMMOK SYSLOG+WALL | ||
+ | NOTIFYFLAG COMMBAD SYSLOG+WALL | ||
+ | NOTIFYFLAG SHUTDOWN SYSLOG+WALL | ||
+ | NOTIFYFLAG REPLBATT SYSLOG+WALL | ||
+ | NOTIFYFLAG NOCOMM SYSLOG+WALL | ||
+ | NOTIFYFLAG NOPARENT SYSLOG+WALL | ||
+ | </file> | ||
- | * v1 -- Mini box 10 x 7% + 1 x 14% | + | Dans **''/var/log/syslog''**, on obtient un message préformaté. Exemple : |
+ | <file> | ||
+ | Aug 19 21:49:34 localhost upsmon[7784]: Startup successful | ||
+ | Aug 19 21:50:24 localhost upsmon[7786]: UPS localups@localhost on battery | ||
+ | Aug 19 21:50:34 localhost upsmon[7786]: Poll UPS [localups@localhost] failed - Data stale | ||
+ | Aug 19 21:50:34 localhost upsmon[7786]: Communications with UPS localups@localhost lost | ||
+ | Aug 19 21:50:39 localhost upsmon[7786]: Communications with UPS localups@localhost established | ||
+ | Aug 19 21:50:39 localhost upsmon[7786]: UPS localups@localhost on line power | ||
+ | </file> | ||
- | <note>Problème si fenêtre redimensionnée : texte tronqué !</note> | + | <note>//Dans l'exemple ci-dessus ''localups'' est le libellé associé à l'onduleur dans le fichier **''/etc/nut/ups.conf''**//</note> |
- | <box 100% center #FFFFFF> | + | === Utilisation d'un script via l'option NOTIFYCMD et la directive EXEC=== |
- | <box 7% round left #dcf0ea>**[[:imprimantes_brother|Brother]]**</box> | + | |
- | <box 7% round left #dcf0ea>**[[:tutoriel/installer_imprimante_canon|Canon]]**</box> | + | |
- | <box 7% round left #dcf0ea>**[[:tutoriel/installer_imprimante_compaq|Compaq]]**</box> | + | |
- | <box 7% round left #dcf0ea>**[[:tutoriel/installer_imprimante_dell| Dell]]**</box> | + | |
- | <box 7% round left #dcf0ea>**[[:tutoriel/installer_imprimante_epson|Epson]]**</box> | + | |
- | <box 7% round left #dcf0ea>**[[:tutoriel/installer_imprimante_hp|HP]]**</box> | + | |
- | <box 14% round left #dcf0ea>**[[:tutoriel/installer_imprimante_konica|Konica/Minolta]]**</box> | + | |
- | <box 7% round left #dcf0ea>**[[:tutoriel/installer_imprimante_lexmark|Lexmark]]**</box> | + | |
- | <box 7% round left #dcf0ea>**[[:tutoriel/installer_imprimante_ricoh|Ricoh]]**</box> | + | |
- | <box 7% round left #dcf0ea>**[[:tutoriel/installer_imprimante_samsung|Samsung]]**</box> | + | |
- | <box 7% round left #dcf0ea>**[[:tutoriel/installer_imprimante_xerox|Xerox]]**</box> | + | |
- | </box> | + | |
- | Texte ... | + | Il est possible en plus ou la place des directives WALL et SYSLOG, d'utiliser la directive **''EXEC''** pour lancer un script définit par l'option **''NOTIFYCMD''** pour réaliser un traitement personnalisé. |
- | ==== Attributs ==== | + | Le fichier de configuration **''/etc/nut/upsmon.conf''** contiendra donc la ligne : |
+ | <file> | ||
+ | NOTIFYCMD /usr/local/bin/upsalert.sh | ||
+ | </file> | ||
+ | <note tip>Le chemin ''/usr/local/bin/upsalert.sh'' est à remplacer par celui votre script !</note> | ||
+ | Les options NOTIFYFAG concernée par ce traitement personnalisée doivent avoir la directive EXEC. Exemple pour ''ONLINE'' et ''ONBATT'' et ''LOWBATT'' : | ||
+ | <file> | ||
+ | NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC | ||
+ | NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC | ||
+ | NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC | ||
+ | NOTIFYFLAG FSD SYSLOG+WALL | ||
+ | NOTIFYFLAG COMMOK SYSLOG+WALL | ||
+ | NOTIFYFLAG COMMBAD SYSLOG+WALL | ||
+ | NOTIFYFLAG SHUTDOWN SYSLOG+WALL | ||
+ | NOTIFYFLAG REPLBATT SYSLOG+WALL | ||
+ | NOTIFYFLAG NOCOMM SYSLOG+WALL | ||
+ | NOTIFYFLAG NOPARENT SYSLOG+WALL | ||
+ | </file> | ||
- | * v2.1 -- Mini Box 50% seules | + | FIXME Le script reçoit en argument le même libellé que ce qui est tracé dans ''/var/log/syslog''. |
- | <box 50% round left>50%</box> | + | == Notification par mail == |
- | <box 50% round left>50%</box> | + | |
- | \\ \\ \\ \\ \\ \\ | + | <note warning>Votre modem ainsi que vos équipements réseaux reliant ce dernier au PC hébergeant upsmon serveur (relié à l'onduleur) et upsmon client (celui exécutant le script) doivent aussi être alimentés pour pouvoir envoyer le mail au moment opportun. Dans le cas contraire, vous risquez de ne recevoir le mail que lorsque le courant revient, voir de ne pas recevoir le mail du tout !!</note> |
- | * v2.2 -- Mini Box xx% dans box 100% | + | ** Choix d'un MTA accessible en console ** |
- | <box 100% center|100%> | + | Plusieurs MTA (mail transfert agent) accessible en console sont disponibles dans les dépôts. Parmi ceux-ci on notera : |
- | <box 50% round left>50%</box> | + | * [[:ssmtp]] : Très simple d'utilisation |
- | <box 50% round left>50%</box> | + | * [[:mutt]] : plus évolué que ''ssmtp'' et ligne de commande plus complexe |
- | </box> | + | * [[:postfix]] : le plus puissant, mais aussi plus compliqué à configurer ! |
- | <box 100% center|100%> | + | ** Installation et configuration avec SSMTP ** |
- | <box 40% round left>40%</box> | + | |
- | <box 40% round left>40%</box> | + | |
- | <box 40% round left>40%</box> | + | |
- | </box> | + | |
- | <box 100% center|100%> | + | Exemple avec ''ssmtp'' : |
- | <box 30% round left>30%</box> | + | * [[:tutoriel:comment_installer_un_paquet|Installer le paquet]] **[[apt>ssmtp]]** |
- | <box 30% round left>30%</box> | + | * [[:tutoriel:comment_modifier_un_fichier|Modifier le fichier]] **''/etc/ssmtp/ssmtp.conf''** suivant l'exemple ci-dessous :<file> |
- | <box 30% round left>30%</box> | + | root=mon-adresse-email@mon-fai.fr 25 |
- | <box 30% round left>30%</box> | + | mailhub=smtp.fai.fr |
- | </box> | + | hostname=ubuntu-desktop |
+ | FromLineOverride=YES | ||
+ | </file> | ||
+ | * Depuis un [[:terminal]], faites un essai avec la commande ci-dessous :<code>ssmtp <mon-adresse-email@mon-fai.fr></code>entrez le texte suivant :<code>From: mon-adresse-email@mon-fai.fr | ||
+ | Subject: Test envoi mail avec ssmtp | ||
+ | Test réussi ! Bravo ! | ||
+ | </code>et enfin, appuyez sur la combinaison CTRL+D pour terminer la saisie et envoyer le mail. | ||
- | <box 100% center|100%> | + | ** Création du script de notification mail ** |
- | <box 25% round left>25%</box> | + | |
- | <box 25% round left>25%</box> | + | |
- | <box 25% round left>25%</box> | + | |
- | <box 25% round left>25%</box> | + | |
- | </box> | + | |
- | ==== Modulation sur box 25% ==== | + | <note> A METTRE EN FORME --- Brouillon</note> |
+ | Créer un fichier pour l'entête avec une ligne From: ; To: ; Subject: : Ces données sont invariantes dans le message. | ||
+ | Créer le script contenant les lignes : | ||
+ | <code>#!/bin/bash | ||
+ | echo "$@" | cat </chemin/fichier/entête> - | ssmtp <mon-adresse-mail@mon-fai.fr> | ||
+ | </code> | ||
- | ----- | + | FIXME : Non testé : à vérifier si ça marche bien :p |
- | <box 100% right|100% right> | + | <note tips>Vous pouvez modifier le libellé par défaut associé à chaque événement dans le fichier upsmon.conf : |
- | <box 25% round left>25% round left</box> | + | <file> |
- | <box 25% round left>25% round left</box> | + | NOTIFYMSG ONLINE "UPS %s sur secteur." |
- | <box 25% round left>25% round left</box> | + | NOTIFYMSG ONBATT "UPS %s sur batterie." |
- | <box 25% round left>25% round left</box> | + | NOTIFYMSG LOWBATT "UPS %s batterie faible." |
- | </box> | + | NOTIFYMSG FSD "UPS %s: arrêt forcé en cours." |
+ | NOTIFYMSG COMMOK "Communications avec l'UPS %s établie." | ||
+ | NOTIFYMSG COMMBAD "Communications avec l'UPS %s perdue." | ||
+ | NOTIFYMSG SHUTDOWN "Déconnexion et arrêt automatiques engagés." | ||
+ | NOTIFYMSG REPLBATT "UPS %s La batterie doit être remplacée." | ||
+ | NOTIFYMSG NOCOMM "UPS %s indisponible." | ||
+ | NOTIFYMSG NOPARENT "mort du processus upsmon parent - arrêt impossible" | ||
+ | </file></note> | ||
- | <box 100% center|100% center> | + | === Utilisation de upssched === |
- | <box 25% round left>25% round left</box> | + | |
- | <box 25% round left>25% round left</box> | + | |
- | <box 25% round left>25% round left</box> | + | |
- | <box 25% round left>25% round left</box> | + | |
- | </box> | + | |
- | <box 100% left|100% left> | + | Si vous souhaitez effectuer des actions différentes selon le type d'événement, il est préférable d'utiliser upssched. |
- | <box 25% round left>25% round left</box> | + | |
- | <box 25% round left>25% round left</box> | + | |
- | <box 25% round left>25% round left</box> | + | |
- | <box 25% round left>25% round left</box> | + | |
- | </box> | + | |
- | <box 100% round left|100% round left> | + | fichier upsmon.conf (exemple) : |
- | <box 25% round left>25% round left</box> | + | |
- | <box 25% round left>25% round left</box> | + | |
- | <box 25% round left>25% round left</box> | + | |
- | <box 25% round left>25% round left</box> | + | |
- | </box> | + | |
- | <box 100% left|100% left> | + | <file> |
- | <box 25% left>25% left</box> | + | NOTIFYCMD /sbin/upssched |
- | <box 25% left>25% left</box> | + | |
- | <box 25% left>25% left</box> | + | |
- | <box 25% left>25% left</box> | + | |
- | </box> | + | |
- | <box 100% left> | + | NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC |
- | ------- | + | NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC |
- | </box> | + | NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC |
+ | NOTIFYFLAG FSD SYSLOG+WALL+EXEC | ||
+ | NOTIFYFLAG COMMOK SYSLOG+EXEC | ||
+ | NOTIFYFLAG COMMBAD SYSLOG+EXEC | ||
+ | NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC | ||
+ | NOTIFYFLAG REPLBATT SYSLOG+WALL+EXEC | ||
+ | NOTIFYFLAG NOCOMM SYSLOG+WALL+EXEC | ||
+ | NOTIFYFLAG NOPARENT SYSLOG+WALL+EXEC | ||
+ | </file> | ||
- | %% | + | Créer le fichier de config /etc/nut/upssched.conf |
- | <box 75% left|75% left> | + | <file> |
- | <box 25% left>25% left</box> | + | # the script to be executed |
- | <box 25% left>25% left</box> | + | CMDSCRIPT /usr/local/bin/upsalert.sh |
- | <box 25% left>25% left</box> | + | |
- | <box 25% left>25% left</box> | + | |
- | </box> | + | |
- | %% | + | |
- | <box 100% left> | + | # mandatory fields that must be set before AT commands |
- | ------- | + | PIPEFN /var/run/nut/upssched.pipe |
- | </box> | + | LOCKFN /var/run/nut/upssched.lock |
+ | # the timers, here 30 sec after the ONBATT (ups on battery) event | ||
+ | AT ONBATT * START-TIMER onbatt-timer 120 | ||
+ | # cancel the countdown is power is back | ||
+ | AT ONLINE * CANCEL-TIMER onbatt-timer | ||
- | <box 100% left|100% left> | + | AT COMMBAD * EXECUTE commbad |
- | <box 25% round left>25% round left</box> | + | AT COMMOK * EXECUTE commok |
- | <box 25% round left>25% round left</box> | + | AT NOCOMM * EXECUTE nocomm |
- | <box 25% round left>25% round left</box> | + | AT ONBATT * EXECUTE onbatt |
- | <box 25% round left>25% round left</box> | + | AT LOWBATT * EXECUTE lowbatt |
- | </box> | + | AT ONLINE * EXECUTE online |
+ | AT FSD * EXECUTE fsd | ||
+ | AT SHUTDOWN * EXECUTE shutdown | ||
+ | AT REPLBATT * EXECUTE replbatt | ||
+ | AT NOPARENT * EXECUTE noparent | ||
+ | </file> | ||
- | ==== Taille N box horizontales ==== | + | Créer le script /usr/local/bin/upsalert.sh (FIXME exemple à revoir) |
+ | <file> | ||
+ | #!/bin/bash | ||
+ | logfile=/var/log/ups.log | ||
+ | date=$(date +"%F %T") | ||
- | <note>Valeurs pour résolution 1680x1050\\ Si fenêtre redimensionnée, ne fonctionne plus !</note> | + | case $1 in |
+ | commbad) | ||
+ | echo "$date : UPS communications failure." >> $logfile | ||
+ | ;; | ||
+ | commok) | ||
+ | echo "$date : UPS communications restored." >> $logfile | ||
+ | echo "$date : Current status=[$(/bin/upsc localups ups.status)], Charge=$(/bin/upsc localups battery.charge)%, Load=$(/bin/upsc localups ups.load)%." >> $logfile | ||
+ | sudo /bin/upscmd -u login -p pwd localups beeper.enable 2>> $logfile | ||
+ | ;; | ||
+ | nocomm) | ||
+ | echo "$date : UPS communications cannot be established." >> $logfile | ||
+ | ;; | ||
+ | onbatt) | ||
+ | echo "$date : UPS is on battery. Trying to suspend." >> $logfile | ||
+ | echo "$date : Current status=[$(/bin/upsc localups ups.status)], Charge=$(/bin/upsc localups battery.charge)%, Load=$(/bin/upsc localups ups.load)%." >> $logfile | ||
+ | sudo /bin/upscmd -u login -p pwd localups beeper.mute 120 2>> $logfile | ||
+ | sudo /usr/sbin/pm-suspend-hybrid --quirk-none 2>&1 >> $logfile | ||
+ | ;; | ||
+ | onbatt-timer) | ||
+ | echo "$date : UPS is on battery for more than 2 min. Trying to hibernate." >> $logfile | ||
+ | $echo "$date : Current status=[$(/bin/upsc localups ups.status)], Charge=$(/bin/upsc localups battery.charge)%, Load=$(/bin/upsc localups ups.load)%." >> $logfile | ||
+ | sudo /bin/upscmd -u login -p pwd localups beeper.mute 300 2>> $logfile | ||
+ | sudo /usr/sbin/pm-hibernate --quirk-none 2&>1 >>$logfile | ||
+ | ;; | ||
+ | lowbatt) | ||
+ | echo "$date : UPS has a low battery. Current load=$(/bin/upsc localups ups.status)%. Trying forced-shutdown." >> $logfile | ||
+ | echo "$date : Current status=[$(/bin/upsc localups ups.status)], Charge=$(/bin/upsc localups battery.charge)%, Load=$(/bin/upsc localups ups.load)%." >> $logfile | ||
+ | sleep 1 | ||
+ | sudo /bin/upscmd -u login -p pwd localups beeper.enable 2>> $logfile | ||
+ | sudo /sbin/upsmon -c fsd 2>&1 >> $logfile | ||
+ | ;; | ||
+ | online) | ||
+ | echo "$date : UPS on line. Shutdown aborted." >> $logfile | ||
+ | echo "$date : Current status=[$(/bin/upsc localups ups.status)], Charge=$(/bin/upsc localups battery.charge)%, Load=$(/bin/upsc localups ups.load)%." >> $logfile | ||
+ | sudo /bin/upscmd -u login -p pwd localups shutdown.stop | ||
+ | sleep 1 | ||
+ | sudo /sbin/upsmon -K && echo "$date : WARN : fsd flag is still on !" >> $logfile | ||
+ | sudo /bin/upscmd -u login -p pwd localups beeper.enable 2>$logfile | ||
+ | ;; | ||
+ | fsd) | ||
+ | echo "$date : UPS is being forced-shutdown by the master." >> $logfile | ||
+ | echo "$date : Current status=[$(/bin/upsc localups ups.status)], Charge=$(/bin/upsc localups battery.charge)%, Load=$(/bin/upsc localups ups.load)%." >> $logfile | ||
+ | sleep 1 | ||
+ | sudo /bin/upscmd -u login -p pwd localups beeper.mute 300 2>> $logfile | ||
+ | ;; | ||
+ | shutdown) | ||
+ | echo "$date : The system is being shutdown." >> $logfile | ||
+ | echo "$date : Current status=[$(/bin/upsc localups ups.status)], Charge=$(/bin/upsc localups battery.charge)%, Load=$(/bin/upsc localups ups.load)%." >> $logfile | ||
+ | sudo /bin/upscmd -u login -p pwd localups beeper.mute 300 2>> $logfile | ||
+ | ;; | ||
+ | replbatt) | ||
+ | echo "$date : UPS battery is bad and needs to be replaced !!!" >> $logfile | ||
+ | echo "$date : Current status=[$(/bin/upsc localups ups.status)], Charge=$(/bin/upsc localups battery.charge)%, Load=$(/bin/upsc localups ups.load)%." >> $logfile | ||
+ | sudo /bin/upscmd -u login -p pwd localups beeper.enable 2>> $logfile | ||
+ | ;; | ||
+ | noparent) | ||
+ | echo "$date : The process that shuts down the system has died (shutdown impossible)." >> $logfile | ||
+ | sudo /sbin/shutdown -h now 2>&1 >> $logfile | ||
+ | ;; | ||
+ | *) | ||
+ | echo "$date : $0 > Unrecognized command: $1" | tee -a $logfile 1>&2 | ||
+ | echo "$date : Current status=[$(/bin/upsc localups ups.status)], Charge=$(/bin/upsc localups battery.charge)%, Load=$(/bin/upsc localups ups.load)%." >> $logfile | ||
+ | ;; | ||
+ | esac | ||
+ | exit 0 | ||
+ | </file> | ||
- | * 1 box horizontale | + | ====== Réduire le nombre d'écriture sur disque pour les log et sauver la vie du SSD Ryan ====== |
- | <box 100% center|100% center> | + | - Créer un dossier pour les log permanentes : sudo mkdir -p /var/log.hdd/ |
- | <box 100% round left>100% left</box> | + | - Modifier le fichier de config de /etc/logrotate.conf et ajouter la ligne ''olddir /var/log.hdd/'' : |
- | </box> | + | <file> |
+ | # see "man logrotate" for details | ||
+ | # rotate log files weekly | ||
+ | weekly | ||
- | * 2 box horizontales | + | # keep 4 weeks worth of backlogs |
+ | rotate 4 | ||
- | <box 100% center|100% center> | + | # create new (empty) log files after rotating old ones |
- | <box 48% round left>48% left</box> | + | create |
- | <box 48% round left>48% left</box> | + | |
- | </box> | + | |
- | <box 100% center|100% center> | + | # uncomment this if you want your log files compressed |
- | <box 48% round center>48% center</box> | + | #compress |
- | <box 48% round center>48% center</box> | + | |
- | </box> | + | |
- | <box 100% center|100% center> | + | olddir /var/log.hdd/ |
- | <box 48% round right>48% right</box> | + | |
- | <box 48% round right>48% right</box> | + | |
- | </box> | + | |
- | <box 100% center|100% center> | + | # packages drop log rotation information into this directory |
- | <box 48% round left>48% left</box> | + | include /etc/logrotate.d |
- | <box 48% round right>48% right</box> | + | |
- | </box> | + | |
- | * 3 box horizontales | + | # no packages own wtmp, or btmp -- we'll rotate them here |
+ | /var/log/wtmp { | ||
+ | missingok | ||
+ | monthly | ||
+ | create 0664 root utmp | ||
+ | rotate 1 | ||
+ | } | ||
- | <box 100% center|100% center> | + | /var/log/btmp { |
- | <box 32% round left>32% left</box> | + | missingok |
- | <box 32% round left>32% left</box> | + | monthly |
- | <box 32% round left>32% left</box> | + | create 0660 root utmp |
- | </box> | + | rotate 1 |
+ | } | ||
- | <box 100% center|100% center> | + | # system-specific logs may be configured here |
- | <box 32% round center>32% center</box> | + | </file> |
- | <box 32% round center>32% center</box> | + | - Modifier /etc/fstab pour charge /var/log sur un tmpfs : |
- | <box 32% round center>32% center</box> | + | <file> |
- | </box> | + | # dossier en RAM (volatile) |
+ | tmpfs /tmp tmpfs defaults 0 0 | ||
+ | tmpfs /var/tmp tmpfs defaults 0 0 | ||
+ | tmpfs /var/lock tmpfs defaults 0 0 | ||
+ | tmpfs /var/log tmpfs defaults 0 0 | ||
+ | </file> | ||
- | <box 100% center|100% center> | + | <note important>Il est possible de s'arrêter là, si le système est rarement rebooté, et que l'on accepte de perdre les logs depuis la dernière rotation</note> |
- | <box 32% round right>32% right</box> | + | |
- | <box 32% round right>32% right</box> | + | |
- | <box 32% round right>32% right</box> | + | |
- | </box> | + | |
- | <box 100% center|100% center> | + | === Mod easy === |
- | <box 32% round left>32% left **1**</box> | + | |
- | <box 32% round right>32% right **2**</box> | + | |
- | <box 32% round center>32% center **3**</box> | + | |
- | </box> | + | |
- | * 4 box horizontales | + | <note tip>FIXME devrait bien marcher pour systèmes avec peu de reboot, et permet de ne perdre aucun log !!</note> |
- | <box 100% center|100% center> | + | - FIXME Créer un script dans /etc/init.d/ qui appele logrotate en mode forcé pour recopier les log dans /var/log.hdd si appelé avec ''stop'' |
- | <box 23% round left>23% left 1</box> | + | <code>#!/bin/sh |
- | <box 23% round left>23% left 2</box> | + | case "$1" in |
- | <box 23% round left>23% left 3</box> | + | stop) |
- | <box 23% round left>23% left 4</box> | + | logrotate -f /etc/logrotate.conf |
- | </box> | + | ;; |
+ | *) | ||
+ | #no-op | ||
+ | ;; | ||
+ | esac | ||
+ | exit 0 | ||
+ | </code> | ||
+ | - Lier le script dans /etc/rc0.d/S39savelogs | ||
- | <box 100% center|100% center> | + | > Le mieux serait de faire un service qui écoute le bon événement et ferait la manip juste avant le démontage (S40umountfs). |
- | <box 23% round left>23% left 1</box> | + | |
- | <box 23% round left>23% left 2</box> | + | |
- | <box 23% round right>23% right 3</box> | + | |
- | <box 23% round right>23% right 4</box> | + | |
- | </box> | + | |
- | <box 100% center|100% center> | + | <note warning>Cela ne respecte pas les règles logrotate (daily, weekly ...) donc risque de perdre rapidement des données si peu de génération sont conservées pour un fichier donné !</note> |
- | <box 23% round left>23% left 1</box> | + | |
- | <box 23% round right>23% right 2</box> | + | |
- | <box 23% round center>23% center 3</box> | + | |
- | <box 23% round center>23% center 4</box> | + | |
- | </box> | + | |
+ | === Mod avancé === | ||
+ | - FIXME Créer un script dans /etc/init.d qui fait : | ||
+ | * en stop : copie des fichiers de /var/log vers /var/log.hdd && umount de /var/log && création des liens symboliques avec le même nom que les fichiers copiés de /var/log vers /var/log.hdd (ou lien symbolique des dossiers directement) FIXME utiliser le contenu de /var/lib/logrotate/status ? (cf. /etc/cron.daily/logrotate ) | ||
+ | * en start (juste après mount), copier les log de /var/log/ à la suite des fichiers existant puis écrasement des fichiers de /var/log/ par ceux de /var/log.hdd | ||
- | + | <note warning>FIXME besoin de créer 2 liens symbolique différents : nécessité de tester le nom d'appel pour vérifier si Start ou Stop && avant/après mount/umount. start + après mount = OK ; stop + avant umount = OK ; sinon ne rien faire.</note> | |
- | Texte ... | + |