dolphinscheduler-daemon.sh 4.7 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|status) <command> "
L
ligang 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

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

startStop=$1
shift
command=$1
shift


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

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

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

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

48
export DOLPHINSCHEDULER_OPTS=${DOLPHINSCHEDULER_OPTS:-"-server -Xmx16g -Xms1g -Xss512k -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:LargePageSizeInBytes=10m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70"}
L
ligang 已提交
49 50
export STOP_TIMEOUT=5

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

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

58
cd $DOLPHINSCHEDULER_HOME
L
ligang 已提交
59 60

if [ "$command" = "api-server" ]; then
61
  LOG_FILE="-Dlogging.config=classpath:logback-api.xml -Dspring.profiles.active=api"
62
  CLASS=org.apache.dolphinscheduler.api.ApiApplicationServer
L
ligang 已提交
63
elif [ "$command" = "master-server" ]; then
64
  LOG_FILE="-Dlogging.config=classpath:logback-master.xml -Ddruid.mysql.usePingMethod=false"
65
  CLASS=org.apache.dolphinscheduler.server.master.MasterServer
L
ligang 已提交
66
elif [ "$command" = "worker-server" ]; then
67
  LOG_FILE="-Dlogging.config=classpath:logback-worker.xml -Ddruid.mysql.usePingMethod=false"
68
  CLASS=org.apache.dolphinscheduler.server.worker.WorkerServer
L
ligang 已提交
69
elif [ "$command" = "alert-server" ]; then
70
  LOG_FILE="-Dlogback.configurationFile=conf/logback-alert.xml"
71
  CLASS=org.apache.dolphinscheduler.alert.AlertServer
L
ligang 已提交
72
elif [ "$command" = "logger-server" ]; then
73
  CLASS=org.apache.dolphinscheduler.server.log.LoggerServer
74 75 76 77
elif [ "$command" = "zookeeper-server" ]; then
  #note: this command just for getting a quick experience,not recommended for production. this operation will start a standalone zookeeper server
  LOG_FILE="-Dlogback.configurationFile=classpath:logback-zookeeper.xml"
  CLASS=org.apache.dolphinscheduler.service.zk.ZKServer
L
ligang 已提交
78 79 80 81 82 83 84
else
  echo "Error: No command named \`$command' was found."
  exit 1
fi

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

    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

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

D
dailidong 已提交
98 99
    echo "nohup $JAVA_HOME/bin/java $exec_command > $log 2>&1 &"
    nohup $JAVA_HOME/bin/java $exec_command > $log 2>&1 &
L
ligang 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
    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
      ;;

124 125 126 127 128 129 130 131 132 133 134 135 136 137
  (status)
    # more details about the status can be added later
    serverCount=`ps -ef |grep "$CLASS" |grep -v "grep" |wc -l`
    state="STOP"
    #  font color - red
    state="[ \033[1;31m $state \033[0m ]"
    if [[ $serverCount -gt 0 ]];then
      state="RUNNING"
      # font color - green
      state="[ \033[1;32m $state \033[0m ]"
    fi
    echo -e "$command  $state"
    ;;

L
ligang 已提交
138 139 140 141 142 143
  (*)
    echo $usage
    exit 1
    ;;

esac