Implementation:1mcp app Agent runServeStop
| Knowledge Sources | |
|---|---|
| Domains | Process_Management, CLI |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete CLI command for gracefully stopping a 1MCP runtime with signal escalation (SIGTERM to SIGKILL), PID file cleanup, and supervisor state clearing.
Description
The runServeStop function implements `serve --stop`. It resolves the runtime scope, reads the PID file, sends SIGTERM to the process, waits for exit with a configurable timeout, and escalates to SIGKILL if the process does not exit. It cleans up the PID file, supervisor state, and ownership record. It supports both cooperative runtime stop (via drain) and legacy runtime stop.
Usage
Import this function when you need to:
- Gracefully stop a running 1MCP runtime
- Wait for process exit with timeout and SIGKILL escalation
- Clean up PID files and supervisor state after stop
- Stop a cooperative runtime via drain or a legacy runtime directly
Code Reference
Source Location
- Repository: 1MCP Agent
- File: src/commands/serve/serveStop.ts (L57-177), src/commands/serve/cooperativeRuntime.ts (L713)
Signature
export async function runServeStop(
configDirOption?: string,
deps?: RunStopDeps,
): Promise<void>;
export async function waitForProcessExit(
pid: number,
options?: WaitForExitOptions,
): Promise<boolean>;
export async function stopCooperativeRuntime(scope: string): Promise<boolean>;
export async function stopLegacyRuntime(scope: string): Promise<void>;
interface WaitForExitOptions {
timeoutMs?: number; // default: 10000
intervalMs?: number; // default: 200
kill?: (pid: number, signal: 'SIGTERM' | 'SIGKILL') => void;
}
Import
import { runServeStop, waitForProcessExit } from '@src/commands/serve/serveStop.js';
import { stopCooperativeRuntime } from '@src/commands/serve/cooperativeRuntime.js';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| configDirOption | string | No | Config directory |
| pid | number | Yes | Process ID to stop |
| timeoutMs | number | No | Exit wait timeout (default: 10000) |
Outputs
| Name | Type | Description |
|---|---|---|
| exit code | number | 0 on success |
| PID file | cleaned | Removed after stop |
Usage Examples
Stop Runtime
1mcp serve --stop
1mcp serve --stop --config-dir /custom/dir