Positioning & Roadmap
Why moond exists, platform differences between macOS and Linux, and future directions.
Why moond
As a focused tool for the MoonBit ecosystem, moond makes complete sense; as a general-purpose PM2 replacement, it does not.
- Where it fits: MoonBit currently cannot directly exploit multiple CPU cores within a single process, and the ecosystem lacks a native process manager.
moondfills thecluster + PM2gap for MoonBit services—spawning multiple workers, handling crash restarts, rotating logs, and exposing live metrics in a single zero-dependency native binary. - What it intentionally avoids: General-purpose server process supervision is already well solved by
systemd,supervisord, and container orchestrators.moondstays lean and tailored to MoonBit service workflows rather than duplicating every feature of PM2.
Roadmap
Staying true to a lean, zero-dependency process manager tailored for MoonBit services, progress and upcoming work are organized across Features, Performance, and Experience & Ecosystem:
Features
Completed
-
Single-Binary Daemon & Hardened Control Plane: Auto-spawns a detached daemon on first
start, protects against races with a lock file, binds the port before writing credentials, enforces constant-time0600Bearer-token auth, and validates app names against path traversal. -
Multi-Instance Self-Healing & Guards: Supports
-i <n>, min-uptime crash resets (--min-uptime), exponential backoff, memory limits (--max-memory-restart), 5-field--cron-restart, and 3s-timeout HTTP/TCP health probes (--health-url/--health-tcp). -
Zero-Downtime Operations & Declarative Config: Rolling reloads (
moond reload), dynamic scaling (moond scale), idempotent hot-updates (moond apply --env), targetedname:id/allcontrols, and fullmoond.jsonlifecycle management. -
Built-in L4 TCP Reverse Proxy (
--proxy-port): Automatically injectsPORT/MOOND_WORKER_PORTper worker and load-balances connections with health-aware round-robin routing and automatic failover. -
Persistence & Logging: Atomic
state.jsonpersistence (save/resurrect), incremental byte-offset tailing (logs <name:id> -f),--timeline timestamps, and--merge-logs. -
Graceful Connection Drain & Ready Signal: Drains in-flight proxy connections (
--drain-timeout) before stopping old workers duringreloadand supports explicit workerPOST /apps/readysignaling (--wait-ready). -
Unix Domain Socket Control Plane: Automatically exposes a
0600-permission~/.moond/moond.sockcontrol channel alongside127.0.0.1:19876. -
Observability & Alert Hooks: Exposes a Prometheus-compatible
/metricsendpoint (moond metrics) and triggers--webhook-url/--alert-cmdhooks on crash loops, memory limits, or failed probes. -
Log Search & Multi-App Aggregation: Supports
moond logs all -fwith colored prefixes plus--grepand--sincefiltering.
Performance
Completed
-
Atomic Local Time & Per-Second Caching: Captures local time atomically via a single
localtime_rcall to prevent cross-second tearing, with per-second timestamp caching for--timelog lines. -
Process Metrics Caching: Uses a 50ms per-PID cache around
proc_pidinfoon macOS so sampling RSS and CPU in the same pass avoids duplicate syscalls. -
Low-Memory Streaming Log I/O: Keeps log pipe descriptors open, performs streaming chunked
copytruncaterotation, and readslogs -nvia a tail window without loading entire files into memory. -
Concurrent Scheduling & Fast Change Hashing: Concurrent batch stops, per-app
Semaphorelocks, non-blocking async cron/watch reloads, and 64-bit FNV-1a directory hashing. -
OS-Native File Watching (
kqueue/inotify): Uses kernel-driven filesystem events on macOS and Linux to skip directory scans while idle. -
TCP Proxy Connection Governance: Tracks per-instance active connections with
--proxy-max-connslimits and--proxy-idle-msidle timeouts. -
Tiered Metric Sampling & Compressed Rotation: Slices CPU sampling when > 16 instances are online and supports
--log-compressasync.gzlog archiving.
Experience & Ecosystem
Completed
-
Cross-Platform Live Monitoring: Real-time CPU%, RSS memory, and health visibility in
moond ls,ls --json,describe, andmoond monit(macOS / Linux / Windows metrics support). -
System Service Integration (
moond startup): Generatessystemdand XML-escapedlaunchdboot startup templates with resolved absolute paths. -
Distribution, Docs & Quality: Published
wsafight/moondonmooncakes.io, built a bilingual Astro docs site (3-column TOC + interactive terminal demos), and backed everything with 36 unit tests and 27 E2E tests. -
Prebuilt Binaries & One-Line Install: Multi-arch GitHub Releases matrix (macOS/Linux x86_64 & arm64),
scripts/install.sh,Formula/moond.rb, andmoond self-update. -
Interactive
moond monitTUI: Supportsj/k/arrow selection,linline log tailing,r/R/+/-live actions, andqgraceful exit. -
MoonBit Ecosystem Tooling: Added
moond init,schema/moond.schema.jsonfor IDE autocomplete, and thewsafight/moond/sdkhelper package (worker_port,reuse_port_enabled,notify_ready). -
Windows Process-Tree Cleanup & CI Matrix: Added recursive Windows process-tree termination and a
windows-latestCI test/build matrix.
Platform Behavior Differences
- Linux (
SO_REUSEPORT): Multiple workers can bind the exact same port viaTcpServer(..., reuse_port_lb=true)and let the Linux kernel distribute incoming connections across CPU cores. - Cross-Platform Built-in TCP Reverse Proxy: On macOS (or for services that do not enable
SO_REUSEPORT), pass--proxy-port <port>(and optional--proxy-base-port <port>).moondautomatically injects sequentialPORTandMOOND_WORKER_PORTvalues into each worker and load-balances incoming TCP connections in round-robin order with automatic failover.
Risks & Considerations
- Standard Library Evolution:
moonbitlang/core/asyncis actively evolving; future MoonBit releases may introduce minor API adjustments. - Minimal C FFI Surface: Keeping all platform-specific syscalls isolated inside
src/sysensures the core supervisor remains pure MoonBit and easy to maintain across platforms.