Skip to content

Commit 5d43ee5

Browse files
authored
Merge pull request #8615 from sagemathinc/hub-config-via-env
hub: configure more params via env variables
2 parents ac68fa3 + e1d34fa commit 5d43ee5

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/packages/backend/data.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,28 @@ export function sslConfigToPsqlEnv(config: SSLConfig): PsqlSSLEnvConfig {
171171

172172
export const root: string = process.env.COCALC_ROOT ?? determineRootFromPath();
173173
export const data: string = process.env.DATA ?? join(root, "data");
174+
175+
// Database Config
174176
export const pguser: string = process.env.PGUSER ?? "smc";
175177
export const pgdata: string = process.env.PGDATA ?? join(data, "postgres");
176178
export const pghost: string = process.env.PGHOST ?? join(pgdata, "socket");
177179
export const pgssl = sslConfigFromCoCalcEnv();
178180
export const pgdatabase: string =
179181
process.env.SMC_DB ?? process.env.PGDATABASE ?? "smc";
182+
183+
// Database healthchecks
184+
export const pgConcurrentWarn: number = parseInt(
185+
process.env.COCALC_HEALTH_PG_CONCURRENT_WARN ?? "300",
186+
);
187+
188+
// Hub server configuration
189+
export const hubHostname: string =
190+
process.env.COCALC_HUB_HOSTNAME ?? "127.0.0.1";
191+
export const agentPort: number = parseInt(process.env.COCALC_AGENT_PORT ?? "0");
192+
180193
export const projects: string =
181194
process.env.PROJECTS ?? join(data, "projects", "[project_id]");
195+
182196
export const secrets: string = process.env.SECRETS ?? join(data, "secrets");
183197

184198
// Where the sqlite database files used for sync are stored.

src/packages/hub/hub.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ import { callback } from "awaiting";
1111
import blocked from "blocked";
1212
import { spawn } from "child_process";
1313
import { program as commander, Option } from "commander";
14+
1415
import basePath from "@cocalc/backend/base-path";
1516
import {
1617
pghost as DEFAULT_DB_HOST,
1718
pgdatabase as DEFAULT_DB_NAME,
1819
pguser as DEFAULT_DB_USER,
20+
pgConcurrentWarn as DEFAULT_DB_CONCURRENT_WARN,
21+
hubHostname as DEFAULT_HUB_HOSTNAME,
22+
agentPort as DEFAULT_AGENT_PORT,
1923
} from "@cocalc/backend/data";
2024
import { trimLogFileSize } from "@cocalc/backend/logger";
2125
import port from "@cocalc/backend/port";
@@ -352,14 +356,14 @@ async function main(): Promise<void> {
352356
)
353357
.option(
354358
"--agent-port <n>",
355-
"port for HAProxy agent-check (default: 0 -- do not start)",
359+
`port for HAProxy agent-check (default: ${DEFAULT_AGENT_PORT}; 0 means "do not start")`,
356360
(n) => parseInt(n),
357-
0,
361+
DEFAULT_AGENT_PORT,
358362
)
359363
.option(
360364
"--hostname [string]",
361-
'host of interface to bind to (default: "127.0.0.1")',
362-
"127.0.0.1",
365+
`host of interface to bind to (default: "${DEFAULT_HUB_HOSTNAME}")`,
366+
DEFAULT_HUB_HOSTNAME,
363367
)
364368
.option(
365369
"--database-nodes <string,string,...>",
@@ -407,9 +411,9 @@ async function main(): Promise<void> {
407411
)
408412
.option(
409413
"--db-concurrent-warn <n>",
410-
"be very unhappy if number of concurrent db requests exceeds this (default: 300)",
414+
`be very unhappy if number of concurrent db requests exceeds this (default: ${DEFAULT_DB_CONCURRENT_WARN})`,
411415
(n) => parseInt(n),
412-
300,
416+
DEFAULT_DB_CONCURRENT_WARN,
413417
)
414418
.option(
415419
"--personal",

0 commit comments

Comments
 (0)