fix(infra): allow host-local override of pm2 api exec_mode/instances
ci / typescript (push) Successful in 9m42s
ci / rust (push) Successful in 10m34s

photoreport-api crashes immediately under node cluster mode on some LXC hosts
(native addons: sharp, @node-rs/argon2) while fork mode runs fine. Default
stays cluster/2 everywhere; a host can opt into fork mode by writing
/etc/photoreport/pm2-api.override.json, outside the repo so deploy.sh never
touches it.

Paperclip-Issue: BIT-31073
Paperclip-Run: f547e267-f300-4ca3-a746-be388d7e38b2
This commit is contained in:
spark committed 2026-10-12 13:52:02 +01:00
1 parent 771ae8cc83
commit 2fdbf18fc8
1 file changed
+12 -2
+12 -2
View File
@@ -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,
},