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