dolphinscheduler-daemon.sh 4.1 KB
Newer Older
D
dailidong 已提交
1
#!/bin/sh
B
bao liang 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
L
ligang 已提交
18

19
usage="Usage: dolphinscheduler-daemon.sh (start|stop) <command> "
L
ligang 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

# if no args specified, show usage
if [ $# -le 1 ]; then
  echo $usage
  exit 1
fi

startStop=$1
shift
command=$1
shift

echo "Begin $startStop $command......"

BIN_DIR=`dirname $0`
BIN_DIR=`cd "$BIN_DIR"; pwd`
36
DOLPHINSCHEDULER_HOME=$BIN_DIR/..
L
ligang 已提交
37

D
dailidong 已提交
38 39
source /etc/profile

L
ligang 已提交
40 41 42 43
export JAVA_HOME=$JAVA_HOME
#export JAVA_HOME=/opt/soft/jdk
export HOSTNAME=`hostname`

M
muzhongjiang 已提交
44
export DOLPHINSCHEDULER_PID_DIR=$DOLPHINSCHEDULER_HOME/pid
45 46 47
export DOLPHINSCHEDULER_LOG_DIR=$DOLPHINSCHEDULER_HOME/logs
export DOLPHINSCHEDULER_CONF_DIR=$DOLPHINSCHEDULER_HOME/conf
export DOLPHINSCHEDULER_LIB_JARS=$DOLPHINSCHEDULER_HOME/lib/*
L
ligang 已提交
48

rockxsj's avatar
rockxsj 已提交
49
export DOLPHINSCHEDULER_OPTS=${DOLPHINSCHEDULER_OPTS:-"-server -Xmx16g -Xms1g -Xss512k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70"}
L
ligang 已提交
50 51
export STOP_TIMEOUT=5

52 53
if [ ! -d "$DOLPHINSCHEDULER_LOG_DIR" ]; then
  mkdir $DOLPHINSCHEDULER_LOG_DIR
L
ligang 已提交
54 55
fi

56
log=$DOLPHINSCHEDULER_LOG_DIR/dolphinscheduler-$command-$HOSTNAME.out
M
muzhongjiang 已提交
57
pid=$DOLPHINSCHEDULER_PID_DIR/dolphinscheduler-$command.pid
L
ligang 已提交
58

59
cd $DOLPHINSCHEDULER_HOME
L
ligang 已提交
60 61

if [ "$command" = "api-server" ]; then
62
  LOG_FILE="-Dlogging.config=classpath:logback-api.xml -Dspring.profiles.active=api"
63
  CLASS=org.apache.dolphinscheduler.api.ApiApplicationServer
L
ligang 已提交
64
elif [ "$command" = "master-server" ]; then
65
  LOG_FILE="-Dlogging.config=classpath:logback-master.xml -Ddruid.mysql.usePingMethod=false"
66
  CLASS=org.apache.dolphinscheduler.server.master.MasterServer
L
ligang 已提交
67
elif [ "$command" = "worker-server" ]; then
68
  LOG_FILE="-Dlogging.config=classpath:logback-worker.xml -Ddruid.mysql.usePingMethod=false"
69
  CLASS=org.apache.dolphinscheduler.server.worker.WorkerServer
L
ligang 已提交
70
elif [ "$command" = "alert-server" ]; then
71
  LOG_FILE="-Dlogback.configurationFile=conf/logback-alert.xml"
72
  CLASS=org.apache.dolphinscheduler.alert.AlertServer
L
ligang 已提交
73
elif [ "$command" = "logger-server" ]; then
74
  CLASS=org.apache.dolphinscheduler.server.log.LoggerServer
L
ligang 已提交
75 76 77 78 79 80 81
else
  echo "Error: No command named \`$command' was found."
  exit 1
fi

case $startStop in
  (start)
82
    [ -w "$DOLPHINSCHEDULER_PID_DIR" ] ||  mkdir -p "$DOLPHINSCHEDULER_PID_DIR"
L
ligang 已提交
83 84 85 86 87 88 89 90 91 92

    if [ -f $pid ]; then
      if kill -0 `cat $pid` > /dev/null 2>&1; then
        echo $command running as process `cat $pid`.  Stop it first.
        exit 1
      fi
    fi

    echo starting $command, logging to $log

93
    exec_command="$LOG_FILE $DOLPHINSCHEDULER_OPTS -classpath $DOLPHINSCHEDULER_CONF_DIR:$DOLPHINSCHEDULER_LIB_JARS $CLASS"
L
ligang 已提交
94

D
dailidong 已提交
95 96
    echo "nohup $JAVA_HOME/bin/java $exec_command > $log 2>&1 &"
    nohup $JAVA_HOME/bin/java $exec_command > $log 2>&1 &
L
ligang 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    echo $! > $pid
    ;;

  (stop)

      if [ -f $pid ]; then
        TARGET_PID=`cat $pid`
        if kill -0 $TARGET_PID > /dev/null 2>&1; then
          echo stopping $command
          kill $TARGET_PID
          sleep $STOP_TIMEOUT
          if kill -0 $TARGET_PID > /dev/null 2>&1; then
            echo "$command did not stop gracefully after $STOP_TIMEOUT seconds: killing with kill -9"
            kill -9 $TARGET_PID
          fi
        else
          echo no $command to stop
        fi
        rm -f $pid
      else
        echo no $command to stop
      fi
      ;;

  (*)
    echo $usage
    exit 1
    ;;

esac

echo "End $startStop $command."