vitess.io/vitess@v0.16.2/go/vt/zkctl/zksrv.sh (about)

     1  #!/bin/bash
     2  
     3  # Copyright 2019 The Vitess Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # 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  
    17  # simple wrapper for starting up zookeeper so it detaches from the parent
    18  # process and ingnores signals
    19  
    20  logdir="$1"
    21  config="$2"
    22  pidfile="$3"
    23  zk_java_opts=${ZK_JAVA_OPTS:-}
    24  zk_ver=${ZK_VERSION:-3.8.0}
    25  classpath="$VTROOT/dist/vt-zookeeper-$zk_ver/lib/zookeeper-$zk_ver-fatjar.jar:/usr/local/lib/zookeeper-$zk_ver-fatjar.jar:/usr/share/java/zookeeper-$zk_ver.jar"
    26  
    27  mkdir -p "$logdir"
    28  touch "$logdir/zksrv.log"
    29  
    30  log() {
    31    now=`/bin/date`
    32    echo "$now $*" >> "$logdir/zksrv.log"
    33    return 0
    34  }
    35  
    36  for java in /usr/local/bin/java /usr/bin/java $JAVA_HOME/bin/java; do
    37    if [ -x "$java" ]; then
    38      break
    39    fi
    40  done
    41  
    42  if [ ! -x "$java" ]; then
    43    log "ERROR no java binary found"
    44    exit 1
    45  fi
    46  
    47  if [ "$VTDEV" ]; then
    48    # use less memory
    49    java="$java -client -Xincgc -Xms1m -Xmx32m"
    50  else
    51    # enable hotspot
    52    java="$java -server"
    53  fi
    54  
    55  
    56  cmd="$java -DZOO_LOG_DIR=$logdir $zk_java_opts -cp $classpath org.apache.zookeeper.server.quorum.QuorumPeerMain $config"
    57  
    58  log "INFO starting $cmd"
    59  $cmd < /dev/null &> /dev/null &
    60  pid=$!
    61  
    62  log "INFO pid: $pid pidfile: $pidfile"
    63  if [ "$pidfile" ]; then
    64    if [ -f "$pidfile" ]; then
    65      rm "$pidfile"
    66    fi
    67    echo "$pid" > "$pidfile"
    68  fi
    69  
    70  wait $pid
    71  log "INFO exit status $pid: $exit_status"
    72