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

Method stop_old

mod/project/java/project_update.py:333–374  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

331 return {"status": True, "msg": "停止新实例成功,项目更新已结束"}
332
333 def stop_old(self):
334 self.keep_status[3]["status"] = -1
335 ng_file = "/www/server/panel/vhost/nginx/java_{}.conf".format(self.project_name)
336 ng_data = public.readFile(ng_file)
337 if not isinstance(ng_data, str):
338 return "Nginx配置文件读取错误,无法取消轮询,使用新实例"
339
340 res = public.checkWebConfig()
341 if res is not True:
342 return "Nginx配置文件错误,无法取消轮询,使用新实例"
343
344 old_proxy_res = None
345 for tmp_res in re.finditer(r"\s*proxy_pass\s+(?P<url>\S+)\s*;", ng_data, re.M):
346 if tmp_res.group("url").find("{}_backend".format(self.project_name)):
347 old_proxy_res = tmp_res
348
349 if not old_proxy_res:
350 return "未找到轮询的代理配置"
351
352 upstream_file = "/www/server/panel/vhost/nginx/java_{}_upstream.conf".format(self.project_name)
353 if os.path.isfile(upstream_file):
354 os.remove(upstream_file)
355
356 new_config = ng_data.replace(old_proxy_res.group(), "\n proxy_pass {}://127.0.0.1:{};".format(
357 self.proxy_data["scheme"], self.new_port))
358
359 public.writeFile(ng_file, new_config)
360
361 res = public.checkWebConfig()
362 if res is not True:
363 public.writeFile(ng_file, ng_data)
364 return "Nginx配置文件错误,无法结束轮询配置"
365 else:
366 public.serviceReload()
367
368 old_server_name = "spring_" + self.project_name + self.old_project_config.get("server_name_suffix", "")
369 RealServer().server_admin(old_server_name, "stop")
370 RealServer().del_daemon(old_server_name)
371 if self.old_pro and self.old_pro.is_running():
372 self.old_pro.kill()
373
374 return None
375
376 def keep_update(self):
377 pid_file = "{}/{}.pid".format(self.keep_path, self.project_name)

Callers 2

run_taskMethod · 0.95
select_new_or_oldMethod · 0.95

Calls 13

RealServerClass · 0.90
readFileMethod · 0.80
writeFileMethod · 0.80
killMethod · 0.80
formatMethod · 0.45
findMethod · 0.45
groupMethod · 0.45
removeMethod · 0.45
replaceMethod · 0.45
getMethod · 0.45
server_adminMethod · 0.45
del_daemonMethod · 0.45

Tested by

no test coverage detected