Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(infra): report running only for a container this instance chose
Yudhi Armyndharise25aa0f2d165
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.mdindex 76fe35d09..deeb85395 100644--- a/docs/06-api-specification.md+++ b/docs/06-api-specification.md@@ -5541,7 +5541,7 @@ Aggregate infrastructure status (database, Redis, queue, storage, engine).The `queue.webhooks` counters are live BullMQ job counts (`pending` = waiting + active + delayed; plus `completed`/`failed`), degrading to zeros when the queue is disabled or Redis is unreachable. `redis.connected` is a live probe. `database.host` is the configured `DATABASE_HOST` (default `localhost`) and is reported on SQLite too, so read `type`, not `host`, to tell the database apart.-`builtIn` (on `database`/`redis`/`storage`) reports whether OpenWA's own bundled container is actually running _and_ backing this service, detected live from the labelled container; when Docker is unreachable it falls back to the saved `*_BUILTIN` flag (one pinned by the environment first, else the one in `data/.env.generated`), and a host name alone counts for nothing there, since an external server may be called `postgres`. `running` (on the same three) reports whether a bundled container OpenWA itself created is up, whether or not the service uses it: one Docker Compose created (it carries Compose's project label) reads `false`, and the key is absent while Docker is unreachable, since nothing can be seen or stopped then. In S3 mode `storage` additionally carries `bucket` and `endpoint` (each when one is configured; a bundled MinIO that is stopped still reports `http://minio:9000` here, with `builtIn` false) and `s3Available` (re-probed, throttled, while false; once true it stays true until a restart, so a later outage does not clear it); in local mode neither key is present. `engine.webVersion`/`engine.webVersionSource` (`pinned` / `auto` / `native`) appear only on `whatsapp-web.js`; `webVersion` is `null` until the auto-resolve first succeeds. `engine.browserArgs` is the effective launch argument list: `PUPPETEER_ARGS` (or the four defaults shown) with `--lang=en-US` appended unless a `--lang` flag is already present.+`builtIn` (on `database`/`redis`/`storage`) reports whether OpenWA's own bundled container is actually running _and_ backing this service, detected live from the labelled container; when Docker is unreachable it falls back to the saved `*_BUILTIN` flag (one pinned by the environment first, else the one in `data/.env.generated`), and a host name alone counts for nothing there, since an external server may be called `postgres`. `running` (on the same three) reports whether a bundled container OpenWA itself created is up, whether or not the service uses it: one Docker Compose created (it carries Compose's project label) reads `false`, so does one beside a configuration whose `POSTGRES_BUILTIN`, `REDIS_BUILTIN` or `MINIO_BUILTIN` (the environment's first, else the saved one) is not `true` (the container names are fixed per Docker daemon, so another OpenWA instance on the same daemon sees the same containers), and the key is absent while Docker is unreachable, since nothing can be seen or stopped then. In S3 mode `storage` additionally carries `bucket` and `endpoint` (each when one is configured; a bundled MinIO that is stopped still reports `http://minio:9000` here, with `builtIn` false) and `s3Available` (re-probed, throttled, while false; once true it stays true until a restart, so a later outage does not clear it); in local mode neither key is present. `engine.webVersion`/`engine.webVersionSource` (`pinned` / `auto` / `native`) appear only on `whatsapp-web.js`; `webVersion` is `null` until the auto-resolve first succeeds. `engine.browserArgs` is the effective launch argument list: `PUPPETEER_ARGS` (or the four defaults shown) with `--lang=en-US` appended unless a `--lang` flag is already present.`envPinned` lists which of `DATABASE_TYPE`, `DATABASE_HOST`, `REDIS_ENABLED`, `REDIS_HOST`, `STORAGE_TYPE`, `S3_ENDPOINT`, `STORAGE_LOCAL_PATH`, `ENGINE_TYPE`, `PUPPETEER_HEADLESS`, `SESSION_DATA_PATH` and `PUPPETEER_ARGS` the host environment or the project `.env` sets. Those layers win over `data/.env.generated`, so a value saved for one of these keys through `PUT /api/infra/config` cannot take effect until that layer is changed. A pinned host also decides whether the bundled container backs its service, whatever `builtIn` is saved.diff --git a/docs/13-horizontal-scaling.md b/docs/13-horizontal-scaling.mdindex 046d7d8ba..17602dbf7 100644--- a/docs/13-horizontal-scaling.md+++ b/docs/13-horizontal-scaling.md@@ -742,6 +742,15 @@ The replica count stays at **1** (see 13.3 and 13.4), so the only levers availabsingle-instance deployment with its own session volume and split sessions between them. Horizontal`scale up` / `scale down` becomes an option only once the gaps listed at the top of this guide are closed.+On one Docker daemon, the built-in datastores Dashboard > Infrastructure starts are shared, not per+instance: their container names (`openwa-postgres`, `openwa-redis`, `openwa-minio`), their volumes and+the `openwa-network` network are fixed, so a second instance that turns on Use Built-in attaches to the+first instance's container and data. Let at most one instance on a daemon use them, and point the+others at datastores of their own with their Use Built-in toggles off. A restart from the dashboard+stops a bundled container only when that instance's own configuration uses it or set it up (its+`*_BUILTIN` flag), so an instance that never chose the built-in and dials its own servers leaves the+other one's containers running.+| Metric | Threshold | Action || --------------------------------- | ---------- | ---------------------------------------------------------------------------------------------------------- || CPU > 80% | 5 minutes | Raise `limits.cpu` (StatefulSet); the Swarm block above declares no CPU constraint, so add one |diff --git a/openapi.json b/openapi.jsonindex 2615eee8c..6657470c8 100644--- a/openapi.json+++ b/openapi.json@@ -21912,7 +21912,7 @@},"running": {"type": "boolean",- "description": "Whether a bundled PostgreSQL container OpenWA created is running, whether or not this service uses it. False for one Docker Compose created; absent when Docker is unreachable, where nothing can be seen or stopped.",+ "description": "Whether a bundled PostgreSQL container OpenWA created is running, whether or not this service uses it, beside this instance's built-in flag (the environment's first). False for one Docker Compose created, or with the flag not set; absent when Docker is unreachable, where nothing can be seen or stopped.","example": false}},@@ -21951,7 +21951,7 @@},"running": {"type": "boolean",- "description": "Whether a bundled Redis container OpenWA created is running, whether or not this service uses it. False for one Docker Compose created; absent when Docker is unreachable, where nothing can be seen or stopped.",+ "description": "Whether a bundled Redis container OpenWA created is running, whether or not this service uses it, beside this instance's built-in flag (the environment's first). False for one Docker Compose created, or with the flag not set; absent when Docker is unreachable, where nothing can be seen or stopped.","example": false}},@@ -22043,7 +22043,7 @@},"running": {"type": "boolean",- "description": "Whether a bundled MinIO container OpenWA created is running, whether or not this service uses it. False for one Docker Compose created; absent when Docker is unreachable, where nothing can be seen or stopped.",+ "description": "Whether a bundled MinIO container OpenWA created is running, whether or not this service uses it, beside this instance's built-in flag (the environment's first). False for one Docker Compose created, or with the flag not set; absent when Docker is unreachable, where nothing can be seen or stopped.","example": false},"s3Available": {diff --git a/src/modules/infra/dto/infra-response.dto.ts b/src/modules/infra/dto/infra-response.dto.tsindex 2d4793479..f7f057b2a 100644--- a/src/modules/infra/dto/infra-response.dto.ts+++ b/src/modules/infra/dto/infra-response.dto.ts@@ -32,8 +32,9 @@ export class InfraDatabaseStatusDto {@ApiPropertyOptional({description:- 'Whether a bundled PostgreSQL container OpenWA created is running, whether or not this service uses it. False ' +- 'for one Docker Compose created; absent when Docker is unreachable, where nothing can be seen or stopped.',+ 'Whether a bundled PostgreSQL container OpenWA created is running, whether or not this service uses it, beside ' ++ "this instance's built-in flag (the environment's first). False for one Docker Compose created, or with the " ++ 'flag not set; absent when Docker is unreachable, where nothing can be seen or stopped.',example: false,})running?: boolean;@@ -57,8 +58,9 @@ export class InfraRedisStatusDto {@ApiPropertyOptional({description:- 'Whether a bundled Redis container OpenWA created is running, whether or not this service uses it. False ' +- 'for one Docker Compose created; absent when Docker is unreachable, where nothing can be seen or stopped.',+ 'Whether a bundled Redis container OpenWA created is running, whether or not this service uses it, beside ' ++ "this instance's built-in flag (the environment's first). False for one Docker Compose created, or with the " ++ 'flag not set; absent when Docker is unreachable, where nothing can be seen or stopped.',example: false,})running?: boolean;@@ -111,8 +113,9 @@ export class InfraStorageStatusDto {@ApiPropertyOptional({description:- 'Whether a bundled MinIO container OpenWA created is running, whether or not this service uses it. False ' +- 'for one Docker Compose created; absent when Docker is unreachable, where nothing can be seen or stopped.',+ 'Whether a bundled MinIO container OpenWA created is running, whether or not this service uses it, beside ' ++ "this instance's built-in flag (the environment's first). False for one Docker Compose created, or with the " ++ 'flag not set; absent when Docker is unreachable, where nothing can be seen or stopped.',example: false,})running?: boolean;diff --git a/src/modules/infra/infra-status.controller.spec.ts b/src/modules/infra/infra-status.controller.spec.tsindex 552069f62..c4a295f45 100644--- a/src/modules/infra/infra-status.controller.spec.ts+++ b/src/modules/infra/infra-status.controller.spec.ts@@ -397,8 +397,22 @@ describe('InfraStatusController.getStatus built-in fallback reads the flag only});// `running` reports a bundled container OpenWA created that is up, apart from whether the service uses it: the page-// stops one whose host the environment pins elsewhere. One Docker Compose created belongs to the deployment.+// stops one whose host the environment pins elsewhere. One Docker Compose created belongs to the deployment, and one+// beside a configuration that never chose the built-in service belongs to no setup of this instance (a second+// instance on the same daemon sees the first one's containers under the same names).describe('InfraStatusController.getStatus running bundled containers', () => {+ const FLAGS_TRUE = 'POSTGRES_BUILTIN=true\nREDIS_BUILTIN=true\nMINIO_BUILTIN=true\n';+ const withFile = (contents: string | null) => {+ (fs.existsSync as jest.Mock).mockReturnValue(contents !== null);+ (fs.readFileSync as jest.Mock).mockReturnValue(contents ?? '');+ };+ beforeEach(() => withFile(FLAGS_TRUE));+ afterEach(() => {+ withFile(null);+ recordPinnedEnvKeys({});+ for (const flag of ['POSTGRES_BUILTIN', 'REDIS_BUILTIN', 'MINIO_BUILTIN']) delete process.env[flag];+ });+const build = (containers: Record<'database' | 'cache' | 'storage', false | 'compose' | 'openwa'> | null) => {const values: Record<string, unknown> = {'engine.type': 'baileys',@@ -446,6 +460,26 @@ describe('InfraStatusController.getStatus running bundled containers', () => {expect([status.database.builtIn, status.redis.builtIn, status.storage.builtIn]).toEqual([false, true, false]);});+ it.each([+ ['a first-boot file', 'POSTGRES_BUILTIN=false\nREDIS_BUILTIN=false\nMINIO_BUILTIN=false\n'],+ ['no saved file', null],+ ])('reports none of the three running beside %s that never chose them', async (_label, contents) => {+ withFile(contents);+ const status = await build({ database: 'openwa', cache: 'openwa', storage: 'openwa' }).getStatus();++ expect([status.database.running, status.redis.running, status.storage.running]).toEqual([false, false, false]);+ });++ it('reads the flag the environment pins over the saved one', async () => {+ withFile('POSTGRES_BUILTIN=false\nREDIS_BUILTIN=true\nMINIO_BUILTIN=false\n');+ process.env.POSTGRES_BUILTIN = 'true';+ process.env.REDIS_BUILTIN = 'false';+ recordPinnedEnvKeys({ POSTGRES_BUILTIN: 'true', REDIS_BUILTIN: 'false' });+ const status = await build({ database: 'openwa', cache: 'openwa', storage: 'openwa' }).getStatus();++ expect([status.database.running, status.redis.running, status.storage.running]).toEqual([true, false, false]);+ });+it('reports nothing running when no bundled container is up', async () => {const status = await build({ database: false, cache: false, storage: false }).getStatus();diff --git a/src/modules/infra/infra-status.controller.ts b/src/modules/infra/infra-status.controller.tsindex 4507bad25..6b339a144 100644--- a/src/modules/infra/infra-status.controller.ts+++ b/src/modules/infra/infra-status.controller.ts@@ -198,6 +198,8 @@ export class InfraStatusController {// container, or a host-pinned external host, reads as NOT built-in), and require the app to be// pointed at the bundled service. Fall back to the saved *_BUILTIN flag (the environment's first) when// Docker is unreachable (bare-npm / socket-less) so the toggles don't spuriously flip off. (#488)+ // `running` names a container OpenWA created beside this instance's own built-in flag only: the container names+ // are fixed per daemon, so a second instance there sees the first one's containers, which are not its to stop.const s3Endpoint = this.configService.get<string>('storage.s3.endpoint');const running = this.dockerService.isDockerAvailable()? await this.dockerService.getRunningBuiltinServices()@@ -234,7 +236,7 @@ export class InfraStatusController {type: dbType,host: dbHost,builtIn: dbBuiltIn,- ...(running ? { running: running.database === 'openwa' } : {}),+ ...(running ? { running: running.database === 'openwa' && savedBuiltin.database } : {}),},redis: {enabled: redisEnabled,@@ -242,7 +244,7 @@ export class InfraStatusController {host: redisHost,port: redisPort,builtIn: redisBuiltIn,- ...(running ? { running: running.cache === 'openwa' } : {}),+ ...(running ? { running: running.cache === 'openwa' && savedBuiltin.cache } : {}),},queue: {enabled: queueEnabled,@@ -255,7 +257,7 @@ export class InfraStatusController {// The endpoint this process dials: a bundled MinIO that is stopped still names it, an external store does not....(storageType === 's3' && s3Endpoint ? { endpoint: s3Endpoint } : {}),builtIn: storageBuiltIn,- ...(running ? { running: running.storage === 'openwa' } : {}),+ ...(running ? { running: running.storage === 'openwa' && savedBuiltin.storage } : {}),...(storageType === 's3' ? { s3Available } : {}),},engine: {