Ajouter les fichiers manquants (unités systemd, hooks DHCP) et corriger install-pve-netconfig.sh
- Les fichiers pve-netconfig.service, pve-netconfig-watch.service, pve-netconfig.timer, dhclient-hook et dhcpcd-hook n'avaient jamais ete ajoutes au depot git : un git clone frais ne les contenait pas, ce qui faisait echouer install-pve-netconfig.sh (install: cannot stat ...). - install-pve-netconfig.sh applique desormais automatiquement la configuration DHCP (apply-interfaces + check + demarrage des services) au lieu de se limiter a des instructions manuelles, avec une option SKIP_AUTO_APPLY=1 pour desactiver ce comportement. - Bit executable ajoute sur install-pve-netconfig.sh, dhclient-hook et dhcpcd-hook. - README.md mis a jour avec l'URL reelle du depot (https://git.sdeinfo.app/sde/pvedhcp.git) et le nouveau comportement automatique. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,3 +1,34 @@
|
|||||||
# pvedhcp
|
# pvedhcp
|
||||||
|
|
||||||
Configuration du DHCP sur un serveur Proxmox 9
|
Configuration du DHCP sur un serveur Proxmox 9
|
||||||
|
|
||||||
|
## Utilisation
|
||||||
|
|
||||||
|
Sur un hôte Proxmox VE 9 (Debian 13 "trixie") fraîchement installé, en root :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://git.sdeinfo.app/sde/pvedhcp.git
|
||||||
|
cd pvedhcp
|
||||||
|
chmod +x install-pve-netconfig.sh
|
||||||
|
./install-pve-netconfig.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Le script installe les dépendances (`jq`, `iproute2`, un client DHCP si
|
||||||
|
nécessaire), copie les scripts et unités systemd, installe les hooks DHCP,
|
||||||
|
**puis active automatiquement le DHCP** sur `vmbr0`/`vmbr1` (génération de
|
||||||
|
`/etc/network/interfaces`, tentative de bail DHCP avec bascule automatique
|
||||||
|
sur une IP statique de secours en cas d'échec, démarrage des services de
|
||||||
|
surveillance).
|
||||||
|
|
||||||
|
⚠️ Une rupture réseau temporaire est possible pendant l'application de la
|
||||||
|
configuration : prévoir un accès console (iDRAC/IPMI/KVM) par précaution.
|
||||||
|
|
||||||
|
Pour ne pas appliquer automatiquement la configuration réseau (installation
|
||||||
|
des fichiers uniquement, activation manuelle ensuite) :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
SKIP_AUTO_APPLY=1 ./install-pve-netconfig.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Personnalisation (IP de secours, ports réseau, DNS...) : éditer
|
||||||
|
`/usr/local/sbin/pve-netconfig.sh` puis relancer `pve-netconfig.sh apply-interfaces`.
|
||||||
Executable
+24
@@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#===============================================================================
|
||||||
|
# Hook de sortie dhclient (isc-dhcp-client).
|
||||||
|
# Installe dans /etc/dhcp/dhclient-exit-hooks.d/pve-netconfig
|
||||||
|
#
|
||||||
|
# Declenche a chaque evenement du client DHCP (BOUND, RENEW, REBIND, EXPIRE...).
|
||||||
|
# Sur obtention/renouvellement de bail : synchronise /etc/hosts et leve un
|
||||||
|
# eventuel fallback statique. dhclient exporte $interface et $reason.
|
||||||
|
#===============================================================================
|
||||||
|
|
||||||
|
SCRIPT="/usr/local/sbin/pve-netconfig.sh"
|
||||||
|
|
||||||
|
[[ -x "$SCRIPT" ]] || exit 0
|
||||||
|
|
||||||
|
case "${reason:-}" in
|
||||||
|
BOUND|RENEW|REBIND|REBOOT|STATIC)
|
||||||
|
"$SCRIPT" sync-hosts >/dev/null 2>&1 &
|
||||||
|
;;
|
||||||
|
EXPIRE|NOCARRIER|FAIL)
|
||||||
|
"$SCRIPT" check >/dev/null 2>&1 &
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
Executable
+19
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#===============================================================================
|
||||||
|
# Hook dhcpcd.
|
||||||
|
# Installe dans /usr/lib/dhcpcd/dhcpcd-hooks/90-pve-netconfig
|
||||||
|
#
|
||||||
|
# dhcpcd execute ce hook avec les fonctions/variables $interface et $reason
|
||||||
|
# deja en environnement (BOUND, RENEW, REBIND, ...). On se contente de
|
||||||
|
# resynchroniser /etc/hosts et de lever un eventuel fallback statique.
|
||||||
|
#===============================================================================
|
||||||
|
|
||||||
|
SCRIPT="/usr/local/sbin/pve-netconfig.sh"
|
||||||
|
|
||||||
|
[[ -x "$SCRIPT" ]] || return 0 2>/dev/null || exit 0
|
||||||
|
|
||||||
|
case "${reason:-}" in
|
||||||
|
BOUND|RENEW|REBIND|REBOOT)
|
||||||
|
"$SCRIPT" check >/dev/null 2>&1 &
|
||||||
|
;;
|
||||||
|
esac
|
||||||
Regular → Executable
+33
-18
@@ -58,35 +58,50 @@ systemctl enable pve-netconfig.service
|
|||||||
systemctl enable pve-netconfig.timer
|
systemctl enable pve-netconfig.timer
|
||||||
systemctl enable pve-netconfig-watch.service
|
systemctl enable pve-netconfig-watch.service
|
||||||
|
|
||||||
cat <<'EOF'
|
# --- Activation automatique du DHCP -----------------------------------------
|
||||||
|
# But du script : qu'un simple "git clone + ./install-pve-netconfig.sh" suffise
|
||||||
|
# à activer le DHCP. On applique donc la configuration réseau et on démarre
|
||||||
|
# les services immédiatement, sauf si l'utilisateur désactive ce comportement.
|
||||||
|
SKIP_AUTO_APPLY="${SKIP_AUTO_APPLY:-0}"
|
||||||
|
|
||||||
|
if [[ "$SKIP_AUTO_APPLY" != "1" ]]; then
|
||||||
|
echo "==> Génération de /etc/network/interfaces (DHCP)"
|
||||||
|
/usr/local/sbin/pve-netconfig.sh apply-interfaces || \
|
||||||
|
echo "AVERTISSEMENT : apply-interfaces a échoué, voir les messages ci-dessus." >&2
|
||||||
|
|
||||||
|
echo "==> Premier contrôle DHCP / fallback"
|
||||||
|
/usr/local/sbin/pve-netconfig.sh check || \
|
||||||
|
echo "AVERTISSEMENT : le contrôle initial a échoué, voir les messages ci-dessus." >&2
|
||||||
|
|
||||||
|
echo "==> Démarrage des services"
|
||||||
|
systemctl start pve-netconfig.timer
|
||||||
|
systemctl start pve-netconfig-watch.service
|
||||||
|
|
||||||
|
/usr/local/sbin/pve-netconfig.sh status || true
|
||||||
|
else
|
||||||
|
echo "==> SKIP_AUTO_APPLY=1 : application automatique ignorée (mode manuel)."
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
Installation terminée.
|
Installation terminée. Le DHCP a été activé automatiquement sur ${BRIDGE_MAIN:-vmbr0} / ${BRIDGE_SECONDARY:-vmbr1}.
|
||||||
|
|
||||||
ÉTAPES SUIVANTES (à faire manuellement) :
|
Pour personnaliser la configuration (IP de secours, ports, DNS...) :
|
||||||
|
|
||||||
1. Éditer la section CONFIGURATION du script :
|
|
||||||
nano /usr/local/sbin/pve-netconfig.sh
|
nano /usr/local/sbin/pve-netconfig.sh
|
||||||
-> FALLBACK_IP, FALLBACK_CIDR, FALLBACK_GATEWAY, FALLBACK_DNS
|
-> FALLBACK_IP, FALLBACK_CIDR, FALLBACK_GATEWAY, FALLBACK_DNS
|
||||||
-> PORT_MAIN / PORT_SECONDARY si la détection automatique échoue
|
-> PORT_MAIN / PORT_SECONDARY si la détection automatique échoue
|
||||||
|
Puis réappliquer :
|
||||||
2. Vérifier la détection des ports :
|
|
||||||
pve-netconfig.sh status
|
|
||||||
ip -br link
|
|
||||||
|
|
||||||
3. Générer /etc/network/interfaces :
|
|
||||||
pve-netconfig.sh apply-interfaces
|
pve-netconfig.sh apply-interfaces
|
||||||
ATTENTION : rupture réseau possible. Prévoir un accès console (iDRAC/IPMI/KVM).
|
|
||||||
|
|
||||||
4. Lancer un premier contrôle complet :
|
|
||||||
pve-netconfig.sh check
|
pve-netconfig.sh check
|
||||||
|
|
||||||
|
Vérifier l'état à tout moment :
|
||||||
pve-netconfig.sh status
|
pve-netconfig.sh status
|
||||||
|
|
||||||
5. Démarrer les services :
|
Astuce : pour ignorer l'application automatique lors de l'installation,
|
||||||
systemctl start pve-netconfig.timer
|
relancer avec : SKIP_AUTO_APPLY=1 ./install-pve-netconfig.sh
|
||||||
systemctl start pve-netconfig-watch.service
|
|
||||||
|
|
||||||
6. Redémarrer pour valider le comportement au boot :
|
Il est recommandé de redémarrer pour valider le comportement au boot :
|
||||||
reboot
|
reboot
|
||||||
===============================================================================
|
===============================================================================
|
||||||
EOF
|
EOF
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Surveillance des changements d'adresse IP (netlink) pour Proxmox
|
||||||
|
After=network.target pve-netconfig.service
|
||||||
|
Wants=pve-netconfig.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/local/sbin/pve-netconfig-watch.sh
|
||||||
|
Restart=always
|
||||||
|
RestartSec=10
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Proxmox : configuration DHCP/fallback et synchronisation /etc/hosts
|
||||||
|
Documentation=file:/usr/local/sbin/pve-netconfig.sh
|
||||||
|
After=network-online.target networking.service
|
||||||
|
Wants=network-online.target
|
||||||
|
# Doit tourner AVANT que les services PVE ne lisent /etc/hosts
|
||||||
|
Before=pve-guests.service pveproxy.service pvedaemon.service pve-cluster.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
RemainAfterExit=yes
|
||||||
|
ExecStart=/usr/local/sbin/pve-netconfig.sh check
|
||||||
|
TimeoutStartSec=120
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Vérification périodique DHCP/fallback Proxmox
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnBootSec=2min
|
||||||
|
OnUnitActiveSec=5min
|
||||||
|
AccuracySec=30s
|
||||||
|
Unit=pve-netconfig.service
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
Reference in New Issue
Block a user