Daemon Management
The OpenFang daemon is the core service that runs the kernel, manages agents, and provides the HTTP API and web dashboard.Starting the Daemon
openfang start
Start the OpenFang daemon (kernel + API server).
Behavior:
- Checks if a daemon is already running; exits with an error if so
- Boots the OpenFang kernel:
- Loads configuration from
~/.openfang/config.toml - Initializes SQLite database
- Loads persisted agents
- Connects to configured MCP servers
- Starts background tasks
- Loads configuration from
- Starts the HTTP API server on the configured address (default:
127.0.0.1:4200) - Writes
daemon.jsonto~/.openfang/for daemon discovery - Blocks until interrupted with
Ctrl+C
The daemon runs in the foreground by default. For background operation, use a process manager like
systemd, pm2, or run in a screen/tmux session.Starting with Custom Config
Docker Configuration
When running in Docker, bind to0.0.0.0 to allow external connections:
Stopping the Daemon
openfang stop
Stop the running daemon gracefully.- Reads
daemon.jsonto locate the daemon - Sends
POST /api/shutdownto the daemon - Waits up to 5 seconds for graceful shutdown
- If daemon doesn’t stop, force-kills via PID
- Removes
daemon.json
Stopping from the Same Terminal
If you started the daemon in the foreground, simply pressCtrl+C:
Checking Daemon Status
openfang status
Show the current kernel/daemon status.
Behavior:
-
If daemon is running: Queries
GET /api/statusand displays:- Agent count
- Provider and model
- Uptime
- API URL
- Data directory
- List of active agents
- If no daemon is running: Boots an in-process kernel and shows persisted state with a warning
JSON Output
Health Checks
openfang health
Quick daemon health check.openfang health performs a lightweight check (just the HTTP health endpoint), while openfang status provides comprehensive system information.Diagnostic Checks
openfang doctor
Run comprehensive diagnostic checks on the OpenFang installation.
Checks Performed:
- OpenFang directory -
~/.openfang/exists - .env file - exists and has correct permissions (0600 on Unix)
- Config TOML syntax -
config.tomlparses without errors - Daemon status - whether a daemon is running
- Port availability - if daemon is not running, checks if port 4200 is free
- Stale daemon.json - leftover file from a crashed daemon
- Database file - SQLite magic bytes validation
- Disk space - warns if less than 100MB available (Unix only)
- Agent manifests - validates all
.tomlfiles in~/.openfang/agents/ - LLM provider keys - checks env vars for all providers, performs live validation
- Channel tokens - format validation for Telegram, Discord, Slack tokens
- Config consistency - checks that
api_key_envreferences match actual env vars - Rust toolchain -
rustc --version
Auto-Repair Mode
Gateway Commands
Thegateway subcommand provides an alternative interface to daemon management:
Dashboard Access
openfang dashboard
Open the web dashboard in the default browser.- Requires a running daemon
- Opens the daemon URL (e.g.
http://127.0.0.1:4200/) in the system browser - Copies the URL to the system clipboard
The dashboard is an Alpine.js single-page application served directly by the daemon.
Daemon Auto-Detection Details
The CLI uses a two-step mechanism to detect a running daemon:Step 1: Read daemon.json
On startup, the daemon writes~/.openfang/daemon.json:
Step 2: Health Check
The CLI sendsGET http://<listen_addr>/api/health with a 2-second timeout:
Fallback to In-Process Mode
If either step fails (nodaemon.json, stale file, health check timeout), the CLI falls back to in-process mode for commands that support it.
Commands that require a daemon:
workflowcommandstriggercommandschannel test/enable/disabledashboard
Troubleshooting
Daemon Won’t Start
Port Already in Use:- Kill the process using port 4200
- Change the port in
config.toml:api_listen = "127.0.0.1:4201"
- Check for other OpenFang processes:
ps aux | grep openfang - Remove stale lock:
rm ~/.openfang/data/openfang.db-shm
- Validate TOML syntax with
openfang doctor - Restore default config:
rm ~/.openfang/config.toml && openfang init --quick
Daemon Won’t Stop
Stale daemon.json
If the daemon crashes,daemon.json may be left behind:
Production Deployment
Systemd Service (Linux)
Create/etc/systemd/system/openfang.service:
Docker Compose
PM2 (Node.js Process Manager)
Next Steps
Agent Commands
Learn how to create and manage agents
Configuration
Configure providers, models, and channels