dolphinscheduler-daemon.sh 3.1 KB

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