From: Peter Palfrader Date: Thu, 8 Feb 2018 14:47:32 +0000 (+0100) Subject: dsa-restart-all-idle-postgres: only restart pg instances that show up in dsa-check... X-Git-Url: https://git.adam-barratt.org.uk/?a=commitdiff_plain;h=508d78fa792ddd428b75e381c9ad0c09d2c84404;p=mirror%2Fdsa-puppet.git dsa-restart-all-idle-postgres: only restart pg instances that show up in dsa-check-libs --- diff --git a/modules/postgres/files/dsa-restart-all-idle-postgres b/modules/postgres/files/dsa-restart-all-idle-postgres index b05780303..c08a17541 100755 --- a/modules/postgres/files/dsa-restart-all-idle-postgres +++ b/modules/postgres/files/dsa-restart-all-idle-postgres @@ -3,7 +3,8 @@ # Written by Peter Palfrader # Based on code by Tollef Fog Heen based on code by Peter Palfrader # -# Restart all postgresql clusters when they do not have connections to them. +# Restart all postgresql clusters that show up in dsa-check-libs when they do +# not have connections to them. set -e set -u @@ -45,8 +46,15 @@ handle_cluster() { systemctl restart "postgresql@${version}-${name}.service" } +tmpfile="$(tempfile)" +trap "rm -f '$tmpfile'" EXIT +/usr/lib/nagios/plugins/dsa-check-libs > "$tmpfile" || true + pg_lsclusters -h | while read version name port status; do echo "$status" | grep -q --word-regexp online || continue - handle_cluster $version $name $port < /dev/null > /dev/null >&2 & + pid="$(get_pidfile_value "$version" "$name")" + grep -q --word-regexp $pid "$tmpfile" || continue + + handle_cluster $version $name $port < /dev/null > /dev/null 2>&1 & disown done