Actualiser automated_shutdown/setup.md

This commit is contained in:
2026-01-15 16:47:54 +00:00
parent 994963376c
commit 52f2613015

View File

@@ -0,0 +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.
Crée un fichier /etc/systemd/system/eth-monitor.service :
<code>sudo nano /etc/systemd/system/eth-monitor.service</code>
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 lextinction
Crée un fichier /etc/systemd/system/eth-monitor.timer :
<code>sudo nano /etc/systemd/system/eth-monitor.timer</code>
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 :
<code>sudo nano /etc/systemd/system/shutdown-on-eth-fail.service</code>
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 linterface 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.