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