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
24 # read statd from persistent database
28 mkdir -p $CTDB_VARDIR/state/statd
29 touch $CTDB_VARDIR/state/statd/update-trigger
37 ctdb_service_set_reconfigure
41 ctdb_service_set_reconfigure
45 if ctdb_service_needs_reconfigure ; then
46 ctdb_service_reconfigure
52 # check that statd responds to rpc requests
53 # if statd is not running we try to restart it
54 if ctdb_check_rpc "STATD" 100024 1 >/dev/null ; then
55 (service_name="nfs_statd"; ctdb_counter_init)
57 p="rpc.statd" ; cmd="$p"
58 cmd="${cmd}${STATD_HOSTNAME:+ -n }${STATD_HOSTNAME}"
59 cmd="${cmd}${STATD_PORT:+ -p }${STATD_PORT}"
60 cmd="${cmd}${STATD_OUTGOING_PORT:+ -o }${STATD_OUTGOING_PORT}"
62 service_name="nfs_statd"
64 ctdb_check_counter_limit 10 quiet >/dev/null
66 echo "$ctdb_check_rpc_out"
67 echo "Trying to restart STATD [$cmd]"
73 # check that NFS responds to rpc requests
74 [ "$CTDB_NFS_SKIP_KNFSD_ALIVE_CHECK" = "yes" ] || {
75 if ctdb_check_rpc "NFS" 100003 3 >/dev/null ; then
76 (service_name="nfs_knfsd"; ctdb_counter_init)
79 service_name="nfs_knfsd"
82 ctdb_check_counter_equal 10 || {
83 echo "Trying to restart NFS service"
84 startstop_nfs restart >/dev/null 2>&1 &
88 ctdb_check_counter_limit 15 quiet >/dev/null
90 echo "$ctdb_check_rpc_out"
91 echo "Trying to restart NFS service"
98 # and that its directories are available
99 [ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
100 exportfs | grep -v '^#' | grep '^/' |
101 sed -e 's/[[:space:]]\+[^[:space:]]*$//' |
102 ctdb_check_directories
105 # check that lockd responds to rpc requests
106 ctdb_check_rpc "LOCKD" 100021 1 || {
107 echo "Trying to restart lock manager service"
108 startstop_nfs restart
109 startstop_nfslock restart
113 # mount needs special handling since it is sometimes not started
115 if ctdb_check_rpc "MOUNTD" 100005 1 >/dev/null ; then
116 (service_name="nfs_mountd"; ctdb_counter_init)
119 service_name="nfs_mountd"
122 ctdb_check_counter_equal 5 || {
124 cmd="${p}${MOUNTD_PORT:+ -p }${MOUNTD_PORT}"
125 echo "Trying to restart MOUNTD [${cmd}]"
131 ctdb_check_counter_limit 10 quiet >/dev/null
133 echo "$ctdb_check_rpc_out"
135 cmd="${p}${MOUNTD_PORT:+ -p }${MOUNTD_PORT}"
136 echo "Trying to restart MOUNTD [${cmd}]"
144 # rquotad needs special handling since it is sometimes not started
146 # this is not a critical service so we dont flag the node as unhealthy
147 ctdb_check_rpc "RQUOTAD" 100011 1 || {
149 cmd="${p}${RQUOTAD_PORT:+ -p }${RQUOTAD_PORT}"
150 echo "Trying to restart RQUOTAD [${cmd}]"
155 # once every 60 seconds, update the statd state database for which
156 # clients need notifications
157 LAST_UPDATE=`stat --printf="%Y" $CTDB_VARDIR/state/statd/update-trigger`
158 CURRENT_TIME=`date +"%s"`
159 [ $CURRENT_TIME -ge $(($LAST_UPDATE + 60)) ] && {
160 mkdir -p $CTDB_VARDIR/state/statd
161 touch $CTDB_VARDIR/state/statd/update-trigger
162 $CTDB_BASE/statd-callout updatelocal &
163 $CTDB_BASE/statd-callout updateremote &
168 # if the ips have been reallocated, we must restart the lockmanager
169 # across all nodes and ping all statd listeners
170 [ -x $CTDB_BASE/statd-callout ] && {
171 $CTDB_BASE/statd-callout notify &
175 ctdb_standard_event_handler "$@"