Back (Current repo: terraform-mariadb-replica-homelab)

A terraform homelab with mariadb and maxscale for my own understanding and learning.
To clone this repository:
git clone https://git.viktor1993.net/terraform-mariadb-replica-homelab.git
Log | Download | Files | Refs | README

service_discovery.sh (553B)


#!/bin/bash

NUMBER=$1
PORT=$2
ROOT_SRC=$3
TMP=$(mktemp)

maxctrl list servers | awk -v number=$NUMBER -v port=$PORT -f $ROOT_SRC/awk_scripts/service_discovery.awk | sed -e 'H;1h;$!d;x;s/\(.*\),/\1/' > $TMP

if ! head -n1 "$TMP" | grep -Eq '^[0-9]+$'; then
    echo "Failed to derive boundary from maxctrl output" >&2
    exit 1
fi

cat $ROOT_SRC/boundary.txt > $ROOT_SRC/boundary.txt.last
awk '(NR==1){print $0}' $TMP > $ROOT_SRC/boundary.txt
sed -i '1d' $TMP

cat $ROOT_SRC/locals.tf > $ROOT_SRC/locals.tf.last
cat $TMP > $ROOT_SRC/locals.tf

rm $TMP