VueDataAcServer.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/sh
  2. # set -x
  3. ROOT=$(cd `dirname $0`/../../; pwd)
  4. CURRENT_DIR=$(cd `dirname $0`; pwd)
  5. APP_NAME="Vue-dataAc-server"
  6. RUN_CMD="npm run start"
  7. STOP_CMD="npm run stop"
  8. EXE_NAME="egg-server-Vue-dataAc-server"
  9. #PID 代表是PID文件
  10. PID=$ROOT/pid/$APP_NAME\.pid
  11. #log
  12. LOG=$ROOT/logs/$APP_NAME\.out
  13. ERROR_LOG=$ROOT/logs/$APP_NAME_error\.out
  14. usage() {
  15. echo "Usage: sh 执行脚本.sh [start|stop|restart|status]"
  16. exit 1
  17. }
  18. #检查程序是否在运行
  19. is_exist(){
  20. pid=`ps -ef|grep $EXE_NAME|grep -v grep|awk '{print $2}' `
  21. #如果不存在返回1,存在返回0
  22. if [ -z "${pid}" ]; then
  23. return 1
  24. else
  25. return 0
  26. fi
  27. }
  28. start(){
  29. is_exist
  30. if [ $? -eq "0" ]; then
  31. echo ">>> ${EXE_NAME} is already running PID=${pid} <<<"
  32. else
  33. #nohup $EXE_NAME >> $LOG 2> $ERROR_LOG &
  34. $RUN_CMD >> $LOG 2> $ERROR_LOG
  35. echo $! > $PID
  36. echo ">>> start $EXE_NAME successed PID=$! <<<"
  37. fi
  38. }
  39. #停止方法
  40. stop(){
  41. $STOP_CMD >> $LOG 2> $ERROR_LOG
  42. is_exist
  43. if [ $? -eq "0" ]; then
  44. echo ">>> ${EXE_NAME} is still running PID=${pid} <<<"
  45. pidf=$(cat $PID)
  46. echo ">>> APP PID = $pidf begin kill $pidf <<<"
  47. kill $pidf
  48. rm -rf $PID
  49. sleep 2
  50. is_exist
  51. if [ $? -eq "0" ]; then
  52. echo ">>> api 2 PID = $pid begin kill -9 $pid <<<"
  53. kill -9 $pid
  54. sleep 2
  55. echo ">>> $EXE_NAME process stopped <<<"
  56. else
  57. echo ">>> ${EXE_NAME} is not running <<<"
  58. fi
  59. else
  60. echo ">>> ${EXE_NAME} is not running <<<"
  61. fi
  62. }
  63. #输出运行状态
  64. status(){
  65. is_exist
  66. if [ $? -eq "0" ]; then
  67. echo ">>> ${EXE_NAME} is running PID is ${pid} <<<"
  68. else
  69. echo ">>> ${EXE_NAME} is not running <<<"
  70. fi
  71. }
  72. #重启
  73. restart(){
  74. stop
  75. start
  76. }
  77. #根据输入参数,选择执行对应方法,不输入则执行使用说明
  78. case "$1" in
  79. "start")
  80. start
  81. ;;
  82. "stop")
  83. stop
  84. ;;
  85. "status")
  86. status
  87. ;;
  88. "restart")
  89. restart
  90. ;;
  91. *)
  92. usage
  93. ;;
  94. esac
  95. exit 0