Static configuration

Configure Sockudo with TOML or JSON, understand environment precedence, and keep secrets out of static files.

7 min read
View .mdEdit on GitHub

This page explains exactly how Sockudo resolves its configuration at startup: which file it reads, how environment variables override it, and where secrets belong. Read it before writing a production config for any platform; the Linux, Docker, and Kubernetes guides all build on it.

Sockudo supports a static TOML file, a legacy-compatible JSON file, and runtime environment overrides. Use a file for the complete deployment shape. Use environment variables for the subset of settings that vary per environment and for secret references supplied by the platform.

Loading order

Configuration is resolved once, at startup, in this order:

  1. Start from compiled defaults.
  2. If --config <path> (short form -c) is passed, load that file and nothing else.
  3. Otherwise, look in the process working directory for config/config.toml, then config/config.json, and load the first one that exists. If neither exists, keep the compiled defaults.
  4. Apply supported environment-variable overrides on top of the loaded values.
  5. Validate the final configuration.

An explicit .toml path is parsed as TOML. Any other filename extension is parsed as JSON. Prefer a .toml or .json suffix so the format is obvious.

Terminal window
sockudo --config /etc/sockudo/config.toml
sockudo --config /etc/sockudo/config.json

The selected file becomes the complete file-based configuration. An explicit --config file is not merged with an auto-discovered config/config.toml; fields missing from the file receive compiled defaults, not values from another file.

Environment overrides behave differently: if applying them fails, Sockudo logs environment variable overrides failed: <error> and continues starting. Alert on that log line.

Use --config in every production deployment. Relying on auto-discovery makes the result depend on the working directory. The CONFIG_FILE environment variable present in the published container image does not select the file by itself; the image’s default command passes an explicit --config path.

Configuration is read only at startup. Change it through a rollout or service restart; there is no general-purpose hot reload.

Startup log lines

Once logging is initialized, Sockudo records which source it used. Expect one of these:

Log messageMeaning
explicit configuration applied: <path>The --config file loaded.
loaded configuration file: config/config.tomlAuto-discovery found a file (or config/config.json).
no config/config.toml or config/config.json found; using defaultsNo file was found; only defaults and environment variables apply.
applied environment variable overridesEnvironment overrides were applied.

In production, require the explicit configuration applied line before sending traffic.

TOML or JSON?

FormatPrefer it whenNotes
TOMLHumans maintain the file and comments are valuable.Preferred for bare-metal, VM, and source deployments.
JSONA chart, control plane, or program generates the file.Useful for Helm configJson and legacy installations; comments are not allowed.
Environment onlyA small, single-app deployment uses only supported overrides.Not every nested policy has an environment equivalent.

TOML and JSON deserialize into the same ServerOptions structure, so every key works in both. The annotated reference file is config/config.toml in the repository.

Environment placeholders in config files

Before parsing, Sockudo replaces ${VAR} and ${VAR:-default} placeholders in the file with values from the process environment. This lets a committed file reference a secret without containing it, including nested values that have no dedicated environment variable:

config.toml
[metrics]
port = ${METRICS_PORT:-9601}
[[app_manager.array.apps]]
id = "production"
key = "${PROD_APP_KEY}"
secret = "${PROD_APP_SECRET}"
enabled = true

Rules worth knowing:

  • An environment variable that is set but empty is treated as unset, so ${VAR:-default} uses the default.
  • A placeholder without a default whose variable is unset fails the load and lists every unresolved variable in the error.
  • Substitution is plain text over the whole file before parsing, including comments. A ${...} in a comment must also resolve.
  • The value is inserted verbatim. Quote placeholders for string fields, and avoid values containing " or \ in TOML or JSON strings, because they would change the file’s syntax.

Equivalent single-node files

This TOML profile keeps all state in one process and is suitable for a first production-like test, not for failover:

