STATD is 100027 not 1000247
[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 [ "$NFS_SERVER_MODE" != "GANESHA" ] || exit 0
21
22 ctdb_start_stop_service
23
24 is_ctdb_managed_service || exit 0
25
26 case "$1" in 
27      init)
28         # read statd from persistent database
29         ;;
30      startup)
31         ctdb_service_start
32         mkdir -p $CTDB_VARDIR/state/statd
33         touch $CTDB_VARDIR/state/statd/update-trigger
34         ;;
35
36      shutdown)
37         ctdb_service_stop
38         ;;
39
40      takeip)
41         ctdb_service_set_reconfigure
42         ;;
43
44      releaseip)
45         ctdb_service_set_reconfigure
46         ;;
47
48       monitor)
49         if ctdb_service_needs_reconfigure ; then
50             ctdb_service_reconfigure
51             exit 0
52         fi
53
54         update_tickles 2049
55
56         # check that statd responds to rpc requests
57         # if statd is not running we try to restart it
58         # we only do this IF we have a rpc.statd command.
59         # For platforms where rpc.statd does not exist, we skip
60         # the check compeltely
61         p="rpc.statd"
62         which $p >/dev/null 2>/dev/null && {
63                 if ctdb_check_rpc "STATD" 100024 1 >/dev/null ; then
64                         (service_name="nfs_statd"; ctdb_counter_init)
65                 else
66                         cmd="$p"
67                         cmd="${cmd}${STATD_HOSTNAME:+ -n }${STATD_HOSTNAME}"
68                         cmd="${cmd}${STATD_PORT:+ -p }${STATD_PORT}"
69                         cmd="${cmd}${STATD_OUTGOING_PORT:+ -o }${STATD_OUTGOING_PORT}"
70                         (
71                                 service_name="nfs_statd"
72                                 ctdb_counter_incr
73                                 ctdb_check_counter_limit 10 quiet >/dev/null
74                         ) || {
75                                 echo "$ctdb_check_rpc_out"
76                                 echo "Trying to restart STATD [$cmd]"
77                                 $cmd
78                         }
79                 fi
80         }
81
82         # check that NFS responds to rpc requests
83         [ "$CTDB_NFS_SKIP_KNFSD_ALIVE_CHECK" = "yes" ] || {
84             if ctdb_check_rpc "NFS" 100003 3 >/dev/null ; then
85                 (service_name="nfs_knfsd"; ctdb_counter_init)
86             else
87                 (
88                         service_name="nfs_knfsd"
89                         ctdb_counter_incr
90
91                         ctdb_check_counter_equal 10 || {
92                                 echo "Trying to restart NFS service"
93                                 startstop_nfs restart >/dev/null 2>&1 &
94                                 exit 0
95                         }
96
97                         ctdb_check_counter_limit 15 quiet >/dev/null
98                 ) || {
99                         echo "$ctdb_check_rpc_out"
100                         echo "Trying to restart NFS service"
101                         startstop_nfs restart
102                         exit 1
103                 }
104             fi
105         }
106
107         # and that its directories are available
108         [ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
109             exportfs | grep -v '^#' | grep '^/' |
110             sed -e 's/[[:space:]]\+[^[:space:]]*$//' |
111             ctdb_check_directories
112         } || exit $?
113
114         # check that lockd responds to rpc requests
115         if ctdb_check_rpc "LOCKD" 100021 1 >/dev/null ; then
116                 (service_name="lockd"; ctdb_counter_init)
117         else
118                 (
119                         service_name="lockd"
120                         ctdb_counter_incr
121
122                         ctdb_check_counter_equal 10 || {
123                                 echo "Trying to restart NFS lock service"
124                                 startstop_nfs restart >/dev/null 2>&1 &
125                                 startstop_nfslock restart  >/dev/null 2>&1 &
126                                 exit 0
127                         }
128
129                         ctdb_check_counter_limit 15 quiet >/dev/null
130         ) || {
131                         echo "$ctdb_check_rpc_out"
132                         echo "Trying to restart NFS lock service"
133                         startstop_nfs restart
134                         startstop_nfslock restart
135                         exit 1
136                 }
137         fi
138
139         # mount needs special handling since it is sometimes not started
140         # correctly on RHEL5
141         if ctdb_check_rpc "MOUNTD" 100005 1 >/dev/null ; then
142                 (service_name="nfs_mountd"; ctdb_counter_init)
143         else
144         (
145                 service_name="nfs_mountd"
146                 ctdb_counter_incr
147
148                 ctdb_check_counter_equal 5 || {
149                         p="rpc.mountd"
150                         cmd="${p}${MOUNTD_PORT:+ -p }${MOUNTD_PORT}"
151                         echo "Trying to restart MOUNTD [${cmd}]"
152                         killall -q -9 $p
153                         $cmd &
154                         exit 0
155                 }
156
157                 ctdb_check_counter_limit 10 quiet >/dev/null
158         ) || {
159                 echo "$ctdb_check_rpc_out"
160                 p="rpc.mountd"
161                 cmd="${p}${MOUNTD_PORT:+ -p }${MOUNTD_PORT}"
162                 echo "Trying to restart MOUNTD [${cmd}]"
163                 killall -q -9 $p
164                 $cmd &
165                 exit 1
166         }
167         fi
168
169
170         # rquotad needs special handling since it is sometimes not started
171         # correctly on RHEL5
172         # this is not a critical service so we dont flag the node as unhealthy
173         ctdb_check_rpc "RQUOTAD" 100011 1 || {
174                 p="rpc.rquotad"
175                 cmd="${p}${RQUOTAD_PORT:+ -p }${RQUOTAD_PORT}"
176                 echo "Trying to restart RQUOTAD [${cmd}]"
177                 killall -q -9 $p
178                 $cmd &
179         }
180
181         # once every 60 seconds, update the statd state database for which
182         # clients need notifications
183         LAST_UPDATE=`stat --printf="%Y" $CTDB_VARDIR/state/statd/update-trigger 2>/dev/null`
184         CURRENT_TIME=`date +"%s"`
185         [ $CURRENT_TIME -ge $(($LAST_UPDATE + 60)) ] && {
186             mkdir -p $CTDB_VARDIR/state/statd
187             touch $CTDB_VARDIR/state/statd/update-trigger
188             $CTDB_BASE/statd-callout updatelocal &
189             $CTDB_BASE/statd-callout updateremote &
190         }
191         ;;
192
193     ipreallocated)
194         # if the ips have been reallocated, we must restart the lockmanager
195         # across all nodes and ping all statd listeners
196         [ -x $CTDB_BASE/statd-callout ] && {
197                 $CTDB_BASE/statd-callout notify &
198         } >/dev/null 2>&1
199         ;;
200     *)
201         ctdb_standard_event_handler "$@"
202         ;;
203 esac
204
205 exit 0