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