try to restart NFS LOCKD if it failed to start
[sahlberg/ctdb.git] / config / events.d / 60.nfs
1 #!/bin/sh
2 # script to manage nfs in a clustered environment
3
4 start_nfs() {
5         /bin/mkdir -p $CTDB_VARDIR/state/nfs
6         /bin/mkdir -p $CTDB_VARDIR/state/statd/ip
7         startstop_nfs stop
8         startstop_nfs start
9         echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
10 }
11
12 . $CTDB_BASE/functions
13
14 service_name="nfs"
15 service_start="start_nfs"
16 service_stop="startstop_nfs stop"
17
18 loadconfig
19
20 ctdb_start_stop_service
21
22 case "$1" in 
23      init)
24         # read statd from persistent database
25         ;;
26      startup)
27         ctdb_service_start
28         mkdir -p $CTDB_VARDIR/state/statd
29         touch $CTDB_VARDIR/state/statd/update-trigger
30         ;;
31
32      shutdown)
33         ctdb_service_stop
34         ;;
35
36      takeip)
37         ctdb_service_set_reconfigure
38         ;;
39
40      releaseip)
41         ctdb_service_set_reconfigure
42         ;;
43
44       monitor)
45         if ctdb_service_needs_reconfigure ; then
46             ctdb_service_reconfigure
47             exit 0
48         fi
49
50         update_tickles 2049
51
52         # check that statd responds to rpc requests
53         # if statd is not running we try to restart it
54         rpcinfo -u localhost 100024 1 > /dev/null || {
55                 RPCSTATDOPTS=""
56                 [ -n "$STATD_HOSTNAME" ] && RPCSTATDOPTS="$RPCSTATDOPTS -n $STATD_HOSTNAME"
57                 [ -n "$STATD_PORT" ] && RPCSTATDOPTS="$RPCSTATDOPTS -p $STATD_PORT"
58                 [ -n "$STATD_OUTGOING_PORT" ] && RPCSTATDOPTS="$RPCSTATDOPTS -o $STATD_OUTGOING_PORT"
59                 rpc.statd $RPCSTATDOPTS 
60                 echo "ERROR: STATD is not responding. Trying to restart it. [rpc.statd $RPCSTATDOPTS]"
61         }
62
63
64         # check that NFS responds to rpc requests
65         [ "$CTDB_NFS_SKIP_KNFSD_ALIVE_CHECK" = "yes" ] || {
66             (ctdb_check_rpc "NFS" 100003 3)
67             [ $? = "0" ] || {
68                 echo "Trying to restart NFS service"
69                 startstop_nfs restart
70                 exit 1
71             }
72         }
73
74         # and that its directories are available
75         [ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
76             exportfs | grep -v '^#' | grep '^/' |
77             sed -e 's/[[:space:]]\+[^[:space:]]*$//' |
78             ctdb_check_directories
79         } || exit $?
80
81         # check that lockd responds to rpc requests
82         (ctdb_check_rpc "lockd" 100021 1)
83         [ $? = "0" ] || {
84                 echo "Trying to restart lock manager service"
85                 startstop_nfslock restart
86                 exit 1
87         }
88
89         # mount needs special handling since it is sometimes not started
90         # correctly on RHEL5
91         rpcinfo -u localhost 100005 1 > /dev/null || {
92                 echo "ERROR: MOUNTD is not running. Trying to restart it."
93                 RPCMOUNTDOPTS=""
94                 [ -n "$MOUNTD_PORT" ] && RPCMOUNTDOPTS="$RPCMOUNTDOPTS -p $MOUNTD_PORT"
95                 killall -q -9 rpc.mountd
96                 rpc.mountd $RPCMOUNTDOPTS &
97                 exit 1
98         }
99         # rquotad needs special handling since it is sometimes not started
100         # correctly on RHEL5
101         # this is not a critical service so we dont flag the node as unhealthy
102         rpcinfo -u localhost 100011 1 > /dev/null || {
103                 echo "ERROR: RQUOTAD is not running. Trying to restart it."
104                 RPCRQUOTADOPTS=""
105                 [ -n "$RQUOTAD_PORT" ] && RPCRQUOTADOPTS="$RPCRQUOTADOPTS -p $RQUOTAD_PORT"
106                 killall -q -9 rpc.rquotad
107                 rpc.rquotad $RPCRQUOTADOPTS &
108         }
109
110         # once every 60 seconds, update the statd state database for which
111         # clients need notifications
112         LAST_UPDATE=`stat --printf="%Y" $CTDB_VARDIR/state/statd/update-trigger`
113         CURRENT_TIME=`date +"%s"`
114         expr "$CURRENT_TIME" ">" "(" "$LAST_UPDATE" "+" "60" ")" >/dev/null 2>/dev/null
115         [ $? = "0" ] && {
116             mkdir -p $CTDB_VARDIR/state/statd
117             touch $CTDB_VARDIR/state/statd/update-trigger
118             $CTDB_BASE/statd-callout updatelocal &
119             $CTDB_BASE/statd-callout updateremote &
120         }
121         ;;
122
123     ipreallocated)
124         # if the ips have been reallocated, we must restart the lockmanager
125         # across all nodes and ping all statd listeners
126         [ -x $CTDB_BASE/statd-callout ] && {
127                 $CTDB_BASE/statd-callout notify &
128         } >/dev/null 2>&1
129         ;;
130     *)
131         ctdb_standard_event_handler "$@"
132         ;;
133 esac
134
135 exit 0