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