dolphinscheduler-daemon.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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> "
  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. BIN_DIR=`dirname $0`
  29. BIN_DIR=`cd "$BIN_DIR"; pwd`
  30. DOLPHINSCHEDULER_HOME=$BIN_DIR/..
  31. source /etc/profile
  32. export JAVA_HOME=$JAVA_HOME
  33. #export JAVA_HOME=/opt/soft/jdk
  34. export HOSTNAME=`hostname`
  35. export DOLPHINSCHEDULER_PID_DIR=$DOLPHINSCHEDULER_HOME/pid
  36. export DOLPHINSCHEDULER_LOG_DIR=$DOLPHINSCHEDULER_HOME/logs
  37. export DOLPHINSCHEDULER_CONF_DIR=$DOLPHINSCHEDULER_HOME/conf
  38. export DOLPHINSCHEDULER_LIB_JARS=$DOLPHINSCHEDULER_HOME/lib/*
  39. export STOP_TIMEOUT=5
  40. if [ ! -d "$DOLPHINSCHEDULER_LOG_DIR" ]; then
  41. mkdir $DOLPHINSCHEDULER_LOG_DIR
  42. fi
  43. log=$DOLPHINSCHEDULER_LOG_DIR/dolphinscheduler-$command-$HOSTNAME.out
  44. pid=$DOLPHINSCHEDULER_PID_DIR/dolphinscheduler-$command.pid
  45. cd $DOLPHINSCHEDULER_HOME
  46. if [ "$command" = "api-server" ]; then
  47. HEAP_INITIAL_SIZE=1g
  48. HEAP_MAX_SIZE=1g
  49. HEAP_NEW_GENERATION_SIZE=512m
  50. LOG_FILE="-Dlogging.config=classpath:logback-api.xml -Dspring.profiles.active=api"
  51. CLASS=org.apache.dolphinscheduler.api.ApiApplicationServer
  52. elif [ "$command" = "master-server" ]; then
  53. HEAP_INITIAL_SIZE=4g
  54. HEAP_MAX_SIZE=4g
  55. HEAP_NEW_GENERATION_SIZE=2g
  56. LOG_FILE="-Dlogging.config=classpath:logback-master.xml -Ddruid.mysql.usePingMethod=false"
  57. CLASS=org.apache.dolphinscheduler.server.master.MasterServer
  58. elif [ "$command" = "worker-server" ]; then
  59. HEAP_INITIAL_SIZE=2g
  60. HEAP_MAX_SIZE=2g
  61. HEAP_NEW_GENERATION_SIZE=1g
  62. LOG_FILE="-Dlogging.config=classpath:logback-worker.xml -Ddruid.mysql.usePingMethod=false"
  63. CLASS=org.apache.dolphinscheduler.server.worker.WorkerServer
  64. elif [ "$command" = "alert-server" ]; then
  65. HEAP_INITIAL_SIZE=1g
  66. HEAP_MAX_SIZE=1g
  67. HEAP_NEW_GENERATION_SIZE=512m
  68. LOG_FILE="-Dlogback.configurationFile=conf/logback-alert.xml"
  69. CLASS=org.apache.dolphinscheduler.alert.AlertServer
  70. elif [ "$command" = "logger-server" ]; then
  71. HEAP_INITIAL_SIZE=1g
  72. HEAP_MAX_SIZE=1g
  73. HEAP_NEW_GENERATION_SIZE=512m
  74. CLASS=org.apache.dolphinscheduler.server.log.LoggerServer
  75. elif [ "$command" = "zookeeper-server" ]; then
  76. #note: this command just for getting a quick experience,not recommended for production. this operation will start a standalone zookeeper server
  77. LOG_FILE="-Dlogback.configurationFile=classpath:logback-zookeeper.xml"
  78. CLASS=org.apache.dolphinscheduler.service.zk.ZKServer
  79. else
  80. echo "Error: No command named \`$command' was found."
  81. exit 1
  82. fi
  83. export DOLPHINSCHEDULER_OPTS="-server -Xms$HEAP_INITIAL_SIZE -Xmx$HEAP_MAX_SIZE -Xmn$HEAP_NEW_GENERATION_SIZE -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m -Xss512k -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:LargePageSizeInBytes=128m -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 -XX:+PrintGCDetails -Xloggc:$DOLPHINSCHEDULER_LOG_DIR/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=dump.hprof $DOLPHINSCHEDULER_OPTS"
  84. case $startStop in
  85. (start)
  86. exec_command="$LOG_FILE $DOLPHINSCHEDULER_OPTS -classpath $DOLPHINSCHEDULER_CONF_DIR:$DOLPHINSCHEDULER_LIB_JARS $CLASS"
  87. if [ "$DOCKER" = "true" ]; then
  88. echo "start in docker"
  89. $JAVA_HOME/bin/java $exec_command
  90. else
  91. [ -w "$DOLPHINSCHEDULER_PID_DIR" ] || mkdir -p "$DOLPHINSCHEDULER_PID_DIR"
  92. if [ -f $pid ]; then
  93. if kill -0 `cat $pid` > /dev/null 2>&1; then
  94. echo $command running as process `cat $pid`. Stop it first.
  95. exit 1
  96. fi
  97. fi
  98. echo starting $command, logging to $log
  99. echo "nohup $JAVA_HOME/bin/java $exec_command > $log 2>&1 &"
  100. nohup $JAVA_HOME/bin/java $exec_command > $log 2>&1 &
  101. echo $! > $pid
  102. fi
  103. ;;
  104. (stop)
  105. if [ -f $pid ]; then
  106. TARGET_PID=`cat $pid`
  107. if kill -0 $TARGET_PID > /dev/null 2>&1; then
  108. echo stopping $command
  109. kill $TARGET_PID
  110. sleep $STOP_TIMEOUT
  111. if kill -0 $TARGET_PID > /dev/null 2>&1; then
  112. echo "$command did not stop gracefully after $STOP_TIMEOUT seconds: killing with kill -9"
  113. kill -9 $TARGET_PID
  114. fi
  115. else
  116. echo no $command to stop
  117. fi
  118. rm -f $pid
  119. else
  120. echo no $command to stop
  121. fi
  122. ;;
  123. (status)
  124. # more details about the status can be added later
  125. serverCount=`ps -ef |grep "$CLASS" |grep -v "grep" |wc -l`
  126. state="STOP"
  127. # font color - red
  128. state="[ \033[1;31m $state \033[0m ]"
  129. if [[ $serverCount -gt 0 ]];then
  130. state="RUNNING"
  131. # font color - green
  132. state="[ \033[1;32m $state \033[0m ]"
  133. fi
  134. echo -e "$command $state"
  135. ;;
  136. (*)
  137. echo $usage
  138. exit 1
  139. ;;
  140. esac
  141. echo "End $startStop $command."