try to restart statd everytime it fails, not just the first time
[metze/ctdb/wip.git] / config / events.d / 60.nfs
1 #!/bin/sh
2 # script to manage nfs in a clustered environment
3
4 . $CTDB_BASE/functions
5 loadconfig ctdb
6 loadconfig nfs
7
8 [ "$CTDB_MANAGES_NFS" = "yes" ] || exit 0
9 [ -z "$STATD_SHARED_DIRECTORY" ] && exit 0
10
11 cmd="$1"
12 shift
13
14 PATH=/usr/bin:/bin:/usr/sbin:/sbin:$PATH
15
16
17
18 case $cmd in 
19      startup)
20         /bin/mkdir -p $CTDB_BASE/state/nfs
21         /bin/mkdir -p $CTDB_BASE/state/statd/ip
22         /bin/mkdir -p $STATD_SHARED_DIRECTORY
23
24         # make sure nfs is stopped before we start it, or it may get a bind error
25         startstop_nfs stop
26         startstop_nfs start
27         ;;
28
29      shutdown)
30         startstop_nfs stop
31         exit 0
32         ;;
33
34      takeip)
35         ip=$2
36
37         echo $ip >> $CTDB_BASE/state/statd/restart
38
39         # having a list of what IPs we have allows statd to do the right 
40         # thing via $CTDB_BASE/statd-callout
41         touch $CTDB_BASE/state/statd/ip/$ip
42         exit 0
43         ;;
44
45      releaseip)
46         iface=$1
47         ip=$2
48         maskbits=$3
49
50         echo $ip >> $CTDB_BASE/state/statd/restart
51         /bin/rm -f $CTDB_BASE/state/statd/ip/$ip
52         exit 0
53         ;;
54
55      recovered)
56         # if no IPs have changed then don't need to restart statd 
57         [ -f $CTDB_BASE/state/statd/restart ] || exit 0;
58
59         # always restart the lockmanager so that we start with a clusterwide
60         # graceperiod when ip addresses has changed
61         [ -x $CTDB_BASE/statd-callout ] && {
62                 $CTDB_BASE/statd-callout notify &
63         } >/dev/null 2>&1
64
65         /bin/rm -f $CTDB_BASE/state/statd/restart
66         ;;
67
68       monitor)
69         # check that statd responds to rpc requests
70         # if statd is not running we try to restart it
71         rpcinfo -u localhost 100024 1 > /dev/null || {
72                 RPCSTATDOPTS=""
73                 [ -n "$STATD_HOSTNAME" ] && RPCSTATDOPTS="$RPCSTATDOPTS -n $STATD_HOSTNAME"
74                 [ -n "$STATD_PORT" ] && RPCSTATDOPTS="$RPCSTATDOPTS -p $STATD_PORT"
75                 [ -n "$STATD_OUTGOING_PORT" ] && RPCSTATDOPTS="$RPCSTATDOPTS -o $STATD_OUTGOING_PORT"
76                 rpc.statd $RPCSTATDOPTS 
77                 echo "ERROR: STATD is not responding. Trying to restart it. [rpc.statd $RPCSTATDOPTS]"
78         }
79
80
81         # check that NFS responds to rpc requests
82         ctdb_check_rpc "NFS" 100003 3
83
84         # and that its directories are available
85         [ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
86             nfs_dirs=$(exportfs | grep -v '^#' | grep '^/' | awk {'print $1;'})
87             ctdb_check_directories "nfs" $nfs_dirs
88         }
89
90         # check that lockd responds to rpc requests
91         ctdb_check_rpc "lockd" 100021 1
92         ctdb_check_directories "statd" $STATD_SHARED_DIRECTORY
93
94         # mount needs special handling since it is sometimes not started
95         # correctly on RHEL5
96         rpcinfo -u localhost 100005 1 > /dev/null || {
97                 echo "ERROR: MOUNTD is not running. Trying to restart it."
98                 RPCMOUNTDOPTS=""
99                 [ -n "$MOUNTD_PORT" ] && RPCMOUNTDOPTS="$RPCMOUNTDOPTS -p $MOUNTD_PORT"
100                 killall -q -9 rpc.mountd
101                 rpc.mountd $RPCMOUNTDOPTS &
102                 exit 1
103         }
104         ;;
105
106 esac
107
108 exit 0