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