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