#!/bin/bash

function die {
	(>&2 echo "$@")
	exit 1
}

sed -i 's/^change_replication_type = .*/change_replication_type = no/' /etc/pgsync.conf || die "Can't update pgsync.conf"
service pgsync restart || die "Can't restart pgsync"
echo "alter system set synchronous_standby_names = ''; select pg_reload_conf();" | sudo -u postgres psql -q --no-readline 2>/dev/null || die "Can't update postgresql.auto.conf"
sudo -u monitor monrun -r pg_replication_sync
