Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(infra): report a running bundled container apart from its use

Yudhi Armyndharisd944c5b8c80f
diff --git a/dashboard/src/services/api.ts b/dashboard/src/services/api.ts
index de2d3abb8..e1b0480b8 100644
--- a/dashboard/src/services/api.ts
+++ b/dashboard/src/services/api.ts
@@ -623,9 +623,10 @@ export interface UpdateCheck {
export interface InfraStatus {
// `builtIn` = OpenWA's own bundled container is actually running and backing this service (live),
// not just the saved intent; falls back to the saved flag (the environment's first) when Docker is
- // unavailable. (#488)
- database: { connected: boolean; type: string; host: string; builtIn: boolean };
- redis: { enabled: boolean; connected: boolean; host: string; port: number; builtIn: boolean };
+ // unavailable. (#488) `running` = a bundled container OpenWA created is up, whether or not the service uses it
+ // (false for one Docker Compose created); optional only because an older gateway does not send it.
+ database: { connected: boolean; type: string; host: string; builtIn: boolean; running?: boolean };
+ redis: { enabled: boolean; connected: boolean; host: string; port: number; builtIn: boolean; running?: boolean };
queue: {
enabled: boolean;
webhooks: { pending: number; completed: number; failed: number };
@@ -637,6 +638,7 @@ export interface InfraStatus {
// S3 only, when an endpoint is set: the one the server dials, which a stopped bundled MinIO still names.
endpoint?: string;
builtIn: boolean;
+ running?: boolean;
s3Available?: boolean;
};
engine: {
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.md
index 66e227fd6..12387d1e0 100644
--- a/docs/06-api-specification.md
+++ b/docs/06-api-specification.md
@@ -5512,13 +5512,20 @@ Aggregate infrastructure status (database, Redis, queue, storage, engine).
```json
{
- "database": { "connected": true, "type": "sqlite", "host": "localhost", "builtIn": false },
- "redis": { "enabled": false, "connected": false, "host": "localhost", "port": 6379, "builtIn": false },
+ "database": { "connected": true, "type": "sqlite", "host": "localhost", "builtIn": false, "running": false },
+ "redis": {
+ "enabled": false,
+ "connected": false,
+ "host": "localhost",
+ "port": 6379,
+ "builtIn": false,
+ "running": false
+ },
"queue": {
"enabled": false,
"webhooks": { "pending": 0, "completed": 0, "failed": 0 }
},
- "storage": { "type": "local", "path": "./data/media", "builtIn": false },
+ "storage": { "type": "local", "path": "./data/media", "builtIn": false, "running": false },
"engine": {
"type": "whatsapp-web.js",
"headless": true,
@@ -5533,7 +5540,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`. 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) and any container while Docker is unreachable read `false`. 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/openapi.json b/openapi.json
index 79a41f052..1e07e6acc 100644
--- a/openapi.json
+++ b/openapi.json
@@ -21889,13 +21889,19 @@
"type": "boolean",
"description": "Whether OpenWA's own bundled container is actually running and backing this service, detected live from the labelled container rather than read from the saved intent. When Docker is unavailable it falls back to the saved flag (the environment's first), and a host name alone proves nothing.",
"example": true
+ },
+ "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 and when Docker is unreachable.",
+ "example": false
}
},
"required": [
"connected",
"type",
"host",
- "builtIn"
+ "builtIn",
+ "running"
]
},
"InfraRedisStatusDto": {
@@ -21923,6 +21929,11 @@
"type": "boolean",
"description": "Whether OpenWA's bundled Redis container is backing this.",
"example": true
+ },
+ "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 and when Docker is unreachable.",
+ "example": false
}
},
"required": [
@@ -21930,7 +21941,8 @@
"connected",
"host",
"port",
- "builtIn"
+ "builtIn",
+ "running"
]
},
"InfraQueueDepthDto": {
@@ -22011,6 +22023,11 @@
"description": "Whether OpenWA's bundled MinIO container is backing this.",
"example": false
},
+ "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 and when Docker is unreachable.",
+ "example": false
+ },
"s3Available": {
"type": "boolean",
"description": "Whether the S3 endpoint answered a probe. Present only for `s3`."
@@ -22018,7 +22035,8 @@
},
"required": [
"type",
- "builtIn"
+ "builtIn",
+ "running"
]
},
"InfraEngineStatusDto": {
diff --git a/src/modules/docker/docker.service.spec.ts b/src/modules/docker/docker.service.spec.ts
index 8c681e99c..85b81d214 100644
--- a/src/modules/docker/docker.service.spec.ts
+++ b/src/modules/docker/docker.service.spec.ts
@@ -15,12 +15,12 @@ const imageNotCached = () => ({
});
describe('DockerService.getRunningBuiltinServices', () => {
- const container = (name: string, service: string, state: string) => ({
+ const container = (name: string, service: string, state: string, labels: Record<string, string> = {}) => ({
id: name,
name,
state,
status: state,
- labels: { 'com.openwa.service': service, 'com.openwa.builtin': 'true' },
+ labels: { 'com.openwa.service': service, 'com.openwa.builtin': 'true', ...labels },
});
it('reports a service built-in only when its labeled container is actually running', async () => {
@@ -32,7 +32,20 @@ describe('DockerService.getRunningBuiltinServices', () => {
container('openwa-redis', 'cache', 'exited'),
]);
- expect(await service.getRunningBuiltinServices()).toEqual({ database: true, cache: false, storage: false });
+ expect(await service.getRunningBuiltinServices()).toEqual({ database: 'openwa', cache: false, storage: false });
+ });
+
+ it('names a running container Docker Compose created, by its project label', async () => {
+ const service = new DockerService();
+ jest
+ .spyOn(service, 'listContainers')
+ .mockResolvedValue([
+ container('openwa-postgres', 'database', 'running', { 'com.docker.compose.project': 'openwa' }),
+ container('openwa-redis', 'cache', 'running'),
+ container('openwa-minio', 'storage', 'exited', { 'com.docker.compose.project': 'openwa' }),
+ ]);
+
+ expect(await service.getRunningBuiltinServices()).toEqual({ database: 'compose', cache: 'openwa', storage: false });
});
it('reports all false when no bundled containers are present (e.g. Docker unavailable)', async () => {
diff --git a/src/modules/docker/docker.service.ts b/src/modules/docker/docker.service.ts
index a9825636d..a8470bacd 100644
--- a/src/modules/docker/docker.service.ts
+++ b/src/modules/docker/docker.service.ts
@@ -232,17 +232,22 @@ export class DockerService implements OnModuleInit {
/**
* Which bundled (OpenWA-managed) service containers are currently RUNNING, keyed by the
- * `com.openwa.service` label (`database` | `cache` | `storage`). Lets the dashboard show the real
- * built-in state instead of the saved intent. All false when Docker is unavailable or none run.
+ * `com.openwa.service` label (`database` | `cache` | `storage`), and who created each: `'compose'` for one
+ * Docker Compose created (it carries Compose's project label and belongs to the deployment), `'openwa'` for
+ * one createService made. Lets the dashboard show the real built-in state instead of the saved intent. All
+ * false when Docker is unavailable or none run.
*/
- async getRunningBuiltinServices(): Promise<{ database: boolean; cache: boolean; storage: boolean }> {
+ async getRunningBuiltinServices(): Promise<Record<'database' | 'cache' | 'storage', false | 'compose' | 'openwa'>> {
const containers = await this.listContainers();
- const isRunning = (svc: string): boolean =>
- containers.some(
+ const creator = (svc: string): false | 'compose' | 'openwa' => {
+ const running = containers.find(
c =>
c.labels['com.openwa.service'] === svc && c.labels['com.openwa.builtin'] === 'true' && c.state === 'running',
);
- return { database: isRunning('database'), cache: isRunning('cache'), storage: isRunning('storage') };
+ if (!running) return false;
+ return running.labels['com.docker.compose.project'] ? 'compose' : 'openwa';
+ };
+ return { database: creator('database'), cache: creator('cache'), storage: creator('storage') };
}
/**
diff --git a/src/modules/infra/dto/infra-response.dto.ts b/src/modules/infra/dto/infra-response.dto.ts
index 27ce98305..830fb4fac 100644
--- a/src/modules/infra/dto/infra-response.dto.ts
+++ b/src/modules/infra/dto/infra-response.dto.ts
@@ -29,6 +29,14 @@ export class InfraDatabaseStatusDto {
example: true,
})
builtIn!: boolean;
+
+ @ApiProperty({
+ description:
+ 'Whether a bundled PostgreSQL container OpenWA created is running, whether or not this service uses it. False ' +
+ 'for one Docker Compose created and when Docker is unreachable.',
+ example: false,
+ })
+ running!: boolean;
}
export class InfraRedisStatusDto {
@@ -46,6 +54,14 @@ export class InfraRedisStatusDto {
@ApiProperty({ description: "Whether OpenWA's bundled Redis container is backing this.", example: true })
builtIn!: boolean;
+
+ @ApiProperty({
+ description:
+ 'Whether a bundled Redis container OpenWA created is running, whether or not this service uses it. False ' +
+ 'for one Docker Compose created and when Docker is unreachable.',
+ example: false,
+ })
+ running!: boolean;
}
export class InfraQueueDepthDto {
@@ -93,6 +109,14 @@ export class InfraStorageStatusDto {
@ApiProperty({ description: "Whether OpenWA's bundled MinIO container is backing this.", example: false })
builtIn!: boolean;
+ @ApiProperty({
+ description:
+ 'Whether a bundled MinIO container OpenWA created is running, whether or not this service uses it. False ' +
+ 'for one Docker Compose created and when Docker is unreachable.',
+ example: false,
+ })
+ running!: boolean;
+
@ApiPropertyOptional({ description: 'Whether the S3 endpoint answered a probe. Present only for `s3`.' })
s3Available?: boolean;
}
diff --git a/src/modules/infra/infra-status.controller.spec.ts b/src/modules/infra/infra-status.controller.spec.ts
index 4a092879e..0510de5b4 100644
--- a/src/modules/infra/infra-status.controller.spec.ts
+++ b/src/modules/infra/infra-status.controller.spec.ts
@@ -394,3 +394,59 @@ describe('InfraStatusController.getStatus built-in fallback reads the flag only
expect([status.database.builtIn, status.redis.builtIn, status.storage.builtIn]).toEqual([true, false, false]);
});
});
+
+// `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.
+describe('InfraStatusController.getStatus running bundled containers', () => {
+ const build = (containers: Record<'database' | 'cache' | 'storage', false | 'compose' | 'openwa'> | null) => {
+ const values: Record<string, unknown> = {
+ 'engine.type': 'baileys',
+ 'dataDatabase.type': 'postgres',
+ 'dataDatabase.host': 'db.ext.example',
+ 'redis.host': 'redis',
+ 'storage.type': 's3',
+ 'storage.s3.endpoint': 'https://s3.ext.example',
+ };
+ const config = { get: (k: string, def?: unknown) => values[k] ?? def };
+ const ds = { isInitialized: true, query: jest.fn().mockResolvedValue([{ '1': 1 }]) };
+ return new InfraStatusController(
+ config as never,
+ ds as never,
+ ds as never,
+ { create: jest.fn() } as never,
+ {
+ isDockerAvailable: () => containers !== null,
+ getRunningBuiltinServices: jest.fn().mockResolvedValue(containers),
+ } as never,
+ { isAvailable: jest.fn().mockResolvedValue(false) } as never,
+ { refreshS3Availability: jest.fn().mockResolvedValue(true) } as never,
+ undefined as never,
+ );
+ };
+ const savedRedisHost = process.env.REDIS_HOST;
+
+ beforeEach(() => delete process.env.REDIS_HOST);
+ afterAll(() => {
+ if (savedRedisHost !== undefined) process.env.REDIS_HOST = savedRedisHost;
+ });
+
+ it('reports a container OpenWA created as running whether or not the service uses it', async () => {
+ const status = await build({ database: 'openwa', cache: 'compose', storage: 'openwa' }).getStatus();
+
+ expect([status.database.builtIn, status.database.running]).toEqual([false, true]);
+ expect([status.redis.builtIn, status.redis.running]).toEqual([true, false]);
+ expect([status.storage.builtIn, status.storage.running]).toEqual([false, true]);
+ });
+
+ it('reports nothing running when no bundled container is up', async () => {
+ const status = await build({ database: false, cache: false, storage: false }).getStatus();
+
+ expect([status.database.running, status.redis.running, status.storage.running]).toEqual([false, false, false]);
+ });
+
+ it('reports nothing running when Docker is unreachable', async () => {
+ const status = await build(null).getStatus();
+
+ expect([status.database.running, status.redis.running, status.storage.running]).toEqual([false, false, false]);
+ });
+});
diff --git a/src/modules/infra/infra-status.controller.ts b/src/modules/infra/infra-status.controller.ts
index 89be9509b..b30de6204 100644
--- a/src/modules/infra/infra-status.controller.ts
+++ b/src/modules/infra/infra-status.controller.ts
@@ -32,8 +32,10 @@ interface InfraStatus {
// `builtIn` reflects whether OpenWA's own bundled container is actually running and backing this
// service (detected live from the labeled container), not merely the saved intent. Falls back to the
// saved flag, the environment's first, when Docker is unavailable. (#488)
- database: { connected: boolean; type: string; host: string; builtIn: boolean };
- redis: { enabled: boolean; connected: boolean; host: string; port: number; builtIn: boolean };
+ // `running` is whether a bundled container OpenWA created is up, whether or not the service uses it; false for
+ // one Docker Compose created and when Docker is unavailable.
+ database: { connected: boolean; type: string; host: string; builtIn: boolean; running: boolean };
+ redis: { enabled: boolean; connected: boolean; host: string; port: number; builtIn: boolean; running: boolean };
queue: {
enabled: boolean;
webhooks: { pending: number; completed: number; failed: number };
@@ -44,6 +46,7 @@ interface InfraStatus {
bucket?: string;
endpoint?: string;
builtIn: boolean;
+ running: boolean;
s3Available?: boolean;
};
engine: {
@@ -200,9 +203,9 @@ export class InfraStatusController {
? await this.dockerService.getRunningBuiltinServices()
: null;
const savedBuiltin = this.readSavedBuiltinFlags();
- const dbBuiltIn = running ? running.database && dbHost === 'postgres' : savedBuiltin.database;
- const redisBuiltIn = running ? running.cache && redisHost === 'redis' : savedBuiltin.cache;
- const storageBuiltIn = running ? running.storage && s3Endpoint === 'http://minio:9000' : savedBuiltin.storage;
+ const dbBuiltIn = running ? !!running.database && dbHost === 'postgres' : savedBuiltin.database;
+ const redisBuiltIn = running ? !!running.cache && redisHost === 'redis' : savedBuiltin.cache;
+ const storageBuiltIn = running ? !!running.storage && s3Endpoint === 'http://minio:9000' : savedBuiltin.storage;
// Re-probe (throttled) so a MinIO/S3 that came up after boot is reflected, not latched unreachable.
const s3Available = storageType === 's3' ? await this.storageService.refreshS3Availability() : undefined;
@@ -224,13 +227,20 @@ export class InfraStatusController {
}
return {
- database: { connected: dbConnected, type: dbType, host: dbHost, builtIn: dbBuiltIn },
+ database: {
+ connected: dbConnected,
+ type: dbType,
+ host: dbHost,
+ builtIn: dbBuiltIn,
+ running: running?.database === 'openwa',
+ },
redis: {
enabled: redisEnabled,
connected: redisConnected,
host: redisHost,
port: redisPort,
builtIn: redisBuiltIn,
+ running: running?.cache === 'openwa',
},
queue: {
enabled: queueEnabled,
@@ -243,6 +253,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?.storage === 'openwa',
...(storageType === 's3' ? { s3Available } : {}),
},
engine: {