启动程序.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. # 获取当前时间
  3. hour=`date +%H`
  4. minute=`date +%M`
  5. # 获取进程数量,一个图像处理进程,一个前端交互进程
  6. process_sonar=`ps -ef | grep "test_tcp.py" | grep -v grep | wc -l`
  7. process_sanic=`ps -ef | grep "sanic_server.py" | grep -v grep | wc -l`
  8. process_ws=`ps -ef | grep "ws_server.py" | grep -v grep | wc -l`
  9. process_count=`ps -ef | grep "count_fish_jh5_v1_bushu.py" | grep -v grep | wc -l`
  10. # 停止运行时间段设置
  11. stop_start_hour=3
  12. stop_start_minute=0
  13. stop_end_hour=3
  14. stop_end_minute=10
  15. if [[ 10#$hour -eq $stop_start_hour && 10#$minute -ge $stop_start_minute && 10#$minute -le $stop_end_minute ]]; then
  16. # 在 23:00 - 23:10 停止运行
  17. if [[ $process_sonar -gt 0 ]]; then
  18. ps aux | grep test_tcp.py | grep -v grep | awk '{print $2}' | xargs kill -9
  19. fi
  20. if [[ $process_ws -gt 0 ]]; then
  21. ps aux | grep ws_server.py | grep -v grep | awk '{print $2}' | xargs kill -9
  22. fi
  23. if [[ process_count -gt 0 ]]; then
  24. ps aux | grep count_fish_jh5_v1_bushu.py | grep -v grep | awk '{print $2}' | xargs kill -9
  25. fi
  26. else
  27. # 其余时间段运行
  28. if [[ process_count -eq 0 ]]; then
  29. cd /home/sencott/sonar/sonar_process/
  30. nohup /home/sencott/anaconda3/bin/python count_fish_jh5_v1_bushu.py > /home/sencott/sonar/sonar_process/log/count_fish.log 2>&1 &
  31. fi
  32. # sanic server 进程
  33. if [[ $process_sanic -eq 0 ]]; then
  34. cd /home/sencott/sonar_project/http_server
  35. nohup /home/sencott/anaconda3/bin/python sanic_server.py > /home/sencott/sonar/log/crontab_sanic.log 2>&1 &
  36. fi
  37. # sonar 进程
  38. if [[ $process_sonar -eq 0 ]]; then
  39. cd /home/sencott/sonar/sonar_control
  40. nohup /home/sencott/anaconda3/bin/python test_tcp.py > /home/sencott/sonar/log/crontab_tset_tcp.log 2>&1 &
  41. fi
  42. # ws 进程
  43. if [[ $process_ws -eq 0 ]]; then
  44. cd /home/sencott/sonar/sonar_server
  45. nohup /home/sencott/anaconda3/bin/python ws_server.py > /home/sencott/sonar/log/crontab_ws.log 2>&1 &
  46. fi
  47. echo "time:$hour:$minute, process_sonar:$process_sonar"
  48. if [[ $process_sonar -ne 7 ]]; then
  49. # 查找 PID 并 kill 进程
  50. pid=`ps -ef | grep "test_tcp.py" | grep -v grep | awk '{print $2}'`
  51. if [[ ! -z $pid ]]; then
  52. echo "kill process $pid"
  53. kill -9 $pid
  54. fi
  55. cd /home/sencott/sonar/sonar_control
  56. nohup /home/sencott/anaconda3/bin/python test_tcp.py > /home/sencott/sonar/log/crontab_tset_tcp.log 2>&1 &
  57. fi
  58. fi
  59. #!/bin/bash
  60. #获取进程数量,从服务器3个,主服务器3个