From 8cb3cbda6eaf7f26bf2eb94cc5f27030d6ae3170 Mon Sep 17 00:00:00 2001 From: Michael Banck Date: Mon, 5 Nov 2018 08:49:40 +0100 Subject: [PATCH] * debian/pg_createconfig_patroni: New script. * debian/dcs.yml, debian/config.yml.in: New configuration templates. * debian/patroni.install: Install new script to /usr/bin and configuration templates to /etc/patroni. --- debian/changelog | 4 ++ debian/config.yml.in | 99 ++++++++++++++++++++++++++++++++++ debian/dcs.yml | 9 ++++ debian/patroni.install | 3 ++ debian/pg_createconfig_patroni | 81 ++++++++++++++++++++++++++++ 5 files changed, 196 insertions(+) create mode 100644 debian/config.yml.in create mode 100644 debian/dcs.yml create mode 100755 debian/pg_createconfig_patroni diff --git a/debian/changelog b/debian/changelog index 60bf378..e04787e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,6 +7,10 @@ patroni (1.5.1-1) UNRELEASED; urgency=medium * debian/patches/consul_import.patch: Likewise. * debian/patches/coverage_binary.patch: Likewise. * debian/patches/startup_scripts.patch: Likewise. + * debian/pg_createconfig_patroni: New script. + * debian/dcs.yml, debian/config.yml.in: New configuration templates. + * debian/patroni.install: Install new script to /usr/bin and configuration + templates to /etc/patroni. -- Debian PostgreSQL Maintainers Fri, 02 Nov 2018 19:23:09 +0100 diff --git a/debian/config.yml.in b/debian/config.yml.in new file mode 100644 index 0000000..545b7b7 --- /dev/null +++ b/debian/config.yml.in @@ -0,0 +1,99 @@ +scope: "@VERSION@-@CLUSTER@" +namespace: "/postgresql-common/" +name: @HOSTNAME@ + +#etcd: +# host: 127.0.0.1:2379 + +#consul: +# host: http://127.0.0.1:8500 +# host: https://127.0.0.1:8500 + +#zookeeper: +# hosts: 127.0.0.1:2181 + +restapi: + listen: @HOSTIP@:8008 + connect_address: @HOSTIP@:8008 +# certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem +# keyfile: /etc/ssl/private/ssl-cert-snakeoil.key +# authentication: +# username: username +# password: password + +# ctl: +# insecure: false # Allow connections to SSL sites without certs +# certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem +# cacert: /etc/ssl/certs/ssl-cacert-snakeoil.pem + +bootstrap: + # Custom bootstrap method + method: pg_createcluster + pg_createcluster: + command: /usr/share/patroni/pg_createcluster_patroni + + # this section will be written into Etcd:///config after initializing new cluster + # and all other cluster members will use it as a `global configuration` + dcs: + ttl: 30 + loop_wait: 10 + retry_timeout: 10 + maximum_lag_on_failover: 1048576 +# master_start_timeout: 300 +# synchronous_mode: false +# standby_cluster: +# host: 127.0.0.1 +# port: 1111 +# primary_slot_name: patroni + postgresql: + use_pg_rewind: true +# use_slots: true + parameters: +# wal_level: hot_standby +# hot_standby: "on" +# wal_keep_segments: 8 +# max_wal_senders: 10 +# max_replication_slots: 10 +# wal_log_hints: "on" +# archive_mode: "on" +# archive_timeout: 1800s +# archive_command: mkdir -p ../wal_archive && test ! -f ../wal_archive/%f && cp %p ../wal_archive/%f +# recovery_conf: +# restore_command: cp ../wal_archive/%f %p + + # some desired options for 'initdb' + initdb: # Note: It needs to be a list (some options need values, others are switches) + - encoding: UTF8 + - data-checksums + + pg_hba: # Add following lines to pg_hba.conf after running 'initdb' + - host replication replicator 127.0.0.1/32 md5 + - host all all 0.0.0.0/0 md5 +# - hostssl all all 0.0.0.0/0 md5 + +postgresql: + # Custom clone method + create_replica_method: + - pg_clonecluster + pg_clonecluster: + command: /usr/share/patroni/pg_clonecluster_patroni + + listen: @HOSTIP@:5432 + connect_address: @HOSTIP@:5432 + data_dir: /var/lib/postgresql/@VERSION@/@CLUSTER@ + bin_dir: /usr/lib/postgresql/@VERSION@/bin + config_dir: /etc/postgresql/@VERSION@/@CLUSTER@ + pgpass: /etc/patroni/pgpass + authentication: + replication: + username: replicator + password: rep-pass +# superuser: +# username: postgres +# password: zalando + parameters: + unix_socket_directories: '/var/run/postgresql/' + # Emulate default Debian/Ubuntu logging + logging_collector: 'on' + log_directory: '/var/log/postgresql' + log_filename: 'postgresql-@VERSION@-@CLUSTER@.log' diff --git a/debian/dcs.yml b/debian/dcs.yml new file mode 100644 index 0000000..e579b32 --- /dev/null +++ b/debian/dcs.yml @@ -0,0 +1,9 @@ +#etcd: +# host: 127.0.0.1:2379 + +#consul: +# host: http://127.0.0.1:8500 +# host: https://127.0.0.1:8500 + +zookeeper: + hosts: 127.0.0.1:2181 diff --git a/debian/patroni.install b/debian/patroni.install index 718e845..5610604 100644 --- a/debian/patroni.install +++ b/debian/patroni.install @@ -3,5 +3,8 @@ extras/startup-scripts/patroni.service lib/systemd/system extras/startup-scripts/patroni@.service lib/systemd/system debian/pg_clonecluster_patroni usr/share/patroni debian/pg_createcluster_patroni usr/share/patroni +debian/pg_createconfig_patroni usr/bin +debian/dcs.yml etc/patroni +debian/config.yml.in etc/patroni debian/tmp/usr/lib debian/tmp/usr/bin diff --git a/debian/pg_createconfig_patroni b/debian/pg_createconfig_patroni new file mode 100755 index 0000000..8d31c18 --- /dev/null +++ b/debian/pg_createconfig_patroni @@ -0,0 +1,81 @@ +#!/bin/sh + +for i in "$@" +do +case $i in + --scope=*) + SCOPE="${i#*=}" + shift # past argument=value + ;; + --hostip=*) + HOSTIP="${i#*=}" + shift # past argument=value + ;; + --force) + FORCE="y" + shift # past argument=value + ;; + *) + # unknown option + ;; +esac +done + +if [ -z "$SCOPE" ]; then + echo "Required option --scope missing" + exit 1 +fi + +# support both '-' and '/' as separator +if [ $(echo $SCOPE | grep -- -) ] +then + VERSION=$(echo $SCOPE | sed -e 's/-.*//') + CLUSTER=$(echo $SCOPE | sed -e 's/.*-//') +else + VERSION=$(echo $SCOPE | sed -e 's/\/.*//') + CLUSTER=$(echo $SCOPE | sed -e 's/.*\///') +fi + +# check DCS configuration +if [ ! -f /etc/patroni/dcs.yml ]; then + echo "DCS not configured yet, edit /etc/patroni/dcs.yml" + exit 1 +fi +grep -v "^#" /etc/patroni/dcs.yml | grep -v "^$" > /dev/null 2>&1 +if [ $? != 0 ]; then + echo "DCS not configured yet, edit /etc/patroni/dcs.yml" + exit 1 +fi + +CONFIG_FILE=/etc/patroni/${VERSION}-${CLUSTER}.yml + +if [ -f $CONFIG_FILE -a -z "$FORCE" ]; then + echo "Patroni configuration file already exists" + exit 1 +else + rm -f $CONFIG_FILE + touch $CONFIG_FILE +fi + +HOSTNAME=$(hostname) + +# set default ipv4 address in case it was not provided +if [ -z "$HOSTIP" ]; then + HOSTIP=$(ip -4 route get 8.8.8.8 | grep ^8.8.8.8 | sed s/.*src.//) +fi + +echo "scope: \"$VERSION-$CLUSTER\"" >> $CONFIG_FILE +echo "namespace: \"/postgresql-common/\"" >> $CONFIG_FILE +echo "name: \"$HOSTNAME\"" >> $CONFIG_FILE +echo "" >> $CONFIG_FILE + +# add DCS configuration +cat /etc/patroni/dcs.yml >> $CONFIG_FILE +echo "" >> $CONFIG_FILE + +# add remaining patroni configuration from template +cat /etc/patroni/config.yml.in | \ + sed -e s/@VERSION@/${VERSION}/ \ + -e s/@CLUSTER@/${CLUSTER}/ \ + -e s/@HOSTIP@/${HOSTIP}/ \ +>> $CONFIG_FILE