diff --git a/infra/pm2/api.config.cjs b/infra/pm2/api.config.cjs index 3bc083f..ef33752 100644 --- a/infra/pm2/api.config.cjs +++ b/infra/pm2/api.config.cjs @@ -1,6 +1,16 @@ // PM2 processes for the API and the background worker. Environment comes from apps/api/.env (never written by deploys) // plus APP_VERSION set by infra/deploy/deploy.sh. const path = require("node:path"); +const fs = require("node:fs"); + +// Container-local override for exec_mode/instances, outside the repo so `git reset --hard` +// in deploy.sh never touches it. Lets a host opt out of cluster mode (e.g. a kernel/LXC +// combination where native addons crash under node's cluster fork) without changing the +// default for every other deployment. +let apiOverride = {}; +try { + apiOverride = JSON.parse(fs.readFileSync("/etc/photoreport/pm2-api.override.json", "utf8")); +} catch {} module.exports = { apps: [ @@ -9,8 +19,8 @@ module.exports = { cwd: path.join(__dirname, "../../apps/api"), script: "dist/server.js", node_args: "--env-file=.env", - instances: 2, - exec_mode: "cluster", + instances: apiOverride.instances ?? 2, + exec_mode: apiOverride.exec_mode ?? "cluster", max_memory_restart: "1G", kill_timeout: 10000, },