zkEnv.sh 3.5 KB

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