config.toml
mode = "production"
host = "0.0.0.0"
port = 6001
debug = false
max_connections = 20000
activity_timeout = 120
shutdown_grace_period = 30
[adapter]
driver = "local"
[cache]
driver = "memory"
[queue]
driver = "memory"
[rate_limiter]
enabled = true
driver = "memory"
[metrics]
enabled = true
driver = "prometheus"
host = "0.0.0.0"
port = 9601
[app_manager]
driver = "memory"
[app_manager.array]
[[app_manager.array.apps]]
id = "example"
key = "replace-me"
secret = "replace-me"
enabled = true
[app_manager.array.apps.policy.limits]
max_connections = 20000
max_client_events_per_second = 100
[app_manager.array.apps.policy.features]
enable_client_messages = false
enable_user_authentication = true
[app_manager.array.apps.policy.channels]
allowed_origins = ["https://app.example.com"]

The top-level max_connections caps sockets on this node across all apps (0 disables the cap). The app’s policy.limits.max_connections is a separate per-app quota.

The equivalent JSON is:

config.json
{
"mode": "production",
"host": "0.0.0.0",
"port": 6001,
"debug": false,
"max_connections": 20000,
"activity_timeout": 120,
"shutdown_grace_period": 30,
"adapter": {
"driver": "local"
},
"cache": {
"driver": "memory"
},
"queue": {
"driver": "memory"
},
"rate_limiter": {
"enabled": true,
"driver": "memory"
},
"metrics": {
"enabled": true,
"driver": "prometheus",
"host": "0.0.0.0",
"port": 9601
},
"app_manager": {
"driver": "memory",
"array": {
"apps": [
{
"id": "example",
"key": "replace-me",
"secret": "replace-me",
"enabled": true,
"policy": {
"limits": {
"max_connections": 20000,
"max_client_events_per_second": 100
},
"features": {
"enable_client_messages": false,
"enable_user_authentication": true
},
"channels": {
"allowed_origins": ["https://app.example.com"]
}
}
}
]
}
}
}

Replace the example credentials before use. For a committed production file, replace the literal key and secret with ${...} placeholders, bootstrap the app from a secret-backed environment, or use a persistent app manager.

Clustered Redis profile

The stable structure can remain in TOML:

config.toml
mode = "production"
host = "0.0.0.0"
port = 6001
max_connections = 50000
shutdown_grace_period = 30
[adapter]
driver = "redis"
# Fail startup instead of silently running as an isolated local node.
fallback_to_local = false
[cache]
driver = "redis"
[queue]
driver = "redis"
[rate_limiter]
enabled = true
driver = "redis"
[app_manager]
driver = "memory"
[metrics]
enabled = true
host = "0.0.0.0"
port = 9601

fallback_to_local defaults to true. Leaving it on lets a node that cannot reach Redis at startup run alone, splitting clients into groups that never see each other’s events.

Inject the shared address, node identity, and one immutable app at runtime:

sockudo.env
REDIS_URL=rediss://sockudo@redis.internal:6379/0
INSTANCE_PROCESS_ID=sockudo-a-01
SOCKUDO_DEFAULT_APP_ENABLED=true
SOCKUDO_DEFAULT_APP_ID=production
SOCKUDO_DEFAULT_APP_KEY=secret-store-value
SOCKUDO_DEFAULT_APP_SECRET=secret-store-value
SOCKUDO_DEFAULT_APP_ALLOWED_ORIGINS=https://app.example.com
SOCKUDO_DEFAULT_APP_MAX_CONNECTIONS=50000

REDIS_URL updates the Redis adapter, cache, queue, and rate limiter connection. Driver selection still must be redis, either in the file or through ADAPTER_DRIVER, CACHE_DRIVER, QUEUE_DRIVER, and RATE_LIMITER_DRIVER.

INSTANCE_PROCESS_ID names the node. When it is unset, Sockudo generates a random UUID at every start, which is unique but changes on each restart. Set it explicitly when logs, metrics, or Iggy consumers need a stable identity, and never put one shared value in a file that every replica loads.

