Skip to content

Add server process management with named instances#15

Merged
sdairs merged 2 commits intomainfrom
server-process-management
Mar 9, 2026
Merged

Add server process management with named instances#15
sdairs merged 2 commits intomainfrom
server-process-management

Conversation

@sdairs
Copy link
Copy Markdown
Collaborator

@sdairs sdairs commented Mar 8, 2026

Summary

  • New chv server command group replacing chv run server, with subcommands: start, list, stop, stop-all, remove
  • Named server instances — each server gets its own data directory at .clickhouse/servers/<name>/data/, enabling multiple isolated servers running simultaneously
  • Smart defaults — first server is called "default", subsequent unnamed servers get random names (e.g. "bold-crane"), or use --name for stable identities
  • Auto port assignment — tries default ports (HTTP 8123, TCP 9000); if in use, automatically finds and assigns free ports. Explicit --http-port and --tcp-port flags for manual control
  • Background by default — servers start in background with PID tracking. Use --foreground (-F / --fg) to run in foreground
  • Process lifecycle management — PID tracking with post-spawn health checks, SIGTERM→SIGKILL graceful shutdown, stale PID cleanup
  • Server discoverychv server list shows both running and stopped servers by scanning data directories
  • chv run simplified — now only handles client, local, and --sql

New commands

Command Description
chv server start Start a server (background by default)
chv server start --name dev Start a named server
chv server start --http-port 8124 Start with explicit port
chv server start --foreground Run in foreground
chv server list List all servers (running + stopped)
chv server stop <name> Stop a server by name
chv server stop-all Stop all running servers
chv server remove <name> Delete a stopped server's data

Breaking changes

  • chv run server is removed — use chv server start instead
  • Server data directories moved from .clickhouse/{version}/ to .clickhouse/servers/<name>/data/

Test plan

  • chv server start — starts "default" server in background, prints PID and ports
  • chv server start again — auto-generates random name, auto-assigns free ports
  • chv server start --name test — starts named server
  • chv server list — shows running and stopped servers with status
  • chv server stop default — stops the default server
  • chv server list — default now shows as [stopped]
  • chv server start --name default — restarts the stopped server
  • chv server stop-all — stops all running servers
  • chv server remove test — deletes stopped server data
  • chv server start --foreground — runs in foreground, Ctrl-C exits cleanly
  • chv server start --http-port 9123 --tcp-port 9100 — uses explicit ports
  • chv run --sql "SELECT 1" — still works
  • chv run client / chv run local — still works

🤖 Generated with Claude Code

sdairs and others added 2 commits March 9, 2026 17:34
Introduce `chv server` command group for managing multiple named
ClickHouse server instances, replacing the old `chv run server`.

Key changes:
- New `src/server.rs` module for process tracking, port management,
  and server lifecycle (start/stop/list/remove)
- Each server gets its own data directory at `.clickhouse/servers/<name>/data/`
- Servers default to background mode with `--foreground` (`-F`/`--fg`) flag
- Auto-assigns free ports when defaults (8123/9000) are in use;
  explicit `--http-port` and `--tcp-port` flags for manual control
- Named servers: "default" for first, random adjective-noun for subsequent,
  or explicit `--name` for stable identity
- PID tracking with health checks, SIGTERM→SIGKILL shutdown sequence
- `chv server list` shows both running and stopped servers
- `chv server stop-all` for bulk shutdown
- `chv server remove` to delete stopped server data
- `chv run` simplified to only handle client, local, and --sql
- New error variants: ServerNotRunning, ServerNotFound, ServerAlreadyRunning

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Document the new `chv server` command group including start, list,
stop, stop-all, and remove subcommands. Cover server naming, auto
port assignment, foreground mode, and per-server data directories.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sdairs sdairs force-pushed the server-process-management branch from eac07ee to a1da230 Compare March 9, 2026 17:36
@sdairs sdairs merged commit 252de4a into main Mar 9, 2026
@sdairs sdairs mentioned this pull request Mar 9, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant