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