run.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/bash
  2. APP_NAME=InsightServer
  3. PROG_NAME=$0
  4. ACTION=$1
  5. SERVER_PORT=20020
  6. current_time=$(date +"%Y%m%d%H%M%S")
  7. LOG_FILE_NAME=logs/${current_time}.log
  8. usage() {
  9. echo "Usage: $PROG_NAME {start|stop|restart}"
  10. exit 2
  11. }
  12. start_application() {
  13. echo "starting ${APP_NAME} process"
  14. nohup uvicorn run_server_async:app --host 0.0.0.0 --port ${SERVER_PORT} --workers 10 --reload > ${LOG_FILE_NAME} 2>&1 &
  15. echo "start success!!!"
  16. }
  17. stop_application() {
  18. pids=`lsof -i:${SERVER_PORT} | awk '{print$2}' | grep -v "PID"`
  19. if [[ ! $pids ]];then
  20. echo -e "\rno process"
  21. return
  22. fi
  23. echo "start stop ${APP_NAME} process"
  24. times=60
  25. for e in $(seq 60);do
  26. sleep 1
  27. COSTTIME=$(($times - $e ))
  28. pids=`lsof -i:${SERVER_PORT} | awk '{print$2}' | grep -v "PID"`
  29. if [[ $pids ]];then
  30. for pid in $pids; do
  31. echo "kill pid:${pid}"
  32. kill -9 $pid
  33. echo -e "\r -- stopping process lasts `expr $COSTTIME` seconds."
  34. done
  35. else
  36. echo -e "\r${APP_NAME} process has exited"
  37. break;
  38. fi
  39. done
  40. echo ""
  41. }
  42. start() {
  43. start_application
  44. }
  45. stop() {
  46. stop_application
  47. }
  48. case "$ACTION" in
  49. start)
  50. start
  51. ;;
  52. stop)
  53. stop
  54. ;;
  55. restart)
  56. stop
  57. start
  58. ;;
  59. *)
  60. usage
  61. ;;
  62. esac