zkEnv.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. # https://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing,
  14. # software distributed under the License is distributed on an
  15. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. # KIND, either express or implied. See the License for the
  17. # specific language governing permissions and limitations
  18. # under the License.
  19. #
  20. # This script should be sourced into other zookeeper
  21. # scripts to setup the env variables
  22. # We use ZOOCFGDIR if defined,
  23. # otherwise we use /etc/zookeeper
  24. # or the conf directory that is
  25. # a sibling of this script's directory.
  26. # Or you can specify the ZOOCFGDIR using the
  27. # '--config' option in the command line.
  28. ZOOBINDIR="${ZOOBINDIR:-/usr/bin}"
  29. ZOOKEEPER_PREFIX="$ZOOBINDIR/.."
  30. #check to see if the conf dir is given as an optional argument
  31. if [[ $# -gt 1 ]]; then
  32. if [[ "--config" == "$1" ]]; then
  33. shift
  34. ZOOCFGDIR=$1
  35. shift
  36. fi
  37. fi
  38. if [[ -z $ZOOCFGDIR ]]; then
  39. if [[ -e "$ZOOKEEPER_PREFIX/conf" ]]; then
  40. ZOOCFGDIR="$ZOOBINDIR/../conf"
  41. else
  42. ZOOCFGDIR="$ZOOBINDIR/../etc/zookeeper"
  43. fi
  44. fi
  45. if [[ -f "$ZOOCFGDIR/zookeeper-env.sh" ]]; then
  46. # shellcheck source=bin/zkEnv.sh
  47. . "$ZOOCFGDIR/zookeeper-env.sh"
  48. fi
  49. ZOOCFG=${ZOOCFG:-zoo.cfg}
  50. ZOOCFG="$ZOOCFGDIR/$ZOOCFG"
  51. if [[ -f "$ZOOCFGDIR/java.env" ]]; then
  52. # shellcheck source=bin/zkEnv.sh
  53. . "$ZOOCFGDIR/java.env"
  54. fi
  55. ZOO_LOG_DIR=${ZOO_LOG_DIR:-$ZOOKEEPER_PREFIX/logs}
  56. if [[ -n $JAVA_HOME ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
  57. JAVA="$JAVA_HOME/bin/java"
  58. elif type -p java; then
  59. # ignore unused; used this file is sourced
  60. # shellcheck disable=SC2034
  61. JAVA=java
  62. else
  63. echo "Error: JAVA_HOME is not set and java could not be found in PATH." 1>&2
  64. exit 1
  65. fi
  66. #add the zoocfg dir to classpath
  67. CLASSPATH="$ZOOCFGDIR:$CLASSPATH"
  68. for i in "$ZOOBINDIR"/../zookeeper-server/src/main/resources/lib/*.jar; do
  69. CLASSPATH="$i:$CLASSPATH"
  70. done
  71. #make it work in the binary package
  72. #(use array for LIBPATH to account for spaces within wildcard expansion)
  73. if ls "$ZOOKEEPER_PREFIX"/share/zookeeper/zookeeper-*.jar &>/dev/null; then
  74. LIBPATH=("$ZOOKEEPER_PREFIX"/share/zookeeper/*.jar)
  75. else
  76. #release tarball format
  77. for i in "$ZOOBINDIR"/../zookeeper-*.jar; do
  78. CLASSPATH="$i:$CLASSPATH"
  79. done
  80. LIBPATH=("$ZOOBINDIR"/../lib/*.jar)
  81. fi
  82. for i in "${LIBPATH[@]}"; do
  83. CLASSPATH="$i:$CLASSPATH"
  84. done
  85. #make it work for developers
  86. for d in "$ZOOBINDIR"/../build/lib/*.jar; do
  87. CLASSPATH="$d:$CLASSPATH"
  88. done
  89. #make it work for developers
  90. for d in "$ZOOBINDIR"/../zookeeper-server/target/lib/*.jar; do
  91. CLASSPATH="$d:$CLASSPATH"
  92. done
  93. #make it work for developers
  94. for d in "$ZOOBINDIR"/../zookeeper-metrics-providers/zookeeper-prometheus-metrics/target/lib/*.jar; do
  95. CLASSPATH="$d:$CLASSPATH"
  96. done
  97. #make it work for developers
  98. CLASSPATH="$ZOOBINDIR/../build/classes:$CLASSPATH"
  99. #make it work for developers
  100. CLASSPATH="$ZOOBINDIR/../zookeeper-server/target/classes:$CLASSPATH"
  101. #make it work for developers
  102. CLASSPATH="$ZOOBINDIR/../zookeeper-metrics-providers/zookeeper-prometheus-metrics/target/classes:$CLASSPATH"
  103. case "$(uname)" in
  104. CYGWIN* | MINGW*) cygwin=true ;;
  105. *) cygwin=false ;;
  106. esac
  107. if $cygwin; then
  108. CLASSPATH=$(cygpath -wp "$CLASSPATH")
  109. fi
  110. #echo "CLASSPATH=$CLASSPATH"
  111. export CLASSPATH
  112. # default heap for zookeeper server
  113. ZK_SERVER_HEAP="${ZK_SERVER_HEAP:-1000}"
  114. export SERVER_JVMFLAGS="-Xmx${ZK_SERVER_HEAP}m $SERVER_JVMFLAGS"
  115. # default heap for zookeeper client
  116. ZK_CLIENT_HEAP="${ZK_CLIENT_HEAP:-256}"
  117. export CLIENT_JVMFLAGS="-Xmx${ZK_CLIENT_HEAP}m $CLIENT_JVMFLAGS"