Skip to content

Latest commit

 

History

History
62 lines (53 loc) · 2.68 KB

File metadata and controls

62 lines (53 loc) · 2.68 KB

Architecture

How It Works

Server Startup (cmd/rhino/server.go)

  1. Pre-flight checks: Kills existing Rhino processes, validates autosave is disabled
  2. Configuration: Loads config from environment, validates settings
  3. Manager initialization: Creates Rhino manager with health monitoring config
  4. Rhino launch: Starts Rhino as detached subprocess with -runscript flag
  5. Health check: Waits 20s then polls TCP endpoint until healthy (30s timeout)
  6. Monitoring: Starts background health checks (every 30s) and process monitoring
  7. HTTP server: Starts REST API with request queue and proxy to Python server

Process Management (pkg/rhino/manager.go)

The Manager handles Rhino's complete lifecycle:

Startup:

  • Detaches Rhino process (new process group) to prevent zombies
  • Redirects stdout/stderr to /tmp/rhino-output.log
  • Passes server script via -runscript with -nosplash flag
  • Opens empty.3dm to prevent "open file" dialog
  • Handles first-run autosave toggle (auto-restarts if needed)

Health Monitoring:

  • HTTP health checks: Every 30s, hits /healthz on TCP port 17890
  • Process checks: Every 30s, verifies Rhino + RhinoMonitor PIDs exist
  • Auto-restart: On health failure, attempts graceful restart (if enabled)
  • Uses syscall.Kill(pid, 0) to verify process existence without sending signals

Child Process Tracking:

  • Discovers Rhinoceros (main) and RhinoMonitor (helper) PIDs via ps -axo
  • Monitors both processes to detect crashes/zombies
  • Waits 5s after launch for child processes to spawn

Shutdown:

  • Graceful: Sends SIGINT, waits for clean exit (10s timeout)
  • Force: Sends SIGKILL if graceful fails or timeout exceeded
  • Stops health/process monitoring tickers and closes channels

Project Structure

rhino-cli/
├── cmd/rhino/              # CLI commands
│   ├── main.go
│   ├── server.go           # Server command
│   ├── exec.go             # Exec command
│   ├── eval.go             # Eval command
│   └── doctor.go           # Doctor command
├── pkg/
│   ├── config/             # Configuration
│   ├── embedded/           # Embedded Python scripts
│   ├── proxy/              # HTTP client to Python server
│   ├── queue/              # Request queue
│   ├── rhino/              # Rhino process manager
│   ├── server/             # HTTP server
│   └── log/                # Logging utilities
├── scripts/                # Python scripts
│   └── rhino-server.py     # Embedded Python server
├── docs/                   # Documentation
└── ainotes/                # Development notes