(self, sid: str, action: str = "start")
| 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) |
nothing calls this directly
no test coverage detected