123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import os
- import sys
- import requests
- # 关闭服务进程
- def server_killer(port):
- # 判断port数据类型
- if isinstance(port, int):
- app_server = os.popen("lsof -i:{}".format(port)).readlines()
- else:
- app_server = os.popen("ps ax|grep {}|grep -v grep".format(port)).readlines()
- # 判断服务是否运行
- if app_server:
- if port == 8858:
- # 保存HNSW模型更新数据
- url = r"http://localhost:8858/hnsw/update"
- save_res = requests.post(url, json="save").json()
- print(save_res)
- # 获取端口进程号
- app_pid = app_server[1].split()[1] if isinstance(port, int) else app_server[0].split()[0]
- app_killer = "kill -9 " + str(app_pid)
- # 关闭服务进程
- os.popen(app_killer)
- # 重启math_dup_app服务(重启之前需要先保存当前正在运行的HNSW模型)
- def restart_math_dup_app():
- # 关闭服务进程
- server_killer(port=8855)
- print("即将启动math_dup_app服务")
- # 启动服务
- # os.popen("nohup python math_dup_app.py >> logs/math_dup_app.log 2>&1 &")
- os.popen("gunicorn -c guc_conf.py math_dup_app:app")
- # 重启rlt_app服务
- def restart_rlt_ddc_app():
- # 关闭服务进程
- server_killer(port=8856)
- print("即将启动rlt_dcc_app服务")
- # 启动服务
- os.popen("nohup python rlt_ddc_app.py >> logs/rlt_ddc_app.log 2>&1 &")
- # 重启hnsw_app服务
- def restart_hnsw_app():
- # 关闭服务进程
- server_killer(port=8858)
- print("即将启动hnsw_app服务")
- # 启动服务
- os.popen("nohup python hnsw_app.py > logs/temp_app.log 2>&1 &")
- # 重启math_dup_monitor服务
- def restart_math_dup_monitor():
- # 关闭服务进程
- server_killer(port="math_dup_monitor")
- print("即将启动math_dup_monitor服务")
- # 启动服务
- os.popen("nohup python math_dup_monitor.py >> logs/temp_app.log 2>&1 &")
- if __name__ == "__main__":
- # 重启服务
- server_list = [restart_math_dup_app, restart_rlt_ddc_app, restart_hnsw_app, restart_math_dup_monitor]
- argv_list = sys.argv
- if len(argv_list) == 1:
- [server() for server in server_list]
- else:
- server_list[int(argv_list[1])]()
|