* debian/pg_createconfig_patroni: Add --vip option and write out a

vip-manager configuration if present.
  * debian/config.yml.in: Add @LISTEN_VIP@ tag.
This commit is contained in:
Michael Banck 2019-11-15 19:12:14 +01:00
parent 74b781686d
commit 2dfc33b913
3 changed files with 61 additions and 2 deletions

5
debian/changelog vendored
View file

@ -1,6 +1,9 @@
patroni (1.6.0-5) UNRELEASED; urgency=medium
*
[ Michael Banck ]
* debian/pg_createconfig_patroni: Add --vip option and write out a
vip-manager configuration if present.
* debian/config.yml.in: Add @LISTEN_VIP@ tag.
-- Debian PostgreSQL Maintainers <team+postgresql@tracker.debian.org> Tue, 08 Oct 2019 12:58:40 +0200

View file

@ -75,7 +75,7 @@ postgresql:
pg_clonecluster:
command: /usr/share/patroni/pg_clonecluster_patroni
listen: "@HOSTIP@,127.0.0.1:@PORT@"
listen: "@HOSTIP@@LISTEN_VIP@,127.0.0.1:@PORT@"
connect_address: @HOSTIP@:@PORT@
use_unix_socket: true
data_dir: /var/lib/postgresql/@VERSION@/@CLUSTER@

View file

@ -19,6 +19,10 @@ case $i in
FORCE="y"
shift # past argument=value
;;
--vip=*)
VIP_IP="${i#*=}"
shift # past argument=value
;;
*)
# unknown option
;;
@ -78,6 +82,44 @@ if [ $? != 0 ]; then
fi
DCS_CONFIG="$(egrep -v '^[[:space:]]*$|^ *#' /etc/patroni/dcs.yml | sed -e ':a;N;$!ba;s/\n/\\n/g' -e 's/\$/\\$/g')"
# check vip configuration
if [ -n "$VIP_IP" ]; then
VIP_FILE=/etc/patroni/${VERSION}-${CLUSTER}.vip
if [ ! -e /etc/patroni/vip.in ]; then
echo "VIP template /etc/patroni/vip.in does not exist, cannot write VIP file"
exit 1
fi
if [ $(grep -q LISTEN_VIP /etc/patroni/config.yml.in) ]; then
echo "Patroni configuration template does not have @LISTEN_VIP@ tag"
echo "Postgres will not be able to bind to the VIP $VIP_IP."
exit 1
fi
VIP_IFACE="$(ip -4 route get 8.8.8.8 | grep ^8.8.8.8 | sed -e s/.*dev.// -e s/\ .*//)"
if [ -z "$VIP_IFACE" ]; then
echo "Network interface could not be determined, cannot write VIP file"
exit 1
fi
VIP_MASK="$(ip -o -f inet addr show $VIP_IFACE | awk '{print $4}' | sed -e 's/.*\///' | uniq)"
if [ -z "$VIP_MASK" ]; then
echo "Netmask could not be determined, cannot write VIP file"
exit 1
fi
VIP_KEY="/postgresql-common/${VERSION}-${CLUSTER}/leader"
DCS_TYPE="$(egrep -v '^[[:space:]]*$|^ *#' /etc/patroni/dcs.yml | egrep '(etcd|consul|zookeeper)' | sed s/:.*//)"
if [ -z "$DCS_TYPE" ]; 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
fi
LISTEN_VIP=",$VIP_IP"
else
LISTEN_VIP=
fi
CONFIG_FILE=/etc/patroni/${VERSION}-${CLUSTER}.yml
if [ -f $CONFIG_FILE -a -z "$FORCE" ]; then
@ -117,12 +159,26 @@ cat /etc/patroni/config.yml.in | \
-e "s/@CLUSTER@/${CLUSTER}/g" \
-e "s/@HOSTNAME@/${HOSTNAME}/g" \
-e "s/@HOSTIP@/${HOSTIP}/g" \
-e "s/@LISTEN_VIP@/${LISTEN_VIP}/g" \
-e "s#@NETWORK@#${NETWORK}#g" \
-e "s/@API_PORT@/${API_PORT}/g" \
-e "s/@PORT@/${PORT}/g" \
-e "s/@DCS_CONFIG@/${DCS_CONFIG}/g" \
>> $CONFIG_FILE
# write vip configuration, if requested
if [ -n "$VIP_IP" ]; then
cat /etc/patroni/vip.in | \
sed -e "s/@VIP_IP@/${VIP_IP}/g" \
-e "s/@VIP_MASK@/${VIP_MASK}/g" \
-e "s/@VIP_IFACE@/${VIP_IFACE}/g" \
-e "s#@VIP_KEY@#${VIP_KEY}#g" \
-e "s/@VIP_HOST@/${HOSTNAME}/g" \
-e "s/@VIP_TYPE@/${DCS_TYPE}/g" \
-e "s#@VIP_ENDPOINT@#${DCS_ENDPOINT}#g" \
>> $VIP_FILE
fi
# Set permissions
chown postgres:postgres $CONFIG_FILE
chmod 660 $CONFIG_FILE