restart_server.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import os
  2. import sys
  3. import requests
  4. # 关闭服务进程
  5. def server_killer(port):
  6. # 判断port数据类型
  7. if isinstance(port, int):
  8. app_server = os.popen("lsof -i:{}".format(port)).readlines()
  9. else:
  10. app_server = os.popen("ps ax|grep {}|grep -v grep".format(port)).readlines()
  11. # 判断服务是否运行
  12. if app_server:
  13. if port == 8858:
  14. # 保存HNSW模型更新数据
  15. url = r"http://localhost:8858/hnsw/update"
  16. save_res = requests.post(url, json="save").json()
  17. print(save_res)
  18. # 获取端口进程号
  19. app_pid = app_server[1].split()[1] if isinstance(port, int) else app_server[0].split()[0]
  20. app_killer = "kill -9 " + str(app_pid)
  21. # 关闭服务进程
  22. os.popen(app_killer)
  23. # 重启math_dup_app服务(重启之前需要先保存当前正在运行的HNSW模型)
  24. def restart_math_dup_app():
  25. # 关闭服务进程
  26. server_killer(port=8855)
  27. print("即将启动math_dup_app服务")
  28. # 启动服务
  29. # os.popen("nohup python math_dup_app.py >> logs/math_dup_app.log 2>&1 &")
  30. os.popen("gunicorn -c guc_conf.py math_dup_app:app")
  31. # 重启rlt_app服务
  32. def restart_rlt_ddc_app():
  33. # 关闭服务进程
  34. server_killer(port=8856)
  35. print("即将启动rlt_dcc_app服务")
  36. # 启动服务
  37. os.popen("nohup python rlt_ddc_app.py >> logs/rlt_ddc_app.log 2>&1 &")
  38. # 重启hnsw_app服务
  39. def restart_hnsw_app():
  40. # 关闭服务进程
  41. server_killer(port=8858)
  42. print("即将启动hnsw_app服务")
  43. # 启动服务
  44. os.popen("nohup python hnsw_app.py > logs/temp_app.log 2>&1 &")
  45. # 重启math_dup_monitor服务
  46. def restart_math_dup_monitor():
  47. # 关闭服务进程
  48. server_killer(port="math_dup_monitor")
  49. print("即将启动math_dup_monitor服务")
  50. # 启动服务
  51. os.popen("nohup python math_dup_monitor.py >> logs/temp_app.log 2>&1 &")
  52. if __name__ == "__main__":
  53. # 重启服务
  54. server_list = [restart_math_dup_app, restart_rlt_ddc_app, restart_hnsw_app, restart_math_dup_monitor]
  55. argv_list = sys.argv
  56. if len(argv_list) == 1:
  57. [server() for server in server_list]
  58. else:
  59. server_list[int(argv_list[1])]()