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