# Written by Peter Palfrader
# Based on code by Tollef Fog Heen <tfheen@err.no> 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
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