retrieval_monitor.py 1023 B

1234567891011121314151617181920212223242526
  1. import os
  2. import time
  3. def server_run(port, command):
  4. # 设置服务缓存时间(防止更新服务产生冲突)
  5. time.sleep(12)
  6. server = os.popen("lsof -i:{}".format(port)).readlines()
  7. if not server:
  8. print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()),
  9. "即将启动{}端口服务".format(port))
  10. # 启动服务
  11. os.popen(command)
  12. while True:
  13. retrieval_app_server = os.popen("lsof -i:8835").readlines()
  14. if not retrieval_app_server:
  15. # server_run(8835, "nohup python retrieval_app.py >> logs/retrieval_app.log 2>&1 &")
  16. server_run(8835, "gunicorn -c guc_conf.py retrieval_app:app")
  17. hnsw_app_server = os.popen("lsof -i:8836").readlines()
  18. if not hnsw_app_server:
  19. server_run(8836, "nohup python hnsw_app.py > logs/temp_app.log 2>&1 &")
  20. dim_classify_app_server = os.popen("lsof -i:8837").readlines()
  21. if not dim_classify_app_server:
  22. server_run(8837, "nohup python dim_classify_app.py > logs/temp_app.log 2>&1 &")