Add process discovery and global server management#105
Merged
Conversation
…management Implements #102: ClickHouse processes started by the CLI can now be recovered via OS-level process inspection when their metadata files are lost. Adds --global flag to server list/stop/stop-all for cross-project server management. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Recovery only ran inside list_all_servers(), so start/stop/remove still relied on metadata-only checks. An orphaned server (live process, missing JSON) could have its data directory deleted by remove, be launched over by start, or be unreachable by stop unless server list ran first. Now each command entry point calls recover_current_project_servers() before any metadata-dependent logic. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Both functions sent SIGTERM/SIGKILL but returned Ok(()) without checking whether the process actually exited. Permission failures (EPERM) and stubborn processes would be silently reported as stopped. Extract shared kill_process() that checks the return value of each libc::kill call and verifies the process is no longer alive after SIGKILL before returning Ok. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
macOS lsof OR's options by default. Without -a, `lsof -d cwd -p <pid>` means "all cwd entries for all processes OR all entries for <pid>", dumping thousands of entries. The parser grabbed the first n-prefixed line (n/ from init), which never matched the server cwd pattern, so no servers were ever discovered. Adding -a ANDs the conditions so only the cwd of the target PID is returned. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
--global is for system-wide maintenance, not normal workflow. Agent context sections should not mention it (per CLAUDE.md convention), and the flag descriptions now explicitly steer agents toward the default project-scoped behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
iskakaushik
approved these changes
Apr 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #102 #89
src/local/discovery.rs): Finds running ClickHouse processes viapgrep, resolves their cwd (macOS:lsof, Linux:/proc/<pid>/cwd), and parses command-line args to extract ports and version. Only processes whose cwd matches.clickhouse/servers/<name>/data/are recognized as CLI-managed.server list,server start, and other server commands automatically run process discovery on the current project. If a running ClickHouse process has no metadata file, aServerInfois recovered and saved so it appears in listings and can be managed normally.--globalflag onserver list: Shows all running ClickHouse servers across all projects with a Project column indicating which directory each belongs to.--globalflag onserver stop: Stops a server from any project by name. If the name is ambiguous across projects,--projectcan disambiguate.--globalflag onserver stop-all: Stops every CLI-managed ClickHouse process system-wide.Test plan
cargo clippycleanparse_server_cwd,parse_port_flag,parse_version_from_cmdline).jsonmetadata file, runserver list→ server should be recoveredserver list --globalfrom either → both shownserver stop-all --globalkills all servers across projectsserver stop <name> --global --project /pathtargets the correct server when names collide🤖 Generated with Claude Code