starter.sh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/usr/bin/env bash
  2. ##
  3. # Licensed to the Apache Software Foundation (ASF) under one
  4. # or more contributor license agreements. See the NOTICE file
  5. # distributed with this work for additional information
  6. # regarding copyright ownership. The ASF licenses this file
  7. # to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance
  9. # with the License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. ##
  19. set -e
  20. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  21. $DIR/envtoconf.py --destination /opt/hadoop/etc/hadoop
  22. if [ -n "$SLEEP_SECONDS" ]; then
  23. echo "Sleeping for $SLEEP_SECONDS seconds"
  24. sleep $SLEEP_SECONDS
  25. fi
  26. #
  27. # You can wait for an other TCP port with these settings.
  28. #
  29. # Example:
  30. #
  31. # export WAITFOR=localhost:9878
  32. #
  33. # With an optional parameter, you can also set the maximum
  34. # time of waiting with (in seconds) with WAITFOR_TIMEOUT.
  35. # (The default is 300 seconds / 5 minutes.)
  36. if [ ! -z "$WAITFOR" ]; then
  37. echo "Waiting for the service $WAITFOR"
  38. WAITFOR_HOST=$(printf "%s\n" "$WAITFOR"| cut -d : -f 1)
  39. WAITFOR_PORT=$(printf "%s\n" "$WAITFOR"| cut -d : -f 2)
  40. for i in `seq ${WAITFOR_TIMEOUT:-300} -1 0` ; do
  41. set +e
  42. nc -z "$WAITFOR_HOST" "$WAITFOR_PORT" > /dev/null 2>&1
  43. result=$?
  44. set -e
  45. if [ $result -eq 0 ] ; then
  46. break
  47. fi
  48. sleep 1
  49. done
  50. if [ "$i" -eq 0 ]; then
  51. echo "Waiting for service $WAITFOR is timed out." >&2
  52. exit 1
  53. f
  54. fi
  55. fi
  56. if [ -n "$KERBEROS_ENABLED" ]; then
  57. echo "Setting up kerberos!!"
  58. KERBEROS_SERVER=${KERBEROS_SERVER:-krb5}
  59. ISSUER_SERVER=${ISSUER_SERVER:-$KERBEROS_SERVER\:8081}
  60. echo "KDC ISSUER_SERVER => $ISSUER_SERVER"
  61. while true
  62. do
  63. STATUS=$(curl -s -o /dev/null -w '%{http_code}' http://$ISSUER_SERVER/keytab/test/test)
  64. if [ $STATUS -eq 200 ]; then
  65. echo "Got 200, KDC service ready!!"
  66. break
  67. else
  68. echo "Got $STATUS :( KDC service not ready yet..."
  69. fi
  70. sleep 5
  71. done
  72. export HOST_NAME=`hostname -f`
  73. for NAME in ${KERBEROS_KEYTABS}; do
  74. echo "Download $NAME/$HOSTNAME@EXAMPLE.COM keytab file to $CONF_DIR/$NAME.keytab"
  75. wget http://$ISSUER_SERVER/keytab/$HOST_NAME/$NAME -O $CONF_DIR/$NAME.keytab
  76. KERBEROS_ENABLED=true
  77. done
  78. cat $DIR/krb5.conf | sed "s/SERVER/$KERBEROS_SERVER/g" | sudo tee /etc/krb5.conf
  79. fi
  80. #To avoid docker volume permission problems
  81. sudo chmod o+rwx /data
  82. if [ -n "$ENSURE_NAMENODE_DIR" ]; then
  83. CLUSTERID_OPTS=""
  84. if [ -n "$ENSURE_NAMENODE_CLUSTERID" ]; then
  85. CLUSTERID_OPTS="-clusterid $ENSURE_NAMENODE_CLUSTERID"
  86. fi
  87. if [ ! -d "$ENSURE_NAMENODE_DIR" ]; then
  88. /opt/hadoop/bin/hdfs namenode -format -force $CLUSTERID_OPTS
  89. fi
  90. fi
  91. if [ -n "$ENSURE_STANDBY_NAMENODE_DIR" ]; then
  92. if [ ! -d "$ENSURE_STANDBY_NAMENODE_DIR" ]; then
  93. /opt/hadoop/bin/hdfs namenode -bootstrapStandby
  94. fi
  95. fi
  96. if [ -n "$ENSURE_SCM_INITIALIZED" ]; then
  97. if [ ! -f "$ENSURE_SCM_INITIALIZED" ]; then
  98. # Improve om and scm start up options
  99. /opt/hadoop/bin/ozone scm --init || /opt/hadoop/bin/ozone scm -init
  100. fi
  101. fi
  102. if [ -n "$ENSURE_OM_INITIALIZED" ]; then
  103. if [ ! -f "$ENSURE_OM_INITIALIZED" ]; then
  104. # Improve om and scm start up options
  105. /opt/hadoop/bin/ozone om --init || /opt/hadoop/bin/ozone om -createObjectStore
  106. fi
  107. fi
  108. # The KSM initialization block will go away eventually once
  109. # we have completed renaming KSM to OzoneManager (OM).
  110. #
  111. if [ -n "$ENSURE_KSM_INITIALIZED" ]; then
  112. if [ ! -f "$ENSURE_KSM_INITIALIZED" ]; then
  113. # To make sure SCM is running in dockerized environment we will sleep
  114. # Could be removed after HDFS-13203
  115. echo "Waiting 15 seconds for SCM startup"
  116. sleep 15
  117. /opt/hadoop/bin/ozone ksm -createObjectStore
  118. fi
  119. fi
  120. # Supports byteman script to instrument hadoop process with byteman script
  121. #
  122. #
  123. if [ -n "$BYTEMAN_SCRIPT" ] || [ -n "$BYTEMAN_SCRIPT_URL" ]; then
  124. export PATH=$PATH:$BYTEMAN_DIR/bin
  125. if [ ! -z "$BYTEMAN_SCRIPT_URL" ]; then
  126. sudo wget $BYTEMAN_SCRIPT_URL -O /tmp/byteman.btm
  127. export BYTEMAN_SCRIPT=/tmp/byteman.btm
  128. fi
  129. if [ ! -f "$BYTEMAN_SCRIPT" ]; then
  130. echo "ERROR: The defined $BYTEMAN_SCRIPT does not exist!!!"
  131. exit -1
  132. fi
  133. AGENT_STRING="-javaagent:/opt/byteman.jar=script:$BYTEMAN_SCRIPT"
  134. export HADOOP_OPTS="$AGENT_STRING $HADOOP_OPTS"
  135. echo "Process is instrumented with adding $AGENT_STRING to HADOOP_OPTS"
  136. fi
  137. $@