startup.sh 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #!/bin/bash
  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. set -e
  19. DOLPHINSCHEDULER_BIN=${DOLPHINSCHEDULER_HOME}/bin
  20. DOLPHINSCHEDULER_SCRIPT=${DOLPHINSCHEDULER_HOME}/script
  21. DOLPHINSCHEDULER_LOGS=${DOLPHINSCHEDULER_HOME}/logs
  22. # start postgresql
  23. initPostgreSQL() {
  24. echo "test postgresql service"
  25. while ! nc -z ${POSTGRESQL_HOST} ${POSTGRESQL_PORT}; do
  26. counter=$((counter+1))
  27. if [ $counter == 30 ]; then
  28. echo "Error: Couldn't connect to postgresql."
  29. exit 1
  30. fi
  31. echo "Trying to connect to postgresql at ${POSTGRESQL_HOST}:${POSTGRESQL_PORT}. Attempt $counter."
  32. sleep 5
  33. done
  34. echo "connect postgresql service"
  35. v=$(sudo -u postgres PGPASSWORD=${POSTGRESQL_PASSWORD} psql -h ${POSTGRESQL_HOST} -p ${POSTGRESQL_PORT} -U ${POSTGRESQL_USERNAME} -d dolphinscheduler -tAc "select 1")
  36. if [ "$(echo '${v}' | grep 'FATAL' | wc -l)" -eq 1 ]; then
  37. echo "Error: Can't connect to database...${v}"
  38. exit 1
  39. fi
  40. echo "import sql data"
  41. ${DOLPHINSCHEDULER_SCRIPT}/create-dolphinscheduler.sh
  42. }
  43. # start zk
  44. initZK() {
  45. echo "connect remote zookeeper"
  46. echo "${ZOOKEEPER_QUORUM}" | awk -F ',' 'BEGIN{ i=1 }{ while( i <= NF ){ print $i; i++ } }' | while read line; do
  47. while ! nc -z ${line%:*} ${line#*:}; do
  48. counter=$((counter+1))
  49. if [ $counter == 30 ]; then
  50. echo "Error: Couldn't connect to zookeeper."
  51. exit 1
  52. fi
  53. echo "Trying to connect to zookeeper at ${line}. Attempt $counter."
  54. sleep 5
  55. done
  56. done
  57. }
  58. # start nginx
  59. initNginx() {
  60. echo "start nginx"
  61. nginx &
  62. }
  63. # start master-server
  64. initMasterServer() {
  65. echo "start master-server"
  66. ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh stop master-server
  67. ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh start master-server
  68. }
  69. # start worker-server
  70. initWorkerServer() {
  71. echo "start worker-server"
  72. ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh stop worker-server
  73. ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh start worker-server
  74. }
  75. # start api-server
  76. initApiServer() {
  77. echo "start api-server"
  78. ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh stop api-server
  79. ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh start api-server
  80. }
  81. # start logger-server
  82. initLoggerServer() {
  83. echo "start logger-server"
  84. ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh stop logger-server
  85. ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh start logger-server
  86. }
  87. # start alert-server
  88. initAlertServer() {
  89. echo "start alert-server"
  90. ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh stop alert-server
  91. ${DOLPHINSCHEDULER_BIN}/dolphinscheduler-daemon.sh start alert-server
  92. }
  93. # print usage
  94. printUsage() {
  95. echo -e "Dolphin Scheduler is a distributed and easy-to-expand visual DAG workflow scheduling system,"
  96. echo -e "dedicated to solving the complex dependencies in data processing, making the scheduling system out of the box for data processing.\n"
  97. echo -e "Usage: [ all | master-server | worker-server | api-server | alert-server | frontend ]\n"
  98. printf "%-13s: %s\n" "all" "Run master-server, worker-server, api-server, alert-server and frontend."
  99. printf "%-13s: %s\n" "master-server" "MasterServer is mainly responsible for DAG task split, task submission monitoring."
  100. printf "%-13s: %s\n" "worker-server" "WorkerServer is mainly responsible for task execution and providing log services.."
  101. printf "%-13s: %s\n" "api-server" "ApiServer is mainly responsible for processing requests from the front-end UI layer."
  102. printf "%-13s: %s\n" "alert-server" "AlertServer mainly include Alarms."
  103. printf "%-13s: %s\n" "frontend" "Frontend mainly provides various visual operation interfaces of the system."
  104. }
  105. # init config file
  106. source /root/startup-init-conf.sh
  107. LOGFILE=/var/log/nginx/access.log
  108. case "$1" in
  109. (all)
  110. initZK
  111. initPostgreSQL
  112. initMasterServer
  113. initWorkerServer
  114. initApiServer
  115. initAlertServer
  116. initLoggerServer
  117. initNginx
  118. LOGFILE=/var/log/nginx/access.log
  119. ;;
  120. (master-server)
  121. initZK
  122. initPostgreSQL
  123. initMasterServer
  124. LOGFILE=${DOLPHINSCHEDULER_LOGS}/dolphinscheduler-master.log
  125. ;;
  126. (worker-server)
  127. initZK
  128. initPostgreSQL
  129. initWorkerServer
  130. initLoggerServer
  131. LOGFILE=${DOLPHINSCHEDULER_LOGS}/dolphinscheduler-worker.log
  132. ;;
  133. (api-server)
  134. initZK
  135. initPostgreSQL
  136. initApiServer
  137. LOGFILE=${DOLPHINSCHEDULER_LOGS}/dolphinscheduler-api-server.log
  138. ;;
  139. (alert-server)
  140. initPostgreSQL
  141. initAlertServer
  142. LOGFILE=${DOLPHINSCHEDULER_LOGS}/dolphinscheduler-alert.log
  143. ;;
  144. (frontend)
  145. initNginx
  146. LOGFILE=/var/log/nginx/access.log
  147. ;;
  148. (help)
  149. printUsage
  150. exit 1
  151. ;;
  152. (*)
  153. printUsage
  154. exit 1
  155. ;;
  156. esac
  157. # init directories and log files
  158. mkdir -p ${DOLPHINSCHEDULER_LOGS} && mkdir -p /var/log/nginx/ && cat /dev/null >> ${LOGFILE}
  159. echo "tail begin"
  160. exec bash -c "tail -n 1 -f ${LOGFILE}"