From c46e18b8b5b16ca2ede06013543f0831712dd85d Mon Sep 17 00:00:00 2001 From: xavye Date: Wed, 14 Jan 2026 13:03:22 +0000 Subject: [PATCH] Actualiser automated_shutdown/read.me --- automated_shutdown/read.me | 87 +++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/automated_shutdown/read.me b/automated_shutdown/read.me index 1c21288..86ec8e9 100644 --- a/automated_shutdown/read.me +++ b/automated_shutdown/read.me @@ -1,2 +1,87 @@ An automated shutdown solution based on the detection of a prolonged ethernet connection loss. -This is because AscoetPi is connection to the router through a switch which is programmed to shutdown at night. \ No newline at end of file +This is because AscoetPi is connection to the router through a switch which is programmed to shutdown at night. + +Crée un fichier /etc/systemd/system/eth-monitor.service : + +sudo nano /etc/systemd/system/eth-monitor.service + +Colle ce contenu : + +[Unit] +Description=Ethernet Connection Monitor +After=network.target + +[Service] +Type=simple +ExecStart=/usr/local/bin/check_eth_connection.sh +Restart=on-failure +RestartSec=60 +TimeoutStopSec=5 + +[Install] +WantedBy=multi-user.target + + +c. Créer le timer systemd pour déclencher l’extinction +Crée un fichier /etc/systemd/system/eth-monitor.timer : + +sudo nano /etc/systemd/system/eth-monitor.timer + +Colle ce contenu : + +[Unit] +Description=Timer for Ethernet Connection Monitor + +[Timer] +OnBootSec=5min +OnUnitActiveSec=1min +AccuracySec=1s + +[Install] +WantedBy=timers.target + + +d. Créer un service pour éteindre après 5 minutes de panne +Crée un fichier /etc/systemd/system/shutdown-on-eth-fail.service : + +sudo nano /etc/systemd/system/shutdown-on-eth-fail.service + +Colle ce contenu : + +[Unit] +Description=Shutdown on Ethernet Failure +After=eth-monitor.service + +[Service] +Type=oneshot +ExecStart=/bin/sh -c 'if [ $(journalctl -u eth-monitor.service --since "5 minutes ago" | grep -c "is down") -ge 5 ]; then /sbin/shutdown -h now; fi' + +[Install] +WantedBy=multi-user.target + + +e. Activer et démarrer les services + +sudo systemctl daemon-reload +sudo systemctl enable eth-monitor.service +sudo systemctl enable eth-monitor.timer +sudo systemctl enable shutdown-on-eth-fail.service +sudo systemctl start eth-monitor.timer +sudo systemctl start eth-monitor.service + + +2. Vérifier le bon fonctionnement + +Consulte les logs : + + +journalctl -u eth-monitor.service -f + + +Teste en débranchant le câble Ethernet et attends 5 minutes. + +3. Explications + +eth-monitor.service : Vérifie l’état de l’interface Ethernet toutes les minutes. +eth-monitor.timer : Déclenche la vérification régulièrement. +shutdown-on-eth-fail.service : Compte le nombre de pannes sur les 5 dernières minutes et éteint si nécessaire. \ No newline at end of file