diff --git a/webhook.cjs b/webhook.cjs index b383f72..e72d4fc 100644 --- a/webhook.cjs +++ b/webhook.cjs @@ -45,6 +45,9 @@ const RESTART_TARGETS = (process.env.PM2_RESTART_TARGETS || 'tssbot-web,tssbot-b .map((target) => target.trim()) .filter((target) => /^[A-Za-z0-9_.:-]{1,80}$/.test(target)) .filter(Boolean) + +// This webhook's own PM2 process name — never reload it during its own deploy. +const SELF_PM2_NAME = process.env.WEBHOOK_PM2_NAME || 'tssbot-webhook' const DIST_DIR = path.join(__dirname, 'dist') const NEXT_DIST_DIR = path.join(__dirname, 'dist-next') const PREVIOUS_DIST_DIR = path.join(__dirname, 'dist-previous') @@ -563,14 +566,19 @@ async function deploy(push) { // Reload via the ecosystem file (not by bare name) with --only so each deploy // re-reads the committed env blocks (e.g. VEHICLE_* paths). `pm2 reload // --update-env` would only merge the CLI's process.env and ignore the file. - // --only excludes tssbot-webhook so the webhook never reloads itself mid-deploy. - await run('pm2', [ - 'reload', - 'ecosystem.config.cjs', - '--only', - RESTART_TARGETS.join(','), - '--update-env', - ]) + // Exclude this webhook process itself: reloading it here kills the process + // running this deploy mid-command, interrupting the remaining reloads. The + // webhook is reloaded separately when its own code changes. + const reloadTargets = RESTART_TARGETS.filter((t) => t !== SELF_PM2_NAME) + if (reloadTargets.length) { + await run('pm2', [ + 'reload', + 'ecosystem.config.cjs', + '--only', + reloadTargets.join(','), + '--update-env', + ]) + } await notifyDeployCompleted(push, diff) } catch (error) {