Use a persistent app manager instead of environment bootstrap when operators create, rotate, or disable multiple applications without rebuilding the deployment.

What belongs where

SettingStatic fileEnvironmentSecret store
Driver selection and feature gatesYesOptional rollout overrideNo
Nested app/channel policyYes, or persistent app managerOnly the documented subsetCredentials only
Retention, buffer, and queue reliabilityYesUse supported overrides sparinglyNo
Per-environment hostnames and portsTemplate, generated file, or ${VAR} placeholderYesOnly if address contains credentials
App keys and secretsAvoid literals in committed files; use ${VAR} placeholdersInject from secret referenceYes
Redis, SQL, broker passwordsAvoid literalsInject from secret referenceYes
TLS private keys and push provider keysFile path or credential referencePath/reference onlyYes

Do not place secrets in image layers, Helm values committed to Git, Kubernetes ConfigMaps, process arguments, or Terraform plan output.

Environment override behavior

Environment variables are explicit mappings in the Sockudo configuration loader, not a generic SECTION_FIELD=value translation. The environment variable reference is the authoritative list. An unknown variable name is ignored without a warning, so check spelling against the reference.

Several app-bootstrap variables have deliberate replacement behavior:

  • a complete SOCKUDO_DEFAULT_APP_ID, SOCKUDO_DEFAULT_APP_KEY, and SOCKUDO_DEFAULT_APP_SECRET set registers the environment-backed default app
  • setting any of those three, or SOCKUDO_DEFAULT_APP_ENABLED=false, removes the apps declared inline in the file
  • SOCKUDO_DEFAULT_APP_ENABLED=false disables the environment-backed registration
  • a partial set (for example an ID and key without a secret) registers nothing and logs default app env configured but id, key, and secret were not all provided
  • SOCKUDO_SKIP_INLINE_APPS=true skips apps declared inside the file
  • APP_MANAGER_REGISTER_INLINE_APPS=false also prevents inline registration

Avoid mixing an inline app and environment bootstrap accidentally. Choose one source for each app and confirm the startup messages.

Container and Kubernetes mounts

Mount a read-only file into the published container and replace the default command:

Terminal window
docker run --rm \
--mount type=bind,src="$PWD/config.toml",dst=/app/config/production.toml,readonly \
ghcr.io/sockudo/sockudo:5.3.0 \
sockudo --config /app/config/production.toml

In Kubernetes, mount non-secret structure from a ConfigMap and inject secrets separately:

containers:
- name: sockudo
args: ["--config", "/etc/sockudo/config.toml"]
envFrom:
- secretRef:
name: sockudo-runtime
volumeMounts:
- name: config
mountPath: /etc/sockudo
readOnly: true
volumes:
- name: config
configMap:
name: sockudo-config

With ${VAR} placeholders in the ConfigMap, the Secret supplies the values and the ConfigMap stays safe to commit. The Helm chart also accepts configJson for advanced generated configuration and extraEnvFrom for Secret or ConfigMap references; see Kubernetes and Helm.

Validate before rollout

  1. Check syntax in CI so a typo never reaches a host:

    Terminal window
    taplo check config.toml
    jq empty config.json

    Both commands print nothing and exit 0 when the file parses.

  2. Start the exact production binary with the same features, environment, working directory, and mounted secrets:

    Terminal window
    sockudo --config /etc/sockudo/config.toml

    The process must keep running. The logs must contain explicit configuration applied and applied environment variable overrides, and must not contain environment variable overrides failed or Configuration validation failed.

  3. Check the process and app health from the same host:

    Terminal window
    curl -fsS -o /dev/null -w '%{http_code}\n' http://127.0.0.1:6001/live
    curl -fsS http://127.0.0.1:6001/up/<app-id>

    Expect 200 from /live. /up/<app-id> prints OK once shared dependencies are reachable, DEGRADED (still 200) when a non-critical check reports degradation, and fails with 503 or 404 when a dependency is down or the app does not exist.

Next steps