From d0aa441487c5c3e00c4f38875cb6eaefd457bef6 Mon Sep 17 00:00:00 2001 From: Michael Banck Date: Sat, 16 Nov 2019 15:43:03 +0100 Subject: [PATCH] * debian/pg_createconfig_patroni: Add --endpoint option for explicit setting of VIP_ENDPOINT, make dcs.yml parsing a bit more robust and add sanity checking for VIP_ENDPOINT. --- debian/changelog | 5 ++++- debian/pg_createconfig_patroni | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index 8f2b123..2e3d424 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,9 @@ patroni (1.6.1-2) UNRELEASED; urgency=medium - * + [ Michael Banck ] + * debian/pg_createconfig_patroni: Add --endpoint option for explicit setting + of VIP_ENDPOINT, make dcs.yml parsing a bit more robust and add sanity + checking for VIP_ENDPOINT. -- Debian PostgreSQL Maintainers Fri, 15 Nov 2019 19:49:57 +0100 diff --git a/debian/pg_createconfig_patroni b/debian/pg_createconfig_patroni index 31bb8e0..dff9b37 100755 --- a/debian/pg_createconfig_patroni +++ b/debian/pg_createconfig_patroni @@ -23,6 +23,10 @@ case $i in VIP_IP="${i#*=}" shift # past argument=value ;; + --endpoint=*) + DCS_ENDPOINT="${i#*=}" + shift # past argument=value + ;; *) # unknown option ;; @@ -110,10 +114,20 @@ if [ -n "$VIP_IP" ]; then echo "DCS type could not be determined from /etc/patroni/dcs.yml, cannot write VIP file" exit 1 fi - DCS_ENDPOINT="$(egrep -v '^[[:space:]]*$|^ *#' /etc/patroni/dcs.yml | grep 'host' | sed -r -e s/.*host:// -e s/-// -e 's/ //g' -e 's/^([0-9])/http:\/\/\1/')" if [ -z "$DCS_ENDPOINT" ]; then - echo "DCS endpoint URL could not be determined from /etc/patroni/dcs.yml, cannot write VIP file" - exit 1 + DCS_ENDPOINT="$(egrep -v '^[[:space:]]*$|^ *#' /etc/patroni/dcs.yml | egrep '(host|-)' | egrep '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+' | sed -r -e s/.*host:// -e s/-// -e 's/ //g' -e 's/^([0-9])/http:\/\/\1/')" + if [ -z "$DCS_ENDPOINT" ]; then + echo "DCS endpoint URL could not be determined from /etc/patroni/dcs.yml and --endpoint not provided, cannot write VIP file" + exit 1 + fi + if [ $(echo "$DCS_ENDPOINT" | wc -l) != 1 ]; then + echo "DCS endpoint URL could not be determined from /etc/patroni/dcs.yml and --endpoint not provided, cannot write VIP file" + exit 1 + fi + fi + if ! $(echo "$DCS_ENDPOINT" | egrep -q '^http.*://[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+:[[:digit:]]+$'); then + echo "DCS endpoint URL not in 'http://1.2.3.4:1234' format, cannot write VIP file" + exit 1 fi LISTEN_VIP=",$VIP_IP" else