2 # script to manage nfs in a clustered environment
5 /bin/mkdir -p $CTDB_VARDIR/state/nfs
6 /bin/mkdir -p $CTDB_VARDIR/state/statd/ip
9 echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
12 . $CTDB_BASE/functions
15 service_start="start_nfs"
16 service_stop="startstop_nfs stop"
20 ctdb_start_stop_service
22 is_ctdb_managed_service || exit 0
26 # read statd from persistent database
30 mkdir -p $CTDB_VARDIR/state/statd
31 touch $CTDB_VARDIR/state/statd/update-trigger
39 ctdb_service_set_reconfigure
43 ctdb_service_set_reconfigure
47 if ctdb_service_needs_reconfigure ; then
48 ctdb_service_reconfigure
54 # check that statd responds to rpc requests
55 # if statd is not running we try to restart it
56 if ctdb_check_rpc "STATD" 100024 1 >/dev/null ; then
57 (service_name="nfs_statd"; ctdb_counter_init)
59 p="rpc.statd" ; cmd="$p"
60 cmd="${cmd}${STATD_HOSTNAME:+ -n }${STATD_HOSTNAME}"
61 cmd="${cmd}${STATD_PORT:+ -p }${STATD_PORT}"
62 cmd="${cmd}${STATD_OUTGOING_PORT:+ -o }${STATD_OUTGOING_PORT}"
64 service_name="nfs_statd"
66 ctdb_check_counter_limit 10 quiet >/dev/null
68 echo "$ctdb_check_rpc_out"
69 echo "Trying to restart STATD [$cmd]"
75 # check that NFS responds to rpc requests
76 [ "$CTDB_NFS_SKIP_KNFSD_ALIVE_CHECK" = "yes" ] || {
77 if ctdb_check_rpc "NFS" 100003 3 >/dev/null ; then
78 (service_name="nfs_knfsd"; ctdb_counter_init)
81 service_name="nfs_knfsd"
84 ctdb_check_counter_equal 10 || {
85 echo "Trying to restart NFS service"
86 startstop_nfs restart >/dev/null 2>&1 &
90 ctdb_check_counter_limit 15 quiet >/dev/null
92 echo "$ctdb_check_rpc_out"
93 echo "Trying to restart NFS service"
100 # and that its directories are available
101 [ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
102 exportfs | grep -v '^#' | grep '^/' |
103 sed -e 's/[[:space:]]\+[^[:space:]]*$//' |
104 ctdb_check_directories
107 # check that lockd responds to rpc requests
108 ctdb_check_rpc "LOCKD" 100021 1 || {
109 echo "Trying to restart lock manager service"
110 startstop_nfs restart
111 startstop_nfslock restart
115 # mount needs special handling since it is sometimes not started
117 if ctdb_check_rpc "MOUNTD" 100005 1 >/dev/null ; then
118 (service_name="nfs_mountd"; ctdb_counter_init)
121 service_name="nfs_mountd"
124 ctdb_check_counter_equal 5 || {
126 cmd="${p}${MOUNTD_PORT:+ -p }${MOUNTD_PORT}"
127 echo "Trying to restart MOUNTD [${cmd}]"
133 ctdb_check_counter_limit 10 quiet >/dev/null
135 echo "$ctdb_check_rpc_out"
137 cmd="${p}${MOUNTD_PORT:+ -p }${MOUNTD_PORT}"
138 echo "Trying to restart MOUNTD [${cmd}]"
146 # rquotad needs special handling since it is sometimes not started
148 # this is not a critical service so we dont flag the node as unhealthy
149 ctdb_check_rpc "RQUOTAD" 100011 1 || {
151 cmd="${p}${RQUOTAD_PORT:+ -p }${RQUOTAD_PORT}"
152 echo "Trying to restart RQUOTAD [${cmd}]"
157 # once every 60 seconds, update the statd state database for which
158 # clients need notifications
159 LAST_UPDATE=`stat --printf="%Y" $CTDB_VARDIR/state/statd/update-trigger`
160 CURRENT_TIME=`date +"%s"`
161 [ $CURRENT_TIME -ge $(($LAST_UPDATE + 60)) ] && {
162 mkdir -p $CTDB_VARDIR/state/statd
163 touch $CTDB_VARDIR/state/statd/update-trigger
164 $CTDB_BASE/statd-callout updatelocal &
165 $CTDB_BASE/statd-callout updateremote &
170 # if the ips have been reallocated, we must restart the lockmanager
171 # across all nodes and ping all statd listeners
172 [ -x $CTDB_BASE/statd-callout ] && {
173 $CTDB_BASE/statd-callout notify &
177 ctdb_standard_event_handler "$@"