feat: add graceful shutdown endpoint and cli service management

- Add /shutdown endpoint for graceful server shutdown
- Add 'aha ps' command to list running services
- Add comprehensive API documentation for shutdown endpoint
- Enhance CLI with --allow-remote-shutdown flag
- Implement process management module with service discovery
- Add graceful shutdown handling for Ctrl+C signals
This commit is contained in:
XiaoYang
2026-02-08 13:24:29 +08:00
parent 390d916ea6
commit ba16c9edf5
10 changed files with 793 additions and 21 deletions
+60 -5
View File
@@ -113,11 +113,11 @@ aha run -m qwen3asr-0.6b -i "audio.wav" --weight-path /path/to/model
### serv - Start service
Start HTTP service only, without downloading models. Must specify local model path via `--weight-path`.
Start HTTP service with a model. The `--weight-path` is optional - if not specified, it defaults to `~/.aha/{model_id}`.
**Syntax:**
```bash
aha serv [OPTIONS] --model <MODEL> --weight-path <WEIGHT_PATH>
aha serv [OPTIONS] --model <MODEL> [--weight-path <WEIGHT_PATH>]
```
**Options:**
@@ -127,21 +127,69 @@ aha serv [OPTIONS] --model <MODEL> --weight-path <WEIGHT_PATH>
| `-a, --address <ADDRESS>` | Service listen address | 127.0.0.1 |
| `-p, --port <PORT>` | Service listen port | 10100 |
| `-m, --model <MODEL>` | Model type (required) | - |
| `--weight-path <WEIGHT_PATH>` | Local model weight path (required) | - |
| `--weight-path <WEIGHT_PATH>` | Local model weight path (optional) | ~/.aha/{model_id} |
| `--allow-remote-shutdown` | Allow remote shutdown requests (not recommended) | false |
**Examples:**
```bash
# Start service with default model path (~/.aha/{model_id})
aha serv -m qwen3vl-2b
# Start service with local model
aha serv -m qwen3vl-2b --weight-path /path/to/model
# Start with specified port
aha serv -m qwen3vl-2b --weight-path /path/to/model -p 8080
aha serv -m qwen3vl-2b -p 8080
# Specify listen address
aha serv -m qwen3vl-2b --weight-path /path/to/model -a 0.0.0.0
aha serv -m qwen3vl-2b -a 0.0.0.0
# Enable remote shutdown (not recommended for production)
aha serv -m qwen3vl-2b --allow-remote-shutdown
```
### ps - List running services
List all currently running AHA services with their process IDs, ports, and status.
**Syntax:**
```bash
aha ps [OPTIONS]
```
**Options:**
| Option | Description | Default |
|--------|-------------|---------|
| `-c, --compact` | Compact output format (show service IDs only) | false |
**Examples:**
```bash
# List all running services (table format)
aha ps
# Compact output (service IDs only)
aha ps -c
```
**Output Format:**
```
Service ID PID Model Port Address Status
-------------------------------------------------------------------------------------
56860@10100 56860 N/A 10100 127.0.0.1 Running
```
**Fields:**
- `Service ID`: Unique identifier in format `pid@port`
- `PID`: Process ID
- `Model`: Model name (N/A if not detected)
- `Port`: Service port number
- `Address`: Service listen address
- `Status`: Service status (Running, Stopping, Unknown)
### download - Download model
Download the specified model only, without starting the service.
@@ -254,6 +302,13 @@ After the service starts, the following API endpoints are available:
- **Format**: OpenAI Chat Completion format
- **Streaming Support**: No
### Shutdown Endpoint
- **Endpoint**: `POST /shutdown`
- **Function**: Gracefully shut down the server
- **Security**: Localhost only by default, use `--allow-remote-shutdown` flag to enable remote access (not recommended)
- **Format**: JSON response
## Backward Compatibility
To maintain compatibility with older versions, the following two usage methods are equivalent: