From d13085fdd6ca865473f98df9d09bb9abcfa36eb5 Mon Sep 17 00:00:00 2001 From: Stanislaw <56738034+anvme@users.noreply.github.com> Date: Sat, 20 Jun 2026 07:20:45 +0200 Subject: [PATCH] Run server as PID 1 in Docker to drop idle launcher processes The container CMD ran `npm run start-docker`, i.e. `npm-run-all check-db update-tracker start-server`. After the one-shot tasks exit, three Node VMs stay resident for the container lifetime (npm -> npm-run-all -> npm -> node server.js), each holding tens of MiB of anonymous memory for nothing. Replace it with a small start script that runs the one-shot steps and then `exec node server.js`, so the server becomes PID 1 and no launcher wrappers remain. On a dev 3.2.0 build under realistic load the container RSS dropped ~28% (memory.stat anon 255 MiB -> 183 MiB); migrations still apply and /api/heartbeat serves normally. --- Dockerfile | 2 +- scripts/start-docker.sh | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100755 scripts/start-docker.sh diff --git a/Dockerfile b/Dockerfile index d9e967b26..520814881 100644 --- a/Dockerfile +++ b/Dockerfile @@ -76,4 +76,4 @@ EXPOSE 3000 ENV HOSTNAME=0.0.0.0 ENV PORT=3000 -CMD ["npm", "run", "start-docker"] +CMD ["sh", "scripts/start-docker.sh"] diff --git a/scripts/start-docker.sh b/scripts/start-docker.sh new file mode 100755 index 000000000..2ad0c3c2e --- /dev/null +++ b/scripts/start-docker.sh @@ -0,0 +1,16 @@ +#!/bin/sh +# Container startup: run the one-shot DB check/migration and tracker update, then +# exec the long-running server so it replaces this shell as PID 1. +# +# This avoids `npm-run-all` keeping idle `npm`/`npm-run-all` parent processes +# resident for the lifetime of the container (each a full Node VM holding tens +# of MiB of anonymous memory). `exec` leaves a single `node server.js` process. +# +# PATH is extended so check-db.js's `prisma migrate deploy` resolves the prisma +# CLI from node_modules/.bin the way `npm run` would have injected it. +set -e +export PATH="$PWD/node_modules/.bin:$PATH" + +node scripts/check-db.js +node scripts/update-tracker.js +exec node server.js