MCPcopy Create free account
hub / github.com/tiann/hapi / stopRunner

Function stopRunner

cli/src/runner/controlClient.ts:278–310  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

276}
277
278export async function stopRunner() {
279 try {
280 const state = await readRunnerState();
281 if (!state) {
282 logger.debug('No runner state found');
283 return;
284 }
285
286 logger.debug(`Stopping runner with PID ${state.pid}`);
287
288 // Try HTTP graceful stop
289 try {
290 await stopRunnerHttp();
291
292 // Wait for runner to die
293 await waitForProcessDeath(state.pid, 2000);
294 logger.debug('Runner stopped gracefully via HTTP');
295 return;
296 } catch (error) {
297 logger.debug('HTTP stop failed, will force kill', error);
298 }
299
300 // Force kill
301 const killed = await killProcess(state.pid, true);
302 if (killed) {
303 logger.debug('Force killed runner');
304 } else {
305 logger.debug('Runner already dead or could not be killed');
306 }
307 } catch (error) {
308 logger.debug('Error stopping runner', error);
309 }
310}
311
312async function waitForProcessDeath(pid: number, timeout: number): Promise<void> {
313 const start = Date.now();

Callers 3

startRunnerFunction · 0.90
runner.tsFile · 0.90

Calls 5

readRunnerStateFunction · 0.90
killProcessFunction · 0.90
stopRunnerHttpFunction · 0.85
waitForProcessDeathFunction · 0.85
debugMethod · 0.80

Tested by

no test coverage detected