docs: document daemon process management commands
Update README.md and CLAUDE.md to document new process management: - Add "Process Management" section with daemon commands - Update all examples to use `./kvs start/stop/status` instead of `&` and `pkill` - Document global PID/log directories (~/.kvs/) - Update cluster setup examples - Update development workflow - Add daemon package to project structure 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
76
CLAUDE.md
76
CLAUDE.md
@@ -10,10 +10,16 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
||||
go build -o kvs .
|
||||
|
||||
# Run with default config (auto-generates config.yaml)
|
||||
./kvs
|
||||
./kvs start config.yaml
|
||||
|
||||
# Run with custom config
|
||||
./kvs /path/to/config.yaml
|
||||
./kvs start /path/to/config.yaml
|
||||
|
||||
# Check running instances
|
||||
./kvs status
|
||||
|
||||
# Stop instance
|
||||
./kvs stop config
|
||||
|
||||
# Run comprehensive integration tests
|
||||
./integration_test.sh
|
||||
@@ -25,6 +31,32 @@ go run test_conflict.go data1 data2
|
||||
go build -o kvs . && ./integration_test.sh
|
||||
```
|
||||
|
||||
### Process Management Commands
|
||||
```bash
|
||||
# Start as background daemon
|
||||
./kvs start <config.yaml> # .yaml extension optional
|
||||
|
||||
# Stop daemon
|
||||
./kvs stop <config> # Graceful SIGTERM shutdown
|
||||
|
||||
# Restart daemon
|
||||
./kvs restart <config> # Stop then start
|
||||
|
||||
# Show status
|
||||
./kvs status # All instances
|
||||
./kvs status <config> # Specific instance
|
||||
|
||||
# Run in foreground (for debugging)
|
||||
./kvs <config.yaml> # Logs to stdout, blocks terminal
|
||||
|
||||
# View daemon logs
|
||||
tail -f ~/.kvs/logs/kvs_<config>.yaml.log
|
||||
|
||||
# Global state directories
|
||||
~/.kvs/pids/ # PID files (works from any directory)
|
||||
~/.kvs/logs/ # Daemon log files
|
||||
```
|
||||
|
||||
### Development Workflow
|
||||
```bash
|
||||
# Format and check code
|
||||
@@ -38,11 +70,25 @@ go mod tidy
|
||||
go build .
|
||||
|
||||
# Test specific cluster scenarios
|
||||
./kvs node1.yaml & # Terminal 1
|
||||
./kvs node2.yaml & # Terminal 2
|
||||
./kvs start node1.yaml
|
||||
./kvs start node2.yaml
|
||||
|
||||
# Wait for cluster formation
|
||||
sleep 5
|
||||
|
||||
# Test data operations
|
||||
curl -X PUT http://localhost:8081/kv/test/data -H "Content-Type: application/json" -d '{"test":"data"}'
|
||||
curl http://localhost:8082/kv/test/data # Should replicate within ~30 seconds
|
||||
pkill kvs
|
||||
|
||||
# Check daemon status
|
||||
./kvs status
|
||||
|
||||
# View logs
|
||||
tail -f ~/.kvs/logs/kvs_node1.yaml.log
|
||||
|
||||
# Cleanup
|
||||
./kvs stop node1
|
||||
./kvs stop node2
|
||||
```
|
||||
|
||||
## Architecture Overview
|
||||
@@ -58,7 +104,8 @@ KVS is a **distributed, eventually consistent key-value store** built around thr
|
||||
|
||||
#### Modular Package Design
|
||||
- **`auth/`** - Complete JWT authentication system with POSIX-inspired permissions
|
||||
- **`cluster/`** - Distributed systems logic (gossip, sync, merkle trees)
|
||||
- **`cluster/`** - Distributed systems logic (gossip, sync, merkle trees)
|
||||
- **`daemon/`** - Process management (daemonization, PID files, lifecycle)
|
||||
- **`storage/`** - BadgerDB abstraction with compression and revision history
|
||||
- **`server/`** - HTTP handlers, routing, and lifecycle management
|
||||
- **`features/`** - Utility functions for TTL, rate limiting, tamper logging, backup
|
||||
@@ -147,9 +194,18 @@ Creates two BadgerDB instances with intentionally conflicting data (same path, s
|
||||
- **Bootstrap sync**: Up to 30 days of historical data for new nodes
|
||||
|
||||
#### Main Entry Point Flow
|
||||
1. `main.go` loads config (auto-generates default if missing)
|
||||
2. `server.NewServer()` initializes all subsystems
|
||||
3. Graceful shutdown handling with `SIGINT`/`SIGTERM`
|
||||
4. All business logic delegated to modular packages
|
||||
1. `main.go` parses command-line arguments for subcommands (`start`, `stop`, `status`, `restart`)
|
||||
2. For daemon mode: `daemon.Daemonize()` spawns background process and manages PID files
|
||||
3. For server mode: loads config (auto-generates default if missing)
|
||||
4. `server.NewServer()` initializes all subsystems
|
||||
5. Graceful shutdown handling with `SIGINT`/`SIGTERM`
|
||||
6. All business logic delegated to modular packages
|
||||
|
||||
#### Daemon Architecture
|
||||
- **PID Management**: Global PID files stored in `~/.kvs/pids/` for cross-directory access
|
||||
- **Logging**: Daemon logs written to `~/.kvs/logs/{config-name}.log`
|
||||
- **Process Lifecycle**: Spawns detached process via `exec.Command()` with `Setsid: true`
|
||||
- **Config Normalization**: Supports both `node1` and `node1.yaml` formats
|
||||
- **Stale PID Detection**: Checks process existence via `Signal(0)` before operations
|
||||
|
||||
This architecture enables easy feature addition, comprehensive testing, and reliable operation in distributed environments while maintaining simplicity for single-node deployments.
|
Reference in New Issue
Block a user