From f31aeb4f6efc6d70e4a56c6cf027d317433446e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Padez?= Date: Sun, 6 Sep 2026 11:00:19 +0100 Subject: [PATCH] a restarted process kept an environment the ecosystem file no longer had startProcess used 'pm2 start ' for a process PM2 already knew, which restarts it with the environment PM2 is holding and never re-reads the file. That was harmless while an entry was a script path and a cwd. It stopped being harmless the moment entries carried env. Seen once, immediately: a plugin's allocated port was re-drawn, the installer wrote PORT_SITE=34507 into ecosystem.config.cjs, the sidecar went on serving 3011, and nothing anywhere reported the disagreement. The file and the process simply disagreed, silently, which is the exact failure the port mechanism was supposed to remove rather than introduce. Now it restarts THROUGH the file - 'restart --only --update-env'. The file is re-read, and --update-env replaces the stored environment rather than merging into it, so a variable removed from an entry actually goes away. --- src/servers/app-store/pm2.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/servers/app-store/pm2.ts b/src/servers/app-store/pm2.ts index 8e6a7d67..b84a8d8f 100644 --- a/src/servers/app-store/pm2.ts +++ b/src/servers/app-store/pm2.ts @@ -59,7 +59,23 @@ export async function isKnownToPm2(name: string, cwd: string): Promise */ export async function startProcess(name: string, cwd: string): Promise { const known = await isKnownToPm2(name, cwd); - const args = known ? ['start', name] : ['start', ECOSYSTEM, '--only', name]; + /* + Through the ECOSYSTEM FILE either way, and that is the whole point of this line. + + `pm2 start ` restarts a known process with the environment PM2 already holds for it, and never + looks at the file again. That was fine while an entry was just a script path — it is not now that an + entry carries `env`, because a plugin whose allocated port changed would have its new number written + to the file and go on running with the old one. + + Seen exactly once, on the day ports were added: the ecosystem said PORT_SITE=34507, the process was + serving 3011, and nothing anywhere reported a disagreement. + + `restart --only ` re-reads the entry; `--update-env` makes PM2 replace the stored + environment rather than merge into it, so a variable REMOVED from the entry actually goes away. + */ + const args = known + ? ['restart', ECOSYSTEM, '--only', name, '--update-env'] + : ['start', ECOSYSTEM, '--only', name]; const { code, out } = await pm2(args, cwd); if (code !== 0) return { ok: false, error: out || `pm2 ${args.join(' ')} exited ${code}` };