8c12443
#!/usr/bin/sh
8c12443
# This script is simple wrapper around garbd, that parses startup configuration.
8c12443
# Its main purpose is to bridge the differences between initscript and systemd unit file.
8c12443
8c12443
CONFIG_FILE=/etc/sysconfig/garb
8c12443
8c12443
source $CONFIG_FILE
8c12443
8c12443
# Check that node addresses and group name are configured
8c12443
if [ -z "$GALERA_NODES" ]; then
8c12443
  echo "List of GALERA_NODES is not configured" >&2
8c12443
  exit 1
8c12443
fi
8c12443
if [ -z "$GALERA_GROUP" ]; then
8c12443
  echo "GALERA_GROUP name is not configured" >&2
8c12443
  exit 1
8c12443
fi
8c12443
8c12443
GALERA_PORT=${GALERA_PORT:-4567}
8c12443
8c12443
# Find a working node
8c12443
for ADDRESS in ${GALERA_NODES} 0; do
8c12443
  HOST=$(echo $ADDRESS | cut -d \: -f 1)
8c12443
  PORT=$(echo $ADDRESS | cut -s -d \: -f 2)
8c12443
  PORT=${PORT:-$GALERA_PORT}
8c12443
  ncat --send-only --recv-only $HOST $PORT >/dev/null && break
8c12443
done
8c12443
if [ ${ADDRESS} == "0" ]; then
8c12443
  echo "None of the nodes in GALERA_NODES is accessible" >&2
8c12443
  exit 1
8c12443
fi
8c12443
8c12443
OPTIONS="-a gcomm://$ADDRESS"
8c12443
[ -n "$GALERA_GROUP" ]   && OPTIONS="$OPTIONS -g $GALERA_GROUP"
8c12443
[ -n "$GALERA_OPTIONS" ] && OPTIONS="$OPTIONS -o $GALERA_OPTIONS"
8c12443
[ -n "$LOG_FILE" ]       && OPTIONS="$OPTIONS -l $LOG_FILE"
8c12443
8c12443
exec /usr/sbin/garbd $OPTIONS