math_dup_monitor.py 1.2 KB

1234567891011121314151617181920212223242526272829
  1. import os
  2. import time
  3. import datetime
  4. def server_run(port, command):
  5. # 设置服务缓存时间(防止更新服务产生冲突)
  6. time.sleep(12) if port == 8858 else time.sleep(8)
  7. server = os.popen("lsof -i:{}".format(port)).readlines()
  8. if not server:
  9. print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()),
  10. "即将启动{}端口服务".format(port))
  11. # 启动服务
  12. os.popen(command)
  13. while True:
  14. math_dup_app_server = os.popen("lsof -i:8855").readlines()
  15. if not math_dup_app_server:
  16. # server_run(8855, "nohup python math_dup_app.py >> logs/math_dup_app.log 2>&1 &")
  17. server_run(8855, "gunicorn -c guc_conf.py math_dup_app:app")
  18. rlt_ddc_app_server = os.popen("lsof -i:8856").readlines()
  19. if not rlt_ddc_app_server:
  20. server_run(8856, "nohup python rlt_ddc_app.py >> logs/rlt_ddc_app.log 2>&1 &")
  21. hnsw_app_server = os.popen("lsof -i:8858").readlines()
  22. if not hnsw_app_server:
  23. current_time = datetime.datetime.now()
  24. if current_time.weekday() not in {0,3} or current_time.hour > 5:
  25. server_run(8858, "nohup python hnsw_app.py > logs/temp_app.log 2>&1 &")