Files
claude-code-router/src/utils/close.ts
jinhui.li 2cc91ada5c add cli
2025-06-10 12:55:25 +08:00

24 lines
721 B
TypeScript

import { isServiceRunning, cleanupPidFile } from './processCheck';
import { existsSync, readFileSync } from 'fs';
import { homedir } from 'os';
import { join } from 'path';
export async function closeService() {
const PID_FILE = join(homedir(), '.claude-code-router.pid');
if (!isServiceRunning()) {
console.log("No service is currently running.");
return;
}
try {
const pid = parseInt(readFileSync(PID_FILE, 'utf-8'));
process.kill(pid);
cleanupPidFile();
console.log("Service has been successfully stopped.");
} catch (e) {
console.log("Failed to stop the service. It may have already been stopped.");
cleanupPidFile();
}
}