dolphinscheduler-daemon.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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) <command> "
  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=$BIN_DIR/..
  32. export JAVA_HOME=$JAVA_HOME
  33. #export JAVA_HOME=/opt/soft/jdk
  34. export HOSTNAME=`hostname`
  35. export DOLPHINSCHEDULER_PID_DIR=/tmp/
  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 DOLPHINSCHEDULER_OPTS="-server -Xmx16g -Xms4g -Xss512k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70"
  40. export STOP_TIMEOUT=5
  41. if [ ! -d "$DOLPHINSCHEDULER_LOG_DIR" ]; then
  42. mkdir $DOLPHINSCHEDULER_LOG_DIR
  43. fi
  44. log=$DOLPHINSCHEDULER_LOG_DIR/dolphinscheduler-$command-$HOSTNAME.out
  45. pid=$DOLPHINSCHEDULER_LOG_DIR/dolphinscheduler-$command.pid
  46. cd $DOLPHINSCHEDULER_HOME
  47. if [ "$command" = "api-server" ]; then
  48. LOG_FILE="-Dlogging.config=classpath:apiserver_logback.xml -Dspring.profiles.active=api"
  49. CLASS=org.apache.dolphinscheduler.api.ApiApplicationServer
  50. elif [ "$command" = "master-server" ]; then
  51. LOG_FILE="-Dlogging.config=classpath:master_logback.xml -Ddruid.mysql.usePingMethod=false"
  52. CLASS=org.apache.dolphinscheduler.server.master.MasterServer
  53. elif [ "$command" = "worker-server" ]; then
  54. LOG_FILE="-Dlogging.config=classpath:worker_logback.xml -Ddruid.mysql.usePingMethod=false"
  55. CLASS=org.apache.dolphinscheduler.server.worker.WorkerServer
  56. elif [ "$command" = "alert-server" ]; then
  57. LOG_FILE="-Dlogback.configurationFile=conf/alert_logback.xml"
  58. CLASS=org.apache.dolphinscheduler.alert.AlertServer
  59. elif [ "$command" = "logger-server" ]; then
  60. CLASS=org.apache.dolphinscheduler.server.rpc.LoggerServer
  61. elif [ "$command" = "combined-server" ]; then
  62. LOG_FILE="-Dlogging.config=classpath:combined_logback.xml -Dspring.profiles.active=api -Dserver.is-combined-server=true"
  63. CLASS=org.apache.dolphinscheduler.api.CombinedApplicationServer
  64. else
  65. echo "Error: No command named \`$command' was found."
  66. exit 1
  67. fi
  68. case $startStop in
  69. (start)
  70. [ -w "$DOLPHINSCHEDULER_PID_DIR" ] || mkdir -p "$DOLPHINSCHEDULER_PID_DIR"
  71. if [ -f $pid ]; then
  72. if kill -0 `cat $pid` > /dev/null 2>&1; then
  73. echo $command running as process `cat $pid`. Stop it first.
  74. exit 1
  75. fi
  76. fi
  77. echo starting $command, logging to $log
  78. exec_command="$LOG_FILE $DOLPHINSCHEDULER_OPTS -classpath $DOLPHINSCHEDULER_CONF_DIR:$DOLPHINSCHEDULER_LIB_JARS $CLASS"
  79. echo "nohup $JAVA_HOME/bin/java $exec_command > $log 2>&1 < /dev/null &"
  80. nohup $JAVA_HOME/bin/java $exec_command > $log 2>&1 < /dev/null &
  81. echo $! > $pid
  82. ;;
  83. (stop)
  84. if [ -f $pid ]; then
  85. TARGET_PID=`cat $pid`
  86. if kill -0 $TARGET_PID > /dev/null 2>&1; then
  87. echo stopping $command
  88. kill $TARGET_PID
  89. sleep $STOP_TIMEOUT
  90. if kill -0 $TARGET_PID > /dev/null 2>&1; then
  91. echo "$command did not stop gracefully after $STOP_TIMEOUT seconds: killing with kill -9"
  92. kill -9 $TARGET_PID
  93. fi
  94. else
  95. echo no $command to stop
  96. fi
  97. rm -f $pid
  98. else
  99. echo no $command to stop
  100. fi
  101. ;;
  102. (*)
  103. echo $usage
  104. exit 1
  105. ;;
  106. esac
  107. echo "End $startStop $command."