Note that exim contains tracker-specific configuration
[mirror/dsa-puppet.git] / modules / bacula / files / bacula-idle-restart
1 #! /bin/sh -e
2
3 # Written by Tollef Fog Heen <tfheen@err.no>
4 # Based on code by Peter Palfrader
5 #
6 # Restart the given bacula director when it's idle.
7 #
8 # XXX: Add locking
9
10 set -e
11
12 if [ "$#" != 2 ];then
13   echo >&2 "$0 <port> <service>"
14   echo "Restart bacula service when port idle"
15   exit 1
16 fi
17
18 PORT="$1"
19 SERVICE="$2"
20
21 # chk_net <port>
22 # returns true (0) if there are connections to that port.
23 chk_net() {
24   local port="$1"; shift
25   local con="$(ss -nt "sport = :$port" | wc -l)"
26   if [ "$con" -gt 1 ]; then
27     return 0
28   else
29     return 1
30   fi
31 }
32
33 while chk_net "$PORT"; do
34     sleep 5
35 done
36
37 service $SERVICE restart