tech:lecteur_reseau_toujours_monte_grace_a_systemd_et_a_un_watchdog
Table des matières
Lecteur réseau toujours monté grâce à SystemD et à un watchdog
Voir aussi
Tentative de création de montage CIFS avec chien de garde
/etc/systemd/system/mnt-plop.mount
[Unit] Description=Partage # PartOf=mnt-plop-watchdog.service # Requires=mnt-plop-watchdog.service # Requires demonte systematiquement le partage avant de le remonter à chaque frequence du watchdog. # Pour eviter ce pb nous utilisons Wants Wants=mnt-plop-watchdog.service [Mount] What=//127.0.0.1/shared Type=cifs Options=noexec,nosuid,nodev,rw,port=445,uid=66,gid=660,file_mode=0644,dir_mode=0755,noperm,credentials=/root/.cifs_plop Where=/mnt/plop # TimeoutSec semble ne pas avoir d effet # time ls -l /mnt/plop/ # ls: cannot access '/mnt/plop/': Host is down # real 0m10.183s TimeoutSec=10 ForceUnmount=yes DirectoryMode=755 [Install] WantedBy=remote-fs.target
/etc/systemd/system/mnt-plop-watchdog.service
[Unit] Description=Watch dog CIFS ConditionPathExists=/mnt/plop After=network.target # Wants=mnt-plop.mount # PartOf=mnt-plop.mount BindsTo=mnt-plop.mount # StartLimitIntervalSec=5s [Service] Type=simple Restart=always RestartSec=10 # Sleep est utilise car le mount depend du watchdog et le wathdog ne peut pas retourner OK si le montage n est pas actif # Pour contourner ce pb nous ajoutons un delai ExecStartPre=/usr/bin/sleep 5 ExecStart=mountpoint -q /mnt/plop [Install] WantedBy=remote-fs.target
chmod 644 /etc/systemd/system/mnt-plop.mount /etc/systemd/system/mnt-plop-watchdog.service
systemctl daemon-reload systemctl stop mnt-plop.mount mnt-plop-watchdog.service systemctl start mnt-plop.mount systemctl status mnt-plop.mount systemctl enable mnt-plop.mount systemctl status mnt-plop-watchdog.service journalctl -u mnt-plop.mount -u mnt-plop-watchdog.service -f
Le démarrage de l'Unit mnt-plop.mount démarrera automatiquement le chien de garde. L'arrêt de l'Unit mnt-plop.mount l'arrêtera automatiquement.
Cette solution fonctionne super bien, mais il y a bien plus simple
Solution (simple)
- Créer un Unit mount et un automount
- Dans automount
TimeoutIdleSec=0 - Activer et démarrer l'Unit mount et l'Unit automount
Exemple
/etc/systemd/system/mnt-plop.mount
[Unit] Description=Partage [Mount] What=//127.0.0.1/shared Type=cifs Options=noexec,nosuid,nodev,rw,port=445,uid=66,gid=660,file_mode=0644,dir_mode=0755,noperm,credentials=/root/.cifs_plop Where=/mnt/plop TimeoutSec=10 ForceUnmount=yes DirectoryMode=755 [Install] WantedBy=remote-fs.target
/etc/systemd/system/mnt-partage.automount
[Unit] Description=Automount Partage [Automount] Where=/mnt/plop TimeoutIdleSec=0 [Install] WantedBy=multi-user.target
chmod 644 /etc/systemd/system/mnt-plop.mount /etc/systemd/system/mnt-plop.automount systemctl daemon-reload systemctl enable --now mnt-plop.mount mnt-plop.automount
tech/lecteur_reseau_toujours_monte_grace_a_systemd_et_a_un_watchdog.txt · Dernière modification : de Jean-Baptiste
