MCPcopy
hub / github.com/xpf0000/FlyEnv / stopAllService

Method stopAllService

src/main/core/MCPTools.ts:580–611  ·  view source on GitHub ↗

停掉某模块当前登记的所有运行实例

(flag: string)

Source from the content-addressed store, hash-verified

578
579 /** 停掉某模块当前登记的所有运行实例 */
580 async stopAllService(flag: string): Promise<any> {
581 this.assertLifecycleFlag(flag, 'stop')
582 const running = ServiceProcessManager.statusOf(flag).instances
583 if (running.length === 0) {
584 // 没有登记在案的实例,尝试用任一已装版本触发一次 stop(兜底)
585 const v = await this.pickVersion(flag).catch(() => null)
586 if (v) await callFork(this.forkManager, flag, 'stopService', v)
587 ServiceProcessManager.delAll(flag)
588 return { stopped: [] }
589 }
590 const raw = await this.rawServiceVersions(flag)
591 const stopped: string[] = []
592 const stoppedBins: string[] = []
593 const failed: string[] = []
594 for (const ins of running) {
595 // 用完整版本对象(含 bin/path)停,匹配不到则用最小对象兜底
596 const full = raw.find((r: any) => r.bin === ins.bin) ?? { ...ins, typeFlag: flag }
597 try {
598 await callFork(this.forkManager, flag, 'stopService', full)
599 stopped.push(ins.version ?? ins.bin)
600 stoppedBins.push(ins.bin)
601 } catch (e) {
602 // 单个失败不阻断其它
603 console.log(`stopAllService ${flag} ${ins.version} error:`, e)
604 failed.push(ins.version ?? ins.bin)
605 }
606 }
607 if (stoppedBins.length > 0) {
608 ServiceProcessManager.delByBin(flag, stoppedBins)
609 }
610 return { stopped, failed }
611 }
612
613 async restartService(flag: string, version?: string): Promise<any> {
614 this.assertLifecycleFlag(flag, 'restart')

Calls 10

assertLifecycleFlagMethod · 0.95
pickVersionMethod · 0.95
rawServiceVersionsMethod · 0.95
statusOfMethod · 0.80
catchMethod · 0.80
delAllMethod · 0.80
pushMethod · 0.80
delByBinMethod · 0.80
callForkFunction · 0.70
logMethod · 0.45

Tested by

no test coverage detected