Guide

CLI & Config Reference

Complete reference for moond subcommands, start options, environment variables, and moond.json.

Subcommands

Command Description
moond start [options] <cmd> [args...] Start and supervise a single- or multi-instance app
moond start <config.json> [--only <name>] [--env <profile>] Batch-start apps from a declarative JSON config file
moond apply <config.json> [--only <name>] [--env <profile>] [--wait <ms>] Idempotent deploy: start missing apps, hot-update env/args/instances and rolling-reload existing ones (alias: startOrReload)
moond ls [--json] / list / status List all apps and instances with PID, status, live CPU%, RSS memory, restarts, and uptime; --json outputs raw JSON
moond monit [--once] / top Interactive ANSI terminal monitor (j/k select, l inline logs, r/R/+/- actions)
moond metrics Print Prometheus text-format metrics (/metrics)
moond init [path] [--force] Scaffold a moond.json config with JSON Schema reference
moond self-update Download and install the latest GitHub Release binary
moond describe <name> / info Show full config, env vars, watch/health/memory settings, log paths, and per-instance metrics
moond logs <name|name:id|all> [-n <lines>] [--err] [-f] [--grep <kw>] [--since <ts>] Show or follow stdout/stderr logs for an app, single instance, or all apps with keyword/time filtering
moond flush [name|all] Truncate logs for one app or all apps
moond restart <name|name:id|all|config.json> [--only <name>] Restart app(s) or a single instance
moond reload <name|name:id|all|config.json> [--only <name>] [--wait <ms>] Zero-downtime rolling reload (waits for health probe if configured)
moond scale <name> <instances> Dynamically scale worker count up or down
moond stop <name|name:id|all|config.json> [--only <name>] Gracefully stop app(s) or a single instance (SIGTERM + process-group cleanup)
moond delete <name|all|config.json> [--only <name>] / rm Stop and remove app(s) from supervision
moond save Persist current app specs to MOOND_HOME/state.json
moond resurrect Auto-start daemon and restore all apps from state.json
moond startup [systemd|launchd] Print a Linux systemd or macOS launchd startup template
moond kill Gracefully stop all apps and shut down the daemon
moond version Print current version

start Options

Option Default Description
--name, -n <name> Command basename Application name
-i, --instances <n> 1 Number of worker instances
-e, --env KEY=VAL None Inject custom env var (repeatable)
--cwd <dir> Current directory Working directory for workers
--max-restarts <n> 15 Max consecutive crashes before marking errored
--restart-delay <ms> 1000 Base exponential backoff delay (capped at 30s)
--min-uptime <ms> 10000 Stable runtime threshold that resets consecutive crash counter
--max-log-bytes <bytes> 10485760 (10MB) Auto-rotate logs on start/restart and during background runtime checks
--log-retain <n> 3 Number of rotated log backups (.1...N) to retain
--merge-logs false Merge stdout/stderr logs across all instances into <name>.out.log / <name>.err.log
--time false Prefix each log line with local timestamp [YYYY-MM-DD HH:MM:SS]
--kill-timeout <ms> 3000 Graceful SIGTERM timeout before escalating to SIGKILL
--max-memory-restart <size> Off Auto-restart instance when RSS exceeds limit (e.g. 256M, 1G)
--cron-restart <expr> Off Standard 5-field cron schedule for periodic rolling reload
--health-url <url> Off HTTP GET health probe URL (2xx/3xx healthy)
--health-tcp <host:port> Off TCP connect health probe address
--health-interval <ms> 5000 Interval between health checks
--health-retries <n> 3 Consecutive probe failures before auto-reload
--watch [path] Off Watch file or directory changes and auto rolling-reload (repeatable; defaults to cwd)
--ignore-watch <pattern> .git, node_modules, .mooncakes Ignore matching watch paths (repeatable)
--watch-delay <ms> 500 Debounce delay in ms before triggering auto-reload
--proxy-port <port> Off Enable built-in TCP reverse proxy to round-robin traffic across online workers
--proxy-base-port <port> proxy_port + 1 Starting worker port assigned by the built-in TCP reverse proxy
--proxy-max-conns <n> 0 (unlimited) Max concurrent connections allowed by the built-in TCP proxy
--proxy-idle-ms <ms> 60000 Idle timeout in ms for proxied TCP connections
--drain-timeout <ms> 5000 Graceful connection drain timeout before stopping a worker during reload
--wait-ready Off Wait for explicit worker POST /apps/ready signaling during reload
--webhook-url <url> Off HTTP POST webhook URL for crash/memory/health alerts
--alert-cmd <cmd> Off Shell command executed on crash/memory/health alerts
--log-compress Off Asynchronously gzip-compress rotated log archives
--only <name> All apps Filter a single app when running config file commands

Injected Worker Environment Variables

moond automatically injects these variables into every managed worker:

  • MOOND_APP_NAME: Application name
  • MOOND_INSTANCE_ID: Zero-based instance index (0, 1, …)
  • MOOND_INSTANCES: Total instance count for the app
  • MOOND_WORKER_PORT / PORT: Injected when --proxy-port (or proxy_port in moond.json) is enabled, set to proxy_base_port + MOOND_INSTANCE_ID

Declarative Config (moond.json)

When the sole argument to moond start ends with .json, moond parses it as a batch configuration:

{
  "apps": [
    {
      "name": "api",
      "cmd": "./my-moonbit-api",
      "args": ["--port", "8080"],
      "cwd": ".",
      "env": {
        "APP_ENV": "development"
      },
      "env_production": {
        "APP_ENV": "production"
      },
      "instances": 4,
      "proxy_port": 8080,
      "proxy_base_port": 18080,
      "health_url": "http://127.0.0.1:8080/health",
      "max_memory_restart": "512M",
      "max_restarts": 15,
      "restart_delay_ms": 1000,
      "min_uptime_ms": 10000,
      "max_log_bytes": 10485760
    },
    {
      "name": "worker",
      "cmd": "./my-moonbit-worker",
      "instances": 2
    }
  ]
}

Global Environment Variables

Variable Default Description
MOOND_HOME ~/.moond Data directory storing token, state.json, daemon.pid, daemon.lock, and logs/
MOOND_PORT 19876 Local HTTP control plane port (bound to 127.0.0.1)