starter.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. if [ -n "$SLEEP_SECONDS" ]; then
  22. echo "Sleeping for $SLEEP_SECONDS seconds"
  23. sleep $SLEEP_SECONDS
  24. fi
  25. #
  26. # You can wait for an other TCP port with these settings.
  27. #
  28. # Example:
  29. #
  30. # export WAITFOR=localhost:9878
  31. #
  32. # With an optional parameter, you can also set the maximum
  33. # time of waiting with (in seconds) with WAITFOR_TIMEOUT.
  34. # (The default is 300 seconds / 5 minutes.)
  35. if [ ! -z "$WAITFOR" ]; then
  36. echo "Waiting for the service $WAITFOR"
  37. WAITFOR_HOST=$(printf "%s\n" "$WAITFOR"| cut -d : -f 1)
  38. WAITFOR_PORT=$(printf "%s\n" "$WAITFOR"| cut -d : -f 2)
  39. for i in `seq ${WAITFOR_TIMEOUT:-300} -1 0` ; do
  40. set +e
  41. nc -z "$WAITFOR_HOST" "$WAITFOR_PORT" > /dev/null 2>&1
  42. result=$?
  43. set -e
  44. if [ $result -eq 0 ] ; then
  45. break
  46. fi
  47. sleep 1
  48. done
  49. if [ "$i" -eq 0 ]; then
  50. echo "Waiting for service $WAITFOR is timed out." >&2
  51. exit 1
  52. f
  53. fi
  54. fi
  55. if [ -n "$KERBEROS_ENABLED" ]; then
  56. echo "Setting up kerberos!!"
  57. KERBEROS_SERVER=${KERBEROS_SERVER:-krb5}
  58. ISSUER_SERVER=${ISSUER_SERVER:-$KERBEROS_SERVER\:8081}
  59. echo "KDC ISSUER_SERVER => $ISSUER_SERVER"
  60. if [ -n "$SLEEP_SECONDS" ]; then
  61. echo "Sleeping for $(SLEEP_SECONDS) seconds"
  62. sleep "$SLEEP_SECONDS"
  63. fi
  64. if [ -z "$KEYTAB_DIR" ]; then
  65. KEYTAB_DIR='/etc/security/keytabs'
  66. fi
  67. while true
  68. do
  69. set +e
  70. STATUS=$(curl -s -o /dev/null -w '%{http_code}' http://"$ISSUER_SERVER"/keytab/test/test)
  71. set -e
  72. if [ "$STATUS" -eq 200 ]; then
  73. echo "Got 200, KDC service ready!!"
  74. break
  75. else
  76. echo "Got $STATUS :( KDC service not ready yet..."
  77. fi
  78. sleep 5
  79. done
  80. HOST_NAME=$(hostname -f)
  81. export HOST_NAME
  82. for NAME in ${KERBEROS_KEYTABS}; do
  83. echo "Download $NAME/$HOSTNAME@EXAMPLE.COM keytab file to $KEYTAB_DIR/$NAME.keytab"
  84. wget "http://$ISSUER_SERVER/keytab/$HOST_NAME/$NAME" -O "$KEYTAB_DIR/$NAME.keytab"
  85. klist -kt "$KEYTAB_DIR/$NAME.keytab"
  86. KERBEROS_ENABLED=true
  87. done
  88. sed "s/SERVER/$KERBEROS_SERVER/g" "$DIR"/krb5.conf | sudo tee /etc/krb5.conf
  89. fi
  90. CONF_DESTINATION_DIR="${HADOOP_CONF_DIR:-/opt/hadoop/etc/hadoop}"
  91. #Try to copy the defaults
  92. set +e
  93. if [[ -d "/opt/ozone/etc/hadoop" ]]; then
  94. cp /opt/hadoop/etc/hadoop/* "$CONF_DESTINATION_DIR/" > /dev/null 2>&1
  95. elif [[ -d "/opt/hadoop/etc/hadoop" ]]; then
  96. cp /opt/hadoop/etc/hadoop/* "$CONF_DESTINATION_DIR/" > /dev/null 2>&1
  97. fi
  98. set -e
  99. "$DIR"/envtoconf.py --destination "$CONF_DESTINATION_DIR"
  100. if [ -n "$ENSURE_NAMENODE_DIR" ]; then
  101. CLUSTERID_OPTS=""
  102. if [ -n "$ENSURE_NAMENODE_CLUSTERID" ]; then
  103. CLUSTERID_OPTS="-clusterid $ENSURE_NAMENODE_CLUSTERID"
  104. fi
  105. if [ ! -d "$ENSURE_NAMENODE_DIR" ]; then
  106. /opt/hadoop/bin/hdfs namenode -format -force "$CLUSTERID_OPTS"
  107. fi
  108. fi
  109. if [ -n "$ENSURE_STANDBY_NAMENODE_DIR" ]; then
  110. if [ ! -d "$ENSURE_STANDBY_NAMENODE_DIR" ]; then
  111. /opt/hadoop/bin/hdfs namenode -bootstrapStandby
  112. fi
  113. fi
  114. if [ -n "$ENSURE_SCM_INITIALIZED" ]; then
  115. if [ ! -f "$ENSURE_SCM_INITIALIZED" ]; then
  116. # Improve om and scm start up options
  117. /opt/hadoop/bin/ozone scm --init || /opt/hadoop/bin/ozone scm -init
  118. fi
  119. fi
  120. if [ -n "$ENSURE_OM_INITIALIZED" ]; then
  121. if [ ! -f "$ENSURE_OM_INITIALIZED" ]; then
  122. # Improve om and scm start up options
  123. /opt/hadoop/bin/ozone om --init || /opt/hadoop/bin/ozone om -createObjectStore
  124. fi
  125. fi
  126. # Supports byteman script to instrument hadoop process with byteman script
  127. #
  128. #
  129. if [ -n "$BYTEMAN_SCRIPT" ] || [ -n "$BYTEMAN_SCRIPT_URL" ]; then
  130. export PATH=$PATH:$BYTEMAN_DIR/bin
  131. if [ ! -z "$BYTEMAN_SCRIPT_URL" ]; then
  132. wget $BYTEMAN_SCRIPT_URL -O /tmp/byteman.btm
  133. export BYTEMAN_SCRIPT=/tmp/byteman.btm
  134. fi
  135. if [ ! -f "$BYTEMAN_SCRIPT" ]; then
  136. echo "ERROR: The defined $BYTEMAN_SCRIPT does not exist!!!"
  137. exit -1
  138. fi
  139. AGENT_STRING="-javaagent:/opt/byteman.jar=script:$BYTEMAN_SCRIPT"
  140. export HADOOP_OPTS="$AGENT_STRING $HADOOP_OPTS"
  141. echo "Process is instrumented with adding $AGENT_STRING to HADOOP_OPTS"
  142. fi
  143. "$@"