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