MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / handleKillCommand

Function handleKillCommand

apps/kimi-code/src/cli/sub/server/kill.ts:61–97  ·  view source on GitHub ↗
(deps: KillCommandDeps)

Source from the content-addressed store, hash-verified

59}
60
61export async function handleKillCommand(deps: KillCommandDeps): Promise<void> {
62 const lock = deps.getLiveLock();
63 if (!lock) {
64 deps.stdout.write('No running Kimi server.\n');
65 return;
66 }
67
68 const { pid } = lock;
69 const origin = serverOrigin(lockConnectHost(lock), lock.port);
70
71 // 1. API path — best-effort graceful shutdown. Ignore every outcome: the
72 // server may be an older build without the route, already wedged, or may
73 // drop the connection as it exits. The bearer token (M5.1) is best-effort
74 // too: if it can't be read the API call 401s and the PID path below still
75 // guarantees the kill.
76 const token = deps.resolveToken();
77 await deps.requestShutdown(origin, token).catch(() => {});
78
79 // 2. PID path — SIGTERM, wait, then SIGKILL.
80 deps.signalPid(pid, 'SIGTERM');
81
82 if (await waitForExit(pid, TERM_GRACE_MS, deps)) {
83 deps.stdout.write(`Kimi server (pid ${String(pid)}) stopped.\n`);
84 return;
85 }
86
87 deps.signalPid(pid, 'SIGKILL');
88
89 if (await waitForExit(pid, KILL_GRACE_MS, deps)) {
90 deps.stdout.write(`Kimi server (pid ${String(pid)}) killed.\n`);
91 return;
92 }
93
94 throw new Error(
95 `Failed to stop Kimi server (pid ${String(pid)}); insufficient permissions?`,
96 );
97}
98
99async function waitForExit(
100 pid: number,

Callers 2

server.test.tsFile · 0.85
registerKillCommandFunction · 0.85

Calls 8

serverOriginFunction · 0.90
lockConnectHostFunction · 0.90
waitForExitFunction · 0.85
getLiveLockMethod · 0.80
resolveTokenMethod · 0.80
signalPidMethod · 0.80
writeMethod · 0.65
requestShutdownMethod · 0.65

Tested by

no test coverage detected