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}` };