12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import os
- import sys
- # 关闭服务进程
- 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:
- # 获取端口进程号
- 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)
- # 重启retrieval_app服务
- def restart_retrieval_app():
- # 关闭服务进程
- server_killer(port=8835)
- print("即将启动retrieval_app服务")
- # 启动服务
- # os.popen("nohup python retrieval_app.py >> logs/retrieval_app.log 2>&1 &")
- os.popen("gunicorn -c guc_conf.py retrieval_app:app")
- # 重启hnsw_app服务
- def restart_hnsw_app():
- # 关闭服务进程
- server_killer(port=8836)
- print("即将启动hnsw_app服务")
- # 启动服务
- os.popen("nohup python hnsw_app.py > logs/temp_app.log 2>&1 &")
- # 重启retrieval_monitor服务
- def restart_retrieval_monitor():
- # 关闭服务进程
- server_killer(port="retrieval_monitor")
- print("即将启动retrieval_monitor服务")
- # 启动服务
- os.popen("nohup python retrieval_monitor.py > logs/temp_app.log 2>&1 &")
- if __name__ == "__main__":
- # 重启服务
- server_list = [restart_retrieval_app, restart_hnsw_app, restart_retrieval_monitor]
- argv_list = sys.argv
- if len(argv_list) == 1:
- [server() for server in server_list]
- else:
- server_list[int(argv_list[1])]()
|