retrieval_monitor.py 866 B

12345678910111213141516171819202122
  1. import os
  2. import time
  3. def server_run(port, command):
  4. # 设置服务缓存时间(防止更新服务产生冲突)
  5. time.sleep(12) if port == 8836 else time.sleep(8)
  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 &")