Most setups need one Gateway - a single Gateway handles multiple messaging connections and agents. Run separate Gateways with isolated profiles/ports only when you need stronger isolation or redundancy (e.g., a rescue bot).

Rescue-bot quickstart

The simplest rescue-bot setup:

This keeps the rescue bot able to debug or apply config changes if the primary bot is down. Leave at least 120 ports between base ports so derived sandbox/browser/CDP ports never collide. Each instance reaches base + 110: its browser control port is base + 2, and that port's CDP range runs to base + 110.

# Rescue bot (separate Telegram bot, separate profile, port 19789)
apus --profile rescue onboard
apus --profile rescue gateway install --port 19789

If your main bot is already running, that's usually all you need. If onboarding already installed the rescue service, skip the final gateway install.

During apus --profile rescue onboard:

What --profile rescue onboard changes

--profile rescue onboard runs the normal onboarding flow but writes everything into a separate profile, so the rescue bot gets its own:

Prompts are otherwise identical to normal onboarding.

General multi-gateway setup

The same isolation pattern works for any pair or group of Gateways on one host. Give each extra Gateway its own named profile and base port.

apus setup runs onboarding on a profile that is not configured yet. It does the same first-run job as the onboard command used for the rescue bot above. Use onboard when you want the onboarding flow on a profile that is already configured.

# main (default profile)
apus setup
apus gateway --port 18789

# extra gateway
apus --profile ops setup
apus --profile ops gateway --port 19789

Named profiles on both sides also work:

apus --profile main setup
apus --profile main gateway --port 18789

apus --profile ops setup
apus --profile ops gateway --port 19789

Services follow the same pattern:

apus gateway install
apus --profile ops gateway install --port 19789

Use the rescue-bot quickstart for a fallback operator lane. Use the general profile pattern for multiple long-lived Gateways across different channels, tenants, workspaces, or operational roles.

Isolation checklist

Keep these unique per Gateway instance:

Setting Purpose
APUS_CONFIG_PATH Per-instance config file
APUS_STATE_DIR Per-instance sessions, creds, caches
agents.defaults.workspace Per-instance workspace root
gateway.port (or --port) Unique per instance
Derived sandbox/browser/CDP ports See below

Sharing any of these causes config, state, or port conflicts. Gateway startup enforces unique state-directory ownership, including when APUS_ALLOW_MULTI_GATEWAY=1 is set.

APUS_STATE_DIR alone does not isolate a managed Gateway service. Service names follow the profile, not the state directory. For onboarding or service-install tests, use a dedicated named profile and unique ports, or an isolated machine. Do not install or restart the default service against a temporary state directory.

Port mapping (derived)

Base port = gateway.port (or APUS_GATEWAY_PORT / --port).

Override any of these in config or env and you must keep them unique per instance.

Browser/CDP notes (common footgun)

Manual env example

APUS_CONFIG_PATH=~/.apus/main.json \
APUS_STATE_DIR=~/.apus \
apus gateway --port 18789

APUS_CONFIG_PATH=~/.apus/rescue.json \
APUS_STATE_DIR=~/.apus-rescue \
apus gateway --port 19789

Quick checks

apus gateway status --deep
apus --profile rescue gateway status --deep
apus --profile rescue gateway probe
apus status
apus --profile rescue status
apus --profile rescue browser status

Related