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