|
| 1 | +#!/usr/bin/env 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 | +# This script should be sourced into other zookeeper |
| 19 | +# scripts to setup the env variables |
| 20 | + |
| 21 | +# We use ZOOCFGDIR if defined, |
| 22 | +# otherwise we use /etc/zookeeper |
| 23 | +# or the conf directory that is |
| 24 | +# a sibling of this script's directory. |
| 25 | +# Or you can specify the ZOOCFGDIR using the |
| 26 | +# '--config' option in the command line. |
| 27 | + |
| 28 | +ZOOBINDIR="${ZOOBINDIR:-/usr/bin}" |
| 29 | +ZOOKEEPER_PREFIX="${ZOOBINDIR}/.." |
| 30 | + |
| 31 | +#check to see if the conf dir is given as an optional argument |
| 32 | +if [ $# -gt 1 ] |
| 33 | +then |
| 34 | + if [ "--config" = "$1" ] |
| 35 | + then |
| 36 | + shift |
| 37 | + confdir=$1 |
| 38 | + shift |
| 39 | + ZOOCFGDIR=$confdir |
| 40 | + fi |
| 41 | +fi |
| 42 | + |
| 43 | +if [ "x$ZOOCFGDIR" = "x" ] |
| 44 | +then |
| 45 | + if [ -e "${ZOOKEEPER_PREFIX}/conf" ]; then |
| 46 | + ZOOCFGDIR="$ZOOBINDIR/../conf" |
| 47 | + else |
| 48 | + ZOOCFGDIR="$ZOOBINDIR/../etc/zookeeper" |
| 49 | + fi |
| 50 | +fi |
| 51 | + |
| 52 | +if [ -f "${ZOOCFGDIR}/zookeeper-env.sh" ]; then |
| 53 | + . "${ZOOCFGDIR}/zookeeper-env.sh" |
| 54 | +fi |
| 55 | + |
| 56 | +if [ "x$ZOOCFG" = "x" ] |
| 57 | +then |
| 58 | + ZOOCFG="zoo.cfg" |
| 59 | +fi |
| 60 | + |
| 61 | +ZOOCFG="$ZOOCFGDIR/$ZOOCFG" |
| 62 | + |
| 63 | +if [ -f "$ZOOCFGDIR/java.env" ] |
| 64 | +then |
| 65 | + . "$ZOOCFGDIR/java.env" |
| 66 | +fi |
| 67 | + |
| 68 | +if [ "x${ZOO_LOG_DIR}" = "x" ] |
| 69 | +then |
| 70 | + ZOO_LOG_DIR="$ZOOKEEPER_PREFIX/logs" |
| 71 | +fi |
| 72 | + |
| 73 | +if [ "x${ZOO_LOG4J_PROP}" = "x" ] |
| 74 | +then |
| 75 | + ZOO_LOG4J_PROP="INFO,CONSOLE" |
| 76 | +fi |
| 77 | + |
| 78 | +if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then |
| 79 | + JAVA="$JAVA_HOME/bin/java" |
| 80 | +elif type -p java; then |
| 81 | + JAVA=java |
| 82 | +else |
| 83 | + echo "Error: JAVA_HOME is not set and java could not be found in PATH." 1>&2 |
| 84 | + exit 1 |
| 85 | +fi |
| 86 | + |
| 87 | +#add the zoocfg dir to classpath |
| 88 | +CLASSPATH="$ZOOCFGDIR:$CLASSPATH" |
| 89 | + |
| 90 | +for i in "$ZOOBINDIR"/../zookeeper-server/src/main/resources/lib/*.jar |
| 91 | +do |
| 92 | + CLASSPATH="$i:$CLASSPATH" |
| 93 | +done |
| 94 | + |
| 95 | +#make it work in the binary package |
| 96 | +#(use array for LIBPATH to account for spaces within wildcard expansion) |
| 97 | +if ls "${ZOOKEEPER_PREFIX}"/share/zookeeper/zookeeper-*.jar > /dev/null 2>&1; then |
| 98 | + LIBPATH=("${ZOOKEEPER_PREFIX}"/share/zookeeper/*.jar) |
| 99 | +else |
| 100 | + #release tarball format |
| 101 | + for i in "$ZOOBINDIR"/../zookeeper-*.jar |
| 102 | + do |
| 103 | + CLASSPATH="$i:$CLASSPATH" |
| 104 | + done |
| 105 | + LIBPATH=("${ZOOBINDIR}"/../lib/*.jar) |
| 106 | +fi |
| 107 | + |
| 108 | +for i in "${LIBPATH[@]}" |
| 109 | +do |
| 110 | + CLASSPATH="$i:$CLASSPATH" |
| 111 | +done |
| 112 | + |
| 113 | +#make it work for developers |
| 114 | +for d in "$ZOOBINDIR"/../build/lib/*.jar |
| 115 | +do |
| 116 | + CLASSPATH="$d:$CLASSPATH" |
| 117 | +done |
| 118 | + |
| 119 | +for d in "$ZOOBINDIR"/../zookeeper-server/target/lib/*.jar |
| 120 | +do |
| 121 | + CLASSPATH="$d:$CLASSPATH" |
| 122 | +done |
| 123 | + |
| 124 | +#make it work for developers |
| 125 | +CLASSPATH="$ZOOBINDIR/../build/classes:$CLASSPATH" |
| 126 | + |
| 127 | +#make it work for developers |
| 128 | +CLASSPATH="$ZOOBINDIR/../zookeeper-server/target/classes:$CLASSPATH" |
| 129 | + |
| 130 | +case "`uname`" in |
| 131 | + CYGWIN*|MINGW*) cygwin=true ;; |
| 132 | + *) cygwin=false ;; |
| 133 | +esac |
| 134 | + |
| 135 | +if $cygwin |
| 136 | +then |
| 137 | + CLASSPATH=`cygpath -wp "$CLASSPATH"` |
| 138 | +fi |
| 139 | + |
| 140 | +#echo "CLASSPATH=$CLASSPATH" |
| 141 | + |
| 142 | +ZK_SERVER_HEAP="-XX:InitialRAMPercentage=30 -XX:MaxRAMPercentage=70 -XX:MinRAMPercentage=70" |
| 143 | +ZK_PERF_OPTS="-server --illegal-access=permit -XX:+UseG1GC -XX:MetaspaceSize=96m -XX:G1HeapRegionSize=16M -XX:MinMetaspaceFreeRatio=50 -XX:MaxMetaspaceFreeRatio=80 -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+ExplicitGCInvokesConcurrent -Djava.awt.headless=true -Dsun.net.inetaddr.ttl=60" |
| 144 | +export SERVER_JVMFLAGS="$ZK_SERVER_HEAP $ZK_PERF_OPTS $SERVER_JVMFLAGS" |
| 145 | + |
| 146 | +# default heap for zookeeper client |
| 147 | +ZK_CLIENT_HEAP="${ZK_CLIENT_HEAP:-256}" |
| 148 | +export CLIENT_JVMFLAGS="-Xmx${ZK_CLIENT_HEAP}m $CLIENT_JVMFLAGS" |
0 commit comments