vitess.io/vitess@v0.16.2/examples/common/scripts/zk-up.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  # This is an example script that creates a quorum of ZooKeeper servers.
    18  
    19  source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh"
    20  
    21  cell=${CELL:-'test'}
    22  
    23  # Start ZooKeeper servers.
    24  # The "zkctl init" command won't return until the server is able to contact its
    25  # peers, so we need to start them all in the background and then wait for them.
    26  echo "Starting zk servers..."
    27  for zkid in $zkids; do
    28    action='init'
    29    printf -v zkdir 'zk_%03d' $zkid
    30    if [ -f $VTDATAROOT/$zkdir/myid ]; then
    31      echo "Resuming from existing ZK data dir:"
    32      echo "    $VTDATAROOT/$zkdir"
    33      action='start'
    34    fi
    35    zkctl -zk.myid $zkid -zk.cfg $zkcfg -log_dir $VTDATAROOT/tmp $action \
    36      > $VTDATAROOT/tmp/zkctl_$zkid.out 2>&1 &
    37    pids[$zkid]=$!
    38  done
    39  
    40  # Wait for all the zkctl commands to return.
    41  echo "Waiting for zk servers to be ready..."
    42  
    43  for zkid in $zkids; do
    44    if ! wait ${pids[$zkid]}; then
    45      echo "ZK server number $zkid failed to start. See log:"
    46      echo "    $VTDATAROOT/tmp/zkctl_$zkid.out"
    47    fi
    48  done
    49  
    50  echo "Started zk servers."
    51  
    52  # Add the CellInfo description for the $CELL cell.
    53  # If the node already exists, it's fine, means we used existing data.
    54  set +e
    55  # shellcheck disable=SC2086
    56  vtctl $TOPOLOGY_FLAGS VtctldCommand AddCellInfo \
    57    --root /vitess/$cell \
    58    --server-address $ZK_SERVER \
    59    $cell
    60  set -e
    61  
    62  echo "Configured zk servers."