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