dolphinscheduler-daemon.sh 4.1 KB

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