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