2007-06-01 18:10:22 +04:00
#!/bin/sh
# script to manage nfs in a clustered environment
2009-11-19 07:00:17 +03:00
. $CTDB_BASE/functions
2007-06-06 06:08:42 +04:00
2009-11-19 07:00:17 +03:00
service_name="nfs"
2011-08-11 03:39:25 +04:00
service_start ()
{
mkdir -p $CTDB_VARDIR/state/nfs
mkdir -p $CTDB_VARDIR/state/statd/ip
startstop_nfs stop
startstop_nfs start
set_proc "sys/net/ipv4/tcp_tw_recycle" 1
}
service_stop ()
{
startstop_nfs stop
}
2011-01-11 09:13:06 +03:00
service_reconfigure="startstop_nfs restart"
2008-02-11 01:35:37 +03:00
2009-11-19 07:00:17 +03:00
loadconfig
2010-12-04 02:26:22 +03:00
[ "$NFS_SERVER_MODE" != "GANESHA" ] || exit 0
2009-11-19 07:00:17 +03:00
ctdb_start_stop_service
2008-02-11 01:35:37 +03:00
2010-11-18 05:23:40 +03:00
is_ctdb_managed_service || exit 0
2009-12-01 09:43:47 +03:00
case "$1" in
2010-08-30 12:13:28 +04:00
init)
# read statd from persistent database
;;
2007-06-01 18:10:22 +04:00
startup)
2009-11-19 07:00:17 +03:00
ctdb_service_start
2010-10-12 01:02:18 +04:00
mkdir -p $CTDB_VARDIR/state/statd
2010-09-03 06:35:25 +04:00
touch $CTDB_VARDIR/state/statd/update-trigger
2007-06-02 10:44:15 +04:00
;;
shutdown)
2009-11-19 07:00:17 +03:00
ctdb_service_stop
2007-07-06 04:54:42 +04:00
;;
takeip)
2009-11-19 07:00:17 +03:00
ctdb_service_set_reconfigure
2007-06-01 18:10:22 +04:00
;;
releaseip)
2009-11-19 07:00:17 +03:00
ctdb_service_set_reconfigure
2007-06-01 18:10:22 +04:00
;;
2007-06-06 06:08:42 +04:00
monitor)
2011-08-11 01:13:28 +04:00
# and that its directories are available
[ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
exportfs | grep -v '^#' | grep '^/' |
sed -e 's/[[:space:]]\+[^[:space:]]*$//' |
ctdb_check_directories
} || exit $?
2009-11-19 07:00:17 +03:00
if ctdb_service_needs_reconfigure ; then
ctdb_service_reconfigure
exit 0
fi
2010-08-26 08:59:59 +04:00
update_tickles 2049
2008-01-21 04:46:11 +03:00
# check that statd responds to rpc requests
2009-09-15 13:33:53 +04:00
# if statd is not running we try to restart it
2011-01-06 07:42:45 +03:00
# we only do this IF we have a rpc.statd command.
# For platforms where rpc.statd does not exist, we skip
2011-01-11 08:17:06 +03:00
# the check completely
2011-01-06 07:42:45 +03:00
p="rpc.statd"
which $p >/dev/null 2>/dev/null && {
2011-01-11 08:15:41 +03:00
if ctdb_check_rpc "STATD" 100024 1 >/dev/null ; then
2011-01-06 07:42:45 +03:00
(service_name="nfs_statd"; ctdb_counter_init)
else
cmd="$p"
cmd="${cmd}${STATD_HOSTNAME:+ -n }${STATD_HOSTNAME}"
cmd="${cmd}${STATD_PORT:+ -p }${STATD_PORT}"
cmd="${cmd}${STATD_OUTGOING_PORT:+ -o }${STATD_OUTGOING_PORT}"
(
service_name="nfs_statd"
ctdb_counter_incr
ctdb_check_counter_limit 10 quiet >/dev/null
) || {
echo "$ctdb_check_rpc_out"
echo "Trying to restart STATD [$cmd]"
$cmd
}
fi
}
2008-07-08 03:58:10 +04:00
2007-06-06 06:08:42 +04:00
# check that NFS responds to rpc requests
2010-02-11 03:09:39 +03:00
[ "$CTDB_NFS_SKIP_KNFSD_ALIVE_CHECK" = "yes" ] || {
2010-11-16 11:31:18 +03:00
if ctdb_check_rpc "NFS" 100003 3 >/dev/null ; then
(service_name="nfs_knfsd"; ctdb_counter_init)
else
(
service_name="nfs_knfsd"
ctdb_counter_incr
2010-11-17 05:50:56 +03:00
2011-01-11 09:13:57 +03:00
ctdb_check_counter_equal 2 || {
2010-11-17 05:50:56 +03:00
echo "Trying to restart NFS service"
startstop_nfs restart >/dev/null 2>&1 &
exit 0
}
2011-01-11 09:13:57 +03:00
ctdb_check_counter_limit 5 quiet >/dev/null
2010-11-16 11:31:18 +03:00
) || {
echo "$ctdb_check_rpc_out"
echo "Trying to restart NFS service"
startstop_nfs restart
exit 1
}
fi
2010-02-11 03:09:39 +03:00
}
2007-06-06 06:08:42 +04:00
2007-07-06 04:54:42 +04:00
# check that lockd responds to rpc requests
2010-12-22 02:09:35 +03:00
if ctdb_check_rpc "LOCKD" 100021 1 >/dev/null ; then
(service_name="lockd"; ctdb_counter_init)
else
(
service_name="lockd"
ctdb_counter_incr
ctdb_check_counter_equal 10 || {
echo "Trying to restart NFS lock service"
startstop_nfs restart >/dev/null 2>&1 &
startstop_nfslock restart >/dev/null 2>&1 &
exit 0
}
ctdb_check_counter_limit 15 quiet >/dev/null
) || {
echo "$ctdb_check_rpc_out"
echo "Trying to restart NFS lock service"
startstop_nfs restart
startstop_nfslock restart
exit 1
}
fi
2007-10-23 06:35:43 +04:00
# mount needs special handling since it is sometimes not started
# correctly on RHEL5
2010-11-17 05:50:56 +03:00
if ctdb_check_rpc "MOUNTD" 100005 1 >/dev/null ; then
(service_name="nfs_mountd"; ctdb_counter_init)
else
(
service_name="nfs_mountd"
ctdb_counter_incr
ctdb_check_counter_equal 5 || {
p="rpc.mountd"
cmd="${p}${MOUNTD_PORT:+ -p }${MOUNTD_PORT}"
echo "Trying to restart MOUNTD [${cmd}]"
killall -q -9 $p
$cmd &
exit 0
}
ctdb_check_counter_limit 10 quiet >/dev/null
) || {
echo "$ctdb_check_rpc_out"
2010-11-16 11:31:18 +03:00
p="rpc.mountd"
cmd="${p}${MOUNTD_PORT:+ -p }${MOUNTD_PORT}"
echo "Trying to restart MOUNTD [${cmd}]"
killall -q -9 $p
$cmd &
2007-10-23 06:35:43 +04:00
exit 1
}
2010-11-17 05:50:56 +03:00
fi
2010-02-12 05:19:57 +03:00
# rquotad needs special handling since it is sometimes not started
# correctly on RHEL5
# this is not a critical service so we dont flag the node as unhealthy
2010-11-16 11:31:18 +03:00
ctdb_check_rpc "RQUOTAD" 100011 1 || {
p="rpc.rquotad"
cmd="${p}${RQUOTAD_PORT:+ -p }${RQUOTAD_PORT}"
echo "Trying to restart RQUOTAD [${cmd}]"
killall -q -9 $p
$cmd &
2010-02-12 05:19:57 +03:00
}
2010-08-30 12:13:28 +04:00
2011-01-21 02:56:56 +03:00
# once every 600 seconds, update the statd state database for which
2010-08-30 12:13:28 +04:00
# clients need notifications
2010-11-18 05:52:46 +03:00
LAST_UPDATE=`stat --printf="%Y" $CTDB_VARDIR/state/statd/update-trigger 2>/dev/null`
2010-08-30 12:13:28 +04:00
CURRENT_TIME=`date +"%s"`
2011-01-21 02:56:56 +03:00
[ $CURRENT_TIME -ge $(($LAST_UPDATE + 600)) ] && {
2010-10-12 01:02:18 +04:00
mkdir -p $CTDB_VARDIR/state/statd
2010-09-03 06:35:25 +04:00
touch $CTDB_VARDIR/state/statd/update-trigger
2010-08-30 12:13:28 +04:00
$CTDB_BASE/statd-callout updatelocal &
$CTDB_BASE/statd-callout updateremote &
}
2008-07-10 02:05:34 +04:00
;;
2007-06-06 06:08:42 +04:00
2010-08-30 12:13:28 +04:00
ipreallocated)
# if the ips have been reallocated, we must restart the lockmanager
# across all nodes and ping all statd listeners
[ -x $CTDB_BASE/statd-callout ] && {
$CTDB_BASE/statd-callout notify &
} >/dev/null 2>&1
;;
2009-12-01 09:43:47 +03:00
*)
ctdb_standard_event_handler "$@"
2009-11-19 07:00:17 +03:00
;;
2007-06-01 18:10:22 +04:00
esac
exit 0