startup.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. export DOLPHINSCHEDULER_BIN=${DOLPHINSCHEDULER_HOME}/bin
  20. export MASTER_START_ENABLED=false
  21. export WORKER_START_ENABLED=false
  22. export API_START_ENABLED=false
  23. export ALERT_START_ENABLED=false
  24. export LOGGER_START_ENABLED=false
  25. export STANDALONE_START_ENABLED=false
  26. # wait database
  27. waitDatabase() {
  28. echo "try to connect ${DATABASE_TYPE} ..."
  29. while ! nc -z ${DATABASE_HOST} ${DATABASE_PORT}; do
  30. local counter=$((counter+1))
  31. if [ $counter == 30 ]; then
  32. echo "Error: Couldn't connect to ${DATABASE_TYPE}."
  33. exit 1
  34. fi
  35. echo "Trying to connect to ${DATABASE_TYPE} at ${DATABASE_HOST}:${DATABASE_PORT}. Attempt $counter."
  36. sleep 5
  37. done
  38. echo "${DATABASE_TYPE} connection is ok"
  39. }
  40. # init database
  41. initDatabase() {
  42. echo "import sql data"
  43. ${DOLPHINSCHEDULER_HOME}/script/create-dolphinscheduler.sh
  44. }
  45. # wait zk
  46. waitZK() {
  47. echo "try to connect zookeeper ..."
  48. echo "${ZOOKEEPER_QUORUM}" | awk -F ',' 'BEGIN{ i=1 }{ while( i <= NF ){ print $i; i++ } }' | while read line; do
  49. while ! nc -z ${line%:*} ${line#*:}; do
  50. local counter=$((counter+1))
  51. if [ $counter == 30 ]; then
  52. echo "Error: Couldn't connect to zookeeper."
  53. exit 1
  54. fi
  55. echo "Trying to connect to zookeeper at ${line}. Attempt $counter."
  56. sleep 5
  57. done
  58. done
  59. echo "zookeeper connection is ok"
  60. }
  61. # print usage
  62. printUsage() {
  63. echo -e "Dolphin Scheduler is a distributed and easy-to-expand visual DAG workflow scheduling system,"
  64. echo -e "dedicated to solving the complex dependencies in data processing, making the scheduling system out of the box for data processing.\n"
  65. echo -e "Usage: [ all | master-server | worker-server | api-server | alert-server | standalone-server ]\n"
  66. printf "%-13s: %s\n" "all" "Run master-server, worker-server, api-server and alert-server"
  67. printf "%-13s: %s\n" "master-server" "MasterServer is mainly responsible for DAG task split, task submission monitoring."
  68. printf "%-13s: %s\n" "worker-server" "WorkerServer is mainly responsible for task execution and providing log services."
  69. printf "%-13s: %s\n" "api-server" "ApiServer is mainly responsible for processing requests and providing the front-end UI layer."
  70. printf "%-13s: %s\n" "alert-server" "AlertServer mainly include Alarms."
  71. printf "%-13s: %s\n" "standalone-server" "Standalone server that uses embedded zookeeper and database, only for testing and demostration."
  72. }
  73. # init config file
  74. source /root/startup-init-conf.sh
  75. case "$1" in
  76. (all)
  77. waitZK
  78. waitDatabase
  79. initDatabase
  80. export MASTER_START_ENABLED=true
  81. export WORKER_START_ENABLED=true
  82. export API_START_ENABLED=true
  83. export ALERT_START_ENABLED=true
  84. export LOGGER_START_ENABLED=true
  85. ;;
  86. (master-server)
  87. waitZK
  88. waitDatabase
  89. export MASTER_START_ENABLED=true
  90. ;;
  91. (worker-server)
  92. waitZK
  93. waitDatabase
  94. export WORKER_START_ENABLED=true
  95. export LOGGER_START_ENABLED=true
  96. ;;
  97. (api-server)
  98. waitZK
  99. waitDatabase
  100. initDatabase
  101. export API_START_ENABLED=true
  102. ;;
  103. (alert-server)
  104. waitDatabase
  105. export ALERT_START_ENABLED=true
  106. ;;
  107. (standalone-server)
  108. export STANDALONE_START_ENABLED=true
  109. ;;
  110. (help)
  111. printUsage
  112. exit 1
  113. ;;
  114. (*)
  115. printUsage
  116. exit 1
  117. ;;
  118. esac
  119. # init directories
  120. mkdir -p ${DOLPHINSCHEDULER_HOME}/logs
  121. # start supervisord
  122. supervisord -n -u root