dolphinscheduler-daemon.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/sh
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one or more
  4. # contributor license agreements. See the NOTICE file distributed with
  5. # this work for additional information regarding copyright ownership.
  6. # The ASF licenses this file to You under the Apache License, Version 2.0
  7. # (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. usage="Usage: dolphinscheduler-daemon.sh (start|stop|status) <api-server|master-server|worker-server|alert-server|python-gateway-server|standalone-server> "
  19. # if no args specified, show usage
  20. if [ $# -le 1 ]; then
  21. echo $usage
  22. exit 1
  23. fi
  24. startStop=$1
  25. shift
  26. command=$1
  27. shift
  28. echo "Begin $startStop $command......"
  29. BIN_DIR=`dirname $0`
  30. BIN_DIR=`cd "$BIN_DIR"; pwd`
  31. DOLPHINSCHEDULER_HOME=`cd "$BIN_DIR/.."; pwd`
  32. source "${DOLPHINSCHEDULER_HOME}/bin/env/dolphinscheduler_env.sh"
  33. export HOSTNAME=`hostname`
  34. export DOLPHINSCHEDULER_LOG_DIR=$DOLPHINSCHEDULER_HOME/$command/logs
  35. export STOP_TIMEOUT=5
  36. if [ ! -d "$DOLPHINSCHEDULER_LOG_DIR" ]; then
  37. mkdir $DOLPHINSCHEDULER_LOG_DIR
  38. fi
  39. pid=$DOLPHINSCHEDULER_HOME/$command/pid
  40. cd $DOLPHINSCHEDULER_HOME/$command
  41. if [ "$command" = "api-server" ]; then
  42. log=$DOLPHINSCHEDULER_HOME/api-server/logs/$command-$HOSTNAME.out
  43. elif [ "$command" = "master-server" ]; then
  44. log=$DOLPHINSCHEDULER_HOME/master-server/logs/$command-$HOSTNAME.out
  45. elif [ "$command" = "worker-server" ]; then
  46. log=$DOLPHINSCHEDULER_HOME/worker-server/logs/$command-$HOSTNAME.out
  47. elif [ "$command" = "alert-server" ]; then
  48. log=$DOLPHINSCHEDULER_HOME/alert-server/logs/$command-$HOSTNAME.out
  49. elif [ "$command" = "standalone-server" ]; then
  50. log=$DOLPHINSCHEDULER_HOME/standalone-server/logs/$command-$HOSTNAME.out
  51. elif [ "$command" = "python-gateway-server" ]; then
  52. log=$DOLPHINSCHEDULER_HOME/python-gateway-server/logs/$command-$HOSTNAME.out
  53. else
  54. echo "Error: No command named '$command' was found."
  55. exit 1
  56. fi
  57. case $startStop in
  58. (start)
  59. echo starting $command, logging to $DOLPHINSCHEDULER_LOG_DIR
  60. nohup /bin/sh "$DOLPHINSCHEDULER_HOME/$command/bin/start.sh" > $log 2>&1 &
  61. echo $! > $pid
  62. ;;
  63. (stop)
  64. if [ -f $pid ]; then
  65. TARGET_PID=`cat $pid`
  66. if kill -0 $TARGET_PID > /dev/null 2>&1; then
  67. echo stopping $command
  68. pkill -P $TARGET_PID
  69. sleep $STOP_TIMEOUT
  70. if kill -0 $TARGET_PID > /dev/null 2>&1; then
  71. echo "$command did not stop gracefully after $STOP_TIMEOUT seconds: killing with kill -9"
  72. pkill -P -9 $TARGET_PID
  73. fi
  74. else
  75. echo no $command to stop
  76. fi
  77. rm -f $pid
  78. else
  79. echo no $command to stop
  80. fi
  81. ;;
  82. (status)
  83. # more details about the status can be added later
  84. serverCount=`ps -ef | grep "$DOLPHINSCHEDULER_HOME" | grep "$CLASS" | grep -v "grep" | wc -l`
  85. state="STOP"
  86. # font color - red
  87. state="[ \033[1;31m $state \033[0m ]"
  88. if [[ $serverCount -gt 0 ]];then
  89. state="RUNNING"
  90. # font color - green
  91. state="[ \033[1;32m $state \033[0m ]"
  92. fi
  93. echo -e "$command $state"
  94. ;;
  95. (*)
  96. echo $usage
  97. exit 1
  98. ;;
  99. esac
  100. echo "End $startStop $command."