From 6f70da56a640f43d2a6beb36eba9f7f05b8ee14f Mon Sep 17 00:00:00 2001 From: jeanotx32 Date: Tue, 11 Aug 2026 18:41:19 +0200 Subject: [PATCH] Fix : Deploy bug --- DEPLOY.md | 6 +++--- README.md | 4 ++-- deploy/install-agent.ps1 | 2 +- deploy/install-agent.sh | 11 ++++++++--- packages/agent/src/index.ts | 13 ++++++++++++- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/DEPLOY.md b/DEPLOY.md index 8e6e119..0e1e86e 100644 --- a/DEPLOY.md +++ b/DEPLOY.md @@ -7,7 +7,7 @@ commande, les artefacts construits et publiés par Gitea Actions. ┌──────────────────────────┐ ┌───────────────────────────────┐ │ Gitea │ │ Machine du plan de contrôle │ │ ├─ registre d'images ───┼───────►│ docker compose up -d │ -│ └─ paquets génériques │ │ → http://control.lan:8080 │ +│ └─ paquets génériques │ │ → http://:8080 │ │ │ agent.cjs │ └───────────────┬───────────────┘ └─────────┼────────────────┘ │ ws:// (réseau privé) │ install-agent.sh/.ps1 ┌──────────┴──────────┐ @@ -144,7 +144,7 @@ persiste. curl -fsSL https://git.jeanbonapp.com/api/packages/jeanbon/generic/stream-control-agent/latest/install-agent.sh \ | sudo bash -s -- \ --registry https://git.jeanbonapp.com \ - --server ws://control.lan:8080/ws/agent \ + --server ws://:8080/ws/agent \ --token \ --name vm-rec-01 \ --obs-password @@ -163,7 +163,7 @@ Dans un PowerShell **administrateur**, sur le compte qui lance OBS : ```powershell & ([scriptblock]::Create((irm 'https://git.jeanbonapp.com/api/packages/jeanbon/generic/stream-control-agent/latest/install-agent.ps1'))) ` -Registry 'https://git.jeanbonapp.com' ` - -Server 'ws://control.lan:8080/ws/agent' ` + -Server 'ws://:8080/ws/agent' ` -Token '' ` -Name 'vm-rec-02' ` -ObsPassword '' diff --git a/README.md b/README.md index c058f4f..ced6ce7 100644 --- a/README.md +++ b/README.md @@ -70,11 +70,11 @@ docker compose up -d # Agent Ubuntu curl -fsSL /api/packages/jeanbon/generic/stream-control-agent/latest/install-agent.sh \ - | sudo bash -s -- --registry --server ws://control.lan:8080/ws/agent --token + | sudo bash -s -- --registry --server ws://:8080/ws/agent --token # Agent Windows (PowerShell administrateur) & ([scriptblock]::Create((irm '/api/packages/jeanbon/generic/stream-control-agent/latest/install-agent.ps1'))) ` - -Registry '' -Server 'ws://control.lan:8080/ws/agent' -Token '' + -Registry '' -Server 'ws://:8080/ws/agent' -Token '' ``` Les agents ne sont volontairement pas conteneurisés : ils doivent voir l'OBS local et la diff --git a/deploy/install-agent.ps1 b/deploy/install-agent.ps1 index 290f5b8..6eaff14 100644 --- a/deploy/install-agent.ps1 +++ b/deploy/install-agent.ps1 @@ -13,7 +13,7 @@ .EXAMPLE & ([scriptblock]::Create((irm 'https://git.jeanbonapp.com/api/packages/jeanbon/generic/stream-control-agent/latest/install-agent.ps1'))) ` -Registry 'https://git.jeanbonapp.com' ` - -Server 'ws://control.lan:8080/ws/agent' ` + -Server 'ws://:8080/ws/agent' ` -Token '' #> diff --git a/deploy/install-agent.sh b/deploy/install-agent.sh index e6845cb..62e7828 100644 --- a/deploy/install-agent.sh +++ b/deploy/install-agent.sh @@ -5,7 +5,7 @@ # curl -fsSL https://git.jeanbonapp.com/api/packages/jeanbon/generic/stream-control-agent/latest/install-agent.sh \ # | sudo bash -s -- \ # --registry https://git.jeanbonapp.com \ -# --server ws://control.lan:8080/ws/agent \ +# --server ws://:8080/ws/agent \ # --token # # Réexécuter le script met à jour le binaire sans toucher à l'identité d'un @@ -40,7 +40,7 @@ Installe (ou met à jour) l'agent Stream Control sur une VM Linux. curl -fsSL https://git.jeanbonapp.com/api/packages/jeanbon/generic/stream-control-agent/latest/install-agent.sh \ | sudo bash -s -- \ --registry https://git.jeanbonapp.com \ - --server ws://control.lan:8080/ws/agent \ + --server ws://:8080/ws/agent \ --token Réexécuter le script met à jour le binaire sans toucher à l'identité d'un agent @@ -215,7 +215,12 @@ systemctl restart "$SERVICE" # --- Vérification ----------------------------------------------------------- echo -sudo -u "$RUN_USER" AGENT_CONFIG="$CONFIG_FILE" \ +# Mêmes variables que l'unité systemd, sinon le diagnostic signale un DISPLAY +# absent que le service, lui, aura bien. +sudo -u "$RUN_USER" \ + AGENT_CONFIG="$CONFIG_FILE" \ + DISPLAY=":0" \ + XAUTHORITY="$USER_HOME/.Xauthority" \ "$(command -v node)" "$INSTALL_DIR/agent.cjs" --check || true sleep 2 diff --git a/packages/agent/src/index.ts b/packages/agent/src/index.ts index 4ce04bd..3c6bfdd 100644 --- a/packages/agent/src/index.ts +++ b/packages/agent/src/index.ts @@ -49,6 +49,7 @@ const watcher = new StreamWatcher(DEFAULT_WATCH_SETTINGS, { let socket: WebSocket | null = null; let statusTimer: NodeJS.Timeout | null = null; +let reconnectTimer: NodeJS.Timeout | null = null; let reconnectDelay = RECONNECT_MIN_MS; let statusIntervalMs = 2000; let shuttingDown = false; @@ -117,7 +118,15 @@ function connect(): void { function scheduleReconnect(): void { const delay = reconnectDelay; reconnectDelay = Math.min(reconnectDelay * 2, RECONNECT_MAX_MS); - setTimeout(connect, delay).unref?.(); + + // Surtout pas de .unref() ici : pendant une coupure, ce minuteur est la seule + // chose qui maintienne la boucle d'évènements en vie. Déréférencé, le process + // sortirait avec le code 0 au lieu de retenter — la reconnexion ne servirait + // jamais. On garde plutôt la référence pour l'annuler à l'arrêt. + reconnectTimer = setTimeout(() => { + reconnectTimer = null; + connect(); + }, delay); } // --- Traitement des messages serveur ---------------------------------------- @@ -243,6 +252,8 @@ async function shutdown(signal: string): Promise { shuttingDown = true; console.log(`\n${signal} reçu, arrêt de l'agent…`); stopStatusLoop(); + if (reconnectTimer) clearTimeout(reconnectTimer); + reconnectTimer = null; watcher.stop(); // L'enregistrement OBS en cours n'est volontairement pas interrompu. await obs.disconnect().catch(() => undefined);