3 # Written by Peter Palfrader
4 # Based on code by Tollef Fog Heen <tfheen@err.no> based on code by Peter Palfrader
6 # Restart all postgresql clusters that show up in dsa-check-libs when they do
7 # not have connections to them.
13 # returns true (0) if there are connections to that port.
15 local port="$1"; shift
16 local con="$(ss -H -nt "sport = :$port" | wc -l)"
17 if [ "$con" -ge 1 ]; then
25 local version="$1"; shift
26 local name="$1"; shift
28 local fn="/run/postgresql/${version}-${name}.pid"
29 if [ -e "$fn" ] ; then
32 echo "No pidfile at $fn" >&2
38 local version="$1"; shift
39 local name="$1"; shift
40 local port="$1"; shift
42 pid="$(get_pidfile_value "$version" "$name")"
43 while chk_net "$port" && [ "$pid" = "$(get_pidfile_value "$version" "$name")" ]; do
46 systemctl restart "postgresql@${version}-${name}.service"
50 trap "rm -f '$tmpfile'" EXIT
51 /usr/lib/nagios/plugins/dsa-check-libs > "$tmpfile" || true
53 pg_lsclusters -h | while read version name port status; do
54 echo "$status" | grep -q --word-regexp online || continue
55 pid="$(get_pidfile_value "$version" "$name")"
56 grep -q --word-regexp $pid "$tmpfile" || continue
58 handle_cluster $version $name $port