| 455 | public.M("sites").where('id=?', (data['id'],)).update({'project_config': json.dumps(data['project_config'])}) |
| 456 | |
| 457 | def add_service(self, service_conf: dict) -> Optional[str]: |
| 458 | try: |
| 459 | conf = { |
| 460 | "name": service_conf.get("name", "").strip(), |
| 461 | "command": service_conf.get("command", "").strip(), |
| 462 | "level": int(service_conf.get("level", 11)), |
| 463 | "log_type": service_conf.get("log_type", "append"), |
| 464 | } |
| 465 | except: |
| 466 | return "参数错误" |
| 467 | |
| 468 | if re.search(r"[\s$^`]+", conf['name']): |
| 469 | return "服务名不能包含空格等特殊符号" |
| 470 | |
| 471 | for i in self.other_services: |
| 472 | if i['name'] == conf['name']: |
| 473 | return "服务名不能重复" |
| 474 | if i['command'] == conf['command']: |
| 475 | return "该启动命令已存在,服务名为:{}".format(i['name']) |
| 476 | |
| 477 | if not (conf['name'] and conf['command']): |
| 478 | return "服务名称和启动命令不能为空" |
| 479 | |
| 480 | conf["sid"] = self.new_id() |
| 481 | |
| 482 | self.other_services.append(conf) |
| 483 | self.save_service_conf() |
| 484 | |
| 485 | def modify_service(self, sid: str, service_conf: dict) -> Optional[str]: |
| 486 | target_data = None |