startup.sh 5.8 KB
Newer Older
Q
qiaozhanwei 已提交
1
#!/bin/bash
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.
#
18 19 20

set -e

L
liwenhe1993 已提交
21 22 23 24 25 26
DOLPHINSCHEDULER_BIN=${DOLPHINSCHEDULER_HOME}/bin
DOLPHINSCHEDULER_SCRIPT=${DOLPHINSCHEDULER_HOME}/script
DOLPHINSCHEDULER_LOGS=${DOLPHINSCHEDULER_HOME}/logs

# start postgresql
initPostgreSQL() {
27 28 29 30 31 32 33 34 35 36 37
    echo "test postgresql service"
    while ! nc -z ${POSTGRESQL_HOST} ${POSTGRESQL_PORT}; do
        counter=$((counter+1))
        if [ $counter == 30 ]; then
            echo "Error: Couldn't connect to postgresql."
            exit 1
        fi
        echo "Trying to connect to postgresql at ${POSTGRESQL_HOST}:${POSTGRESQL_PORT}. Attempt $counter."
        sleep 5
    done

L
liwenhe1993 已提交
38
    echo "connect postgresql service"
39
    v=$(sudo -u postgres PGPASSWORD=${POSTGRESQL_PASSWORD} psql -h ${POSTGRESQL_HOST} -p ${POSTGRESQL_PORT} -U ${POSTGRESQL_USERNAME} -d dolphinscheduler -tAc "select 1")
L
liwenhe1993 已提交
40
    if [ "$(echo '${v}' | grep 'FATAL' | wc -l)" -eq 1 ]; then
41
        echo "Error: Can't connect to database...${v}"
L
liwenhe1993 已提交
42 43
        exit 1
    fi
44

L
liwenhe1993 已提交
45 46 47 48 49 50
    echo "import sql data"
    ${DOLPHINSCHEDULER_SCRIPT}/create-dolphinscheduler.sh
}

# start zk
initZK() {
X
xiaochun.liu 已提交
51 52 53 54 55 56 57 58 59 60
    echo "connect remote zookeeper"
    echo "${ZOOKEEPER_QUORUM}" | awk -F ',' 'BEGIN{ i=1 }{ while( i <= NF ){ print $i; i++ } }' | while read line; do
        while ! nc -z ${line%:*} ${line#*:}; do
            counter=$((counter+1))
            if [ $counter == 30 ]; then
                echo "Error: Couldn't connect to zookeeper."
                exit 1
            fi
            echo "Trying to connect to zookeeper at ${line}. Attempt $counter."
            sleep 5
L
liwenhe1993 已提交
61
        done
X
xiaochun.liu 已提交
62
    done
L
liwenhe1993 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
}

# start nginx
initNginx() {
    echo "start nginx"
    nginx &
}

# start master-server
initMasterServer() {
    echo "start master-server"
    ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh stop master-server
    ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh start master-server
}

# start worker-server
initWorkerServer() {
    echo "start worker-server"
    ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh stop worker-server
    ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh start worker-server
}

# start api-server
initApiServer() {
    echo "start api-server"
    ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh stop api-server
    ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh start api-server
}

# start logger-server
initLoggerServer() {
    echo "start logger-server"
    ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh stop logger-server
    ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh start logger-server
}

# start alert-server
initAlertServer() {
    echo "start alert-server"
    ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh stop alert-server
    ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh start alert-server
}

# print usage
printUsage() {
    echo -e "Dolphin Scheduler is a distributed and easy-to-expand visual DAG workflow scheduling system,"
    echo -e "dedicated to solving the complex dependencies in data processing, making the scheduling system out of the box for data processing.\n"
    echo -e "Usage: [ all | master-server | worker-server | api-server | alert-server | frontend ]\n"
    printf "%-13s:  %s\n" "all"           "Run master-server, worker-server, api-server, alert-server and frontend."
    printf "%-13s:  %s\n" "master-server" "MasterServer is mainly responsible for DAG task split, task submission monitoring."
    printf "%-13s:  %s\n" "worker-server" "WorkerServer is mainly responsible for task execution and providing log services.."
    printf "%-13s:  %s\n" "api-server"    "ApiServer is mainly responsible for processing requests from the front-end UI layer."
    printf "%-13s:  %s\n" "alert-server"  "AlertServer mainly include Alarms."
    printf "%-13s:  %s\n" "frontend"      "Frontend mainly provides various visual operation interfaces of the system."
}

# init config file
source /root/startup-init-conf.sh

LOGFILE=/var/log/nginx/access.log
case "$1" in
    (all)
        initZK
        initPostgreSQL
        initMasterServer
        initWorkerServer
        initApiServer
        initAlertServer
        initLoggerServer
        initNginx
        LOGFILE=/var/log/nginx/access.log
    ;;
    (master-server)
        initZK
        initPostgreSQL
        initMasterServer
        LOGFILE=${DOLPHINSCHEDULER_LOGS}/dolphinscheduler-master.log
    ;;
    (worker-server)
        initZK
        initPostgreSQL
        initWorkerServer
        initLoggerServer
        LOGFILE=${DOLPHINSCHEDULER_LOGS}/dolphinscheduler-worker.log
    ;;
    (api-server)
149
        initZK
L
liwenhe1993 已提交
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
        initPostgreSQL
        initApiServer
        LOGFILE=${DOLPHINSCHEDULER_LOGS}/dolphinscheduler-api-server.log
    ;;
    (alert-server)
        initPostgreSQL
        initAlertServer
        LOGFILE=${DOLPHINSCHEDULER_LOGS}/dolphinscheduler-alert.log
    ;;
    (frontend)
        initNginx
        LOGFILE=/var/log/nginx/access.log
    ;;
    (help)
        printUsage
        exit 1
    ;;
    (*)
        printUsage
        exit 1
    ;;
esac

173 174 175 176 177
# init directories and log files
mkdir -p ${DOLPHINSCHEDULER_LOGS} && mkdir -p /var/log/nginx/ && cat /dev/null >> ${LOGFILE}

echo "tail begin"
exec bash -c "tail -n 1 -f ${LOGFILE}"
X
xiaochun.liu 已提交
178