X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=modules%2Fpostgres%2Ffiles%2Fdsa-restart-all-idle-postgres;h=078d50010cc377494b61b43df09789c16a1285cc;hb=83978ebb51dcd06c7a4cc2bd7ebf0a42344fdbed;hp=b0578030355a5537f0119851fb232f76decb82d4;hpb=4ef872d1ef3bdf3466b7d2e8883c1beff2a7d914;p=mirror%2Fdsa-puppet.git diff --git a/modules/postgres/files/dsa-restart-all-idle-postgres b/modules/postgres/files/dsa-restart-all-idle-postgres index b05780303..078d50010 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,14 @@ 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 & - disown + pid="$(get_pidfile_value "$version" "$name")" + grep -q --word-regexp $pid "$tmpfile" || continue + + handle_cluster $version $name $port done