startup.sh 4.1 KB

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