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

Method modify_service

mod/project/python/serviceMod.py:485–524  ·  view source on GitHub ↗
(self, sid: str, service_conf: dict)

Source from the content-addressed store, hash-verified

483 self.save_service_conf()
484
485 def modify_service(self, sid: str, service_conf: dict) -> Optional[str]:
486 target_data = None
487 for i in self.other_services:
488 if i["sid"] == sid:
489 target_data = i
490 break
491 if target_data is None:
492 return "未找到该服务"
493
494 name = target_data["name"]
495 if "name" in service_conf and service_conf["name"] != target_data["name"]:
496 name = service_conf["name"].strip()
497 if re.search(r"[\s$^`]+", name):
498 return "服务名不能包含空格等特殊符号"
499 command = target_data["command"]
500 if "command" in service_conf and service_conf["command"] != target_data["command"]:
501 command = service_conf["command"].strip()
502
503 for i in self.other_services:
504 if i["sid"] == sid:
505 continue
506 if i["name"] == name:
507 return "服务名不能重复"
508 if i["command"] == command:
509 return "该启动命令已存在,服务名为:{}".format(i["name"])
510
511 if name != target_data["name"]:
512 log_file = os.path.join(SERVICE_PATH, '{}/{}.log'.format(self.project_name, target_data["name"]))
513 pid_file = os.path.join(SERVICE_PATH, '{}/{}.pid'.format(self.project_name, target_data["name"]))
514 if os.path.exists(log_file):
515 os.rename(log_file, os.path.join(SERVICE_PATH, '{}/{}.log'.format(self.project_name, name)))
516 if os.path.exists(pid_file):
517 os.rename(pid_file, os.path.join(SERVICE_PATH, '{}/{}.pid'.format(self.project_name, name)))
518
519 target_data["name"] = name
520
521 target_data["command"] = command
522 target_data["level"] = int(service_conf.get("level", target_data["level"]))
523 target_data["log_type"] = service_conf.get("log_type", target_data["log_type"])
524 self.save_service_conf()
525
526 def remove_service(self, sid: str) -> Optional[str]:
527 del_idx = None

Callers

nothing calls this directly

Calls 7

save_service_confMethod · 0.95
searchMethod · 0.45
formatMethod · 0.45
joinMethod · 0.45
existsMethod · 0.45
renameMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected