run.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. APP_NAME=baoshi-measure-cargo
  3. APP_PATH=/bssoft/baoshi-measure-cargo
  4. cd $APP_PATH
  5. #使用说明,用来提示输入参数
  6. usage() {
  7. echo "Usage: sh demo.sh [start|stop|restart|status]"
  8. exit 1
  9. }
  10. #检查程序是否在运行
  11. is_exist() {
  12. pid=$(ps -ef | grep "$APP_NAME" | grep -v grep | grep -vF "$0" | awk '{print $2}')
  13. #如果不存在返回1,存在返回0
  14. if [ -z "${pid}" ]; then
  15. return 1
  16. else
  17. return 0
  18. fi
  19. }
  20. #启动方法
  21. start() {
  22. is_exist
  23. if [ $? -eq "0" ]; then
  24. echo "${APP_NAME} is already running. pid=${pid} ."
  25. else
  26. export API_PORT=8080
  27. export ROI_WIDTH_CM=10 # cm
  28. export ROI_HEIGHT_CM=10 # cm
  29. export MIN_DEPTH=50 # cm
  30. export MAX_DEPTH=400 # cm
  31. source env/bin/activate
  32. nohup python $APP_PATH/main.py > output.log 2>&1 &
  33. fi
  34. }
  35. #停止方法
  36. stop() {
  37. is_exist
  38. if [ $? -eq "0" ]; then
  39. kill -9 $pid
  40. else
  41. echo "${APP_NAME} is not running"
  42. fi
  43. }
  44. #输出运行状态
  45. status() {
  46. is_exist
  47. if [ $? -eq "0" ]; then
  48. echo "${APP_NAME} is running. Pid is ${pid}"
  49. else
  50. echo "${APP_NAME} is not running."
  51. fi
  52. }
  53. #重启
  54. restart() {
  55. stop
  56. start
  57. }
  58. #根据输入参数,选择执行对应方法,不输入则执行使用说明
  59. case "$1" in
  60. "start")
  61. start
  62. ;;
  63. "stop")
  64. stop
  65. ;;
  66. "status")
  67. status
  68. ;;
  69. "restart")
  70. restart
  71. ;;
  72. *)
  73. usage
  74. ;;
  75. esac