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