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 [ "$NFS_SERVER_MODE" != "GANESHA" ] || exit 0
22 ctdb_start_stop_service
24 is_ctdb_managed_service || exit 0
28 # read statd from persistent database
32 mkdir -p $CTDB_VARDIR/state/statd
33 touch $CTDB_VARDIR/state/statd/update-trigger
41 ctdb_service_set_reconfigure
45 ctdb_service_set_reconfigure
49 if ctdb_service_needs_reconfigure ; then
50 ctdb_service_reconfigure
56 # check that statd responds to rpc requests
57 # if statd is not running we try to restart it
58 if ctdb_check_rpc "STATD" 100024 1 >/dev/null ; then
59 (service_name="nfs_statd"; ctdb_counter_init)
61 p="rpc.statd" ; cmd="$p"
62 cmd="${cmd}${STATD_HOSTNAME:+ -n }${STATD_HOSTNAME}"
63 cmd="${cmd}${STATD_PORT:+ -p }${STATD_PORT}"
64 cmd="${cmd}${STATD_OUTGOING_PORT:+ -o }${STATD_OUTGOING_PORT}"
66 service_name="nfs_statd"
68 ctdb_check_counter_limit 10 quiet >/dev/null
70 echo "$ctdb_check_rpc_out"
71 echo "Trying to restart STATD [$cmd]"
77 # check that NFS responds to rpc requests
78 [ "$CTDB_NFS_SKIP_KNFSD_ALIVE_CHECK" = "yes" ] || {
79 if ctdb_check_rpc "NFS" 100003 3 >/dev/null ; then
80 (service_name="nfs_knfsd"; ctdb_counter_init)
83 service_name="nfs_knfsd"
86 ctdb_check_counter_equal 10 || {
87 echo "Trying to restart NFS service"
88 startstop_nfs restart >/dev/null 2>&1 &
92 ctdb_check_counter_limit 15 quiet >/dev/null
94 echo "$ctdb_check_rpc_out"
95 echo "Trying to restart NFS service"
102 # and that its directories are available
103 [ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
104 exportfs | grep -v '^#' | grep '^/' |
105 sed -e 's/[[:space:]]\+[^[:space:]]*$//' |
106 ctdb_check_directories
109 # check that lockd responds to rpc requests
110 ctdb_check_rpc "LOCKD" 100021 1 || {
111 echo "Trying to restart lock manager service"
112 startstop_nfs restart
113 startstop_nfslock restart
117 # mount needs special handling since it is sometimes not started
119 if ctdb_check_rpc "MOUNTD" 100005 1 >/dev/null ; then
120 (service_name="nfs_mountd"; ctdb_counter_init)
123 service_name="nfs_mountd"
126 ctdb_check_counter_equal 5 || {
128 cmd="${p}${MOUNTD_PORT:+ -p }${MOUNTD_PORT}"
129 echo "Trying to restart MOUNTD [${cmd}]"
135 ctdb_check_counter_limit 10 quiet >/dev/null
137 echo "$ctdb_check_rpc_out"
139 cmd="${p}${MOUNTD_PORT:+ -p }${MOUNTD_PORT}"
140 echo "Trying to restart MOUNTD [${cmd}]"
148 # rquotad needs special handling since it is sometimes not started
150 # this is not a critical service so we dont flag the node as unhealthy
151 ctdb_check_rpc "RQUOTAD" 100011 1 || {
153 cmd="${p}${RQUOTAD_PORT:+ -p }${RQUOTAD_PORT}"
154 echo "Trying to restart RQUOTAD [${cmd}]"
159 # once every 60 seconds, update the statd state database for which
160 # clients need notifications
161 LAST_UPDATE=`stat --printf="%Y" $CTDB_VARDIR/state/statd/update-trigger 2>/dev/null`
162 CURRENT_TIME=`date +"%s"`
163 [ $CURRENT_TIME -ge $(($LAST_UPDATE + 60)) ] && {
164 mkdir -p $CTDB_VARDIR/state/statd
165 touch $CTDB_VARDIR/state/statd/update-trigger
166 $CTDB_BASE/statd-callout updatelocal &
167 $CTDB_BASE/statd-callout updateremote &
172 # if the ips have been reallocated, we must restart the lockmanager
173 # across all nodes and ping all statd listeners
174 [ -x $CTDB_BASE/statd-callout ] && {
175 $CTDB_BASE/statd-callout notify &
179 ctdb_standard_event_handler "$@"