dolphinscheduler-daemon.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/bin/bash
  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|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. else
  52. echo "Error: No command named '$command' was found."
  53. exit 1
  54. fi
  55. case $startStop in
  56. (start)
  57. echo starting $command, logging to $DOLPHINSCHEDULER_LOG_DIR
  58. nohup /bin/bash "$DOLPHINSCHEDULER_HOME/$command/bin/start.sh" > $log 2>&1 &
  59. echo $! > $pid
  60. ;;
  61. (stop)
  62. if [ -f $pid ]; then
  63. TARGET_PID=`cat $pid`
  64. if kill -0 $TARGET_PID > /dev/null 2>&1; then
  65. echo stopping $command
  66. pkill -P $TARGET_PID
  67. sleep $STOP_TIMEOUT
  68. if kill -0 $TARGET_PID > /dev/null 2>&1; then
  69. echo "$command did not stop gracefully after $STOP_TIMEOUT seconds: killing with kill -9"
  70. pkill -P -9 $TARGET_PID
  71. fi
  72. else
  73. echo no $command to stop
  74. fi
  75. rm -f $pid
  76. else
  77. echo no $command to stop
  78. fi
  79. ;;
  80. (status)
  81. # more details about the status can be added later
  82. serverCount=`ps -ef | grep "$DOLPHINSCHEDULER_HOME" | grep "$CLASS" | grep -v "grep" | wc -l`
  83. state="STOP"
  84. # font color - red
  85. state="[ \033[1;31m $state \033[0m ]"
  86. if [[ $serverCount -gt 0 ]];then
  87. state="RUNNING"
  88. # font color - green
  89. state="[ \033[1;32m $state \033[0m ]"
  90. fi
  91. echo -e "$command $state"
  92. ;;
  93. (*)
  94. echo $usage
  95. exit 1
  96. ;;
  97. esac
  98. echo "End $startStop $command."