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

Method remove_project

mod/project/java/projectMod.py:2446–2510  ·  view source on GitHub ↗

删除指定项目

(self, get)

Source from the content-addressed store, hash-verified

2444 return json_response(True, msg = "设置成功")
2445
2446 def remove_project(self, get):
2447 """删除指定项目"""
2448 try:
2449 project_data = self.get_project_find(get.project_name.strip())
2450 except:
2451 return json_response(False, '参数错误')
2452
2453 if not project_data:
2454 return json_response(False, '指定项目不存在: {}'.format(get.project_name))
2455
2456 project_config = project_data["project_config"]
2457 project_name = project_data["name"]
2458 if project_config['java_type'] == 'duli':
2459 if project_config.get("tomcat_name", ""):
2460 tomcat = utils.site_tomcat(project_config["tomcat_name"])
2461 else:
2462 tomcat = utils.site_tomcat(project_name)
2463 # 关闭独立项目
2464 if tomcat:
2465 tomcat.stop()
2466 tomcat.remove_service()
2467 if os.path.exists(path = tomcat.path):
2468 shutil.rmtree(tomcat.path)
2469
2470 elif project_config['java_type'] == 'neizhi':
2471 # 删除tomcat站点
2472 try:
2473 domains = project_config.get("domains", project_config.get("domain", ""))
2474 domain = (domains[0] if isinstance(domains, list) and domains else domains).rsplit(":", 1)[0]
2475 tomcat = utils.bt_tomcat(project_config["tomcat_version"])
2476 tomcat.remove_host(domain, project_name)
2477 tomcat.save_config_xml()
2478 if tomcat.running():
2479 tomcat.restart()
2480 except:
2481 return json_response(False, '删除Tomcat配置失败,请尝试修复Tomcat后再次删除项目')
2482
2483 elif project_config['java_type'] == 'springboot':
2484 # 停止项目
2485 server_name = self._get_systemd_server_name(project_config)
2486 s_admin = RealServer()
2487 s_admin.daemon_admin(server_name, "stop")
2488 s_admin.del_daemon(server_name)
2489
2490 pid_file = project_config['pids']
2491 if os.path.exists(pid_file):
2492 os.remove(pid_file)
2493 script_file = project_config['scripts']
2494 if os.path.exists(script_file):
2495 os.remove(script_file)
2496 env_path = "{}/env/{}.env".format(self._java_project_vhost, project_config["project_name"])
2497 if os.path.exists(env_path):
2498 os.remove(env_path)
2499 log_file = project_config['logs']
2500 if os.path.exists(log_file):
2501 os.remove(log_file)
2502 else:
2503 return json_response(False, '项目类型错误')

Callers 1

create_projectMethod · 0.95

Calls 15

get_project_findMethod · 0.95
daemon_adminMethod · 0.95
del_daemonMethod · 0.95
write_project_logMethod · 0.95
json_responseFunction · 0.90
RealServerClass · 0.90
save_config_xmlMethod · 0.80
formatMethod · 0.45
getMethod · 0.45
stopMethod · 0.45
remove_serviceMethod · 0.45

Tested by

no test coverage detected