MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / handle_service

Method handle_service

mod/project/python/serviceMod.py:557–589  ·  view source on GitHub ↗
(self, sid: str, action: str = "start")

Source from the content-addressed store, hash-verified

555 return PythonService.from_config(conf, env=self._env)
556
557 def handle_service(self, sid: str, action: str = "start") -> Optional[str]:
558 public.print_log(action)
559 conf = self._get_service_conf_by_sid(sid)
560 if conf is None:
561 return "未找到该服务"
562
563 service = self._build_service_by_conf(conf)
564 if isinstance(service, str):
565 return service
566 pid = service.get_service_pid()
567 if not pid:
568 pid = -1
569 if action == "start":
570 if not psutil.pid_exists(pid):
571 service.start()
572 elif action == "stop":
573 service.stop()
574 elif action == "restart":
575 if psutil.pid_exists(pid):
576 service.stop()
577 for i in range(50):
578 if not psutil.pid_exists(pid):
579 break
580 time.sleep(0.1)
581 else:
582 service.stop()
583 time.sleep(1)
584
585 service.start()
586 else:
587 return "未知操作"
588
589 return None
590
591 def get_service_log(self, sid: str) -> Tuple[bool, str]:
592 conf = self._get_service_conf_by_sid(sid)

Callers

nothing calls this directly

Calls 7

print_logMethod · 0.45
get_service_pidMethod · 0.45
pid_existsMethod · 0.45
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected