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
start_nfs() {
2010-09-03 06:35:25 +04:00
/bin/mkdir -p $CTDB_VARDIR/state/nfs
/bin/mkdir -p $CTDB_VARDIR/state/statd/ip
2009-11-19 07:00:17 +03:00
startstop_nfs stop
startstop_nfs start
2010-08-26 08:59:59 +04:00
echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
2009-11-19 07:00:17 +03:00
}
2007-06-01 18:10:22 +04:00
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"
service_start="start_nfs"
service_stop="startstop_nfs stop"
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)
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
2010-11-16 11:31:18 +03:00
if ctdb_check_rpc "STATD" 100024 1 >/dev/null ; then
(service_name="nfs_statd"; ctdb_counter_init)
else
p="rpc.statd" ; 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-01-21 04:46:11 +03:00
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
ctdb_check_counter_equal 10 || {
echo "Trying to restart NFS service"
startstop_nfs restart >/dev/null 2>&1 &
exit 0
}
ctdb_check_counter_limit 15 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
# and that its directories are available
2009-03-03 23:21:55 +03:00
[ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
2009-11-20 08:45:36 +03:00
exportfs | grep -v '^#' | grep '^/' |
2010-02-23 13:00:23 +03:00
sed -e 's/[[:space:]]\+[^[:space:]]*$//' |
2009-11-20 08:45:36 +03:00
ctdb_check_directories
} || exit $?
2007-07-06 04:54:42 +04:00
# check that lockd responds to rpc requests
2010-11-16 11:31:18 +03:00
ctdb_check_rpc "LOCKD" 100021 1 || {
2010-10-14 01:12:41 +04:00
echo "Trying to restart lock manager service"
2010-10-28 06:43:57 +04:00
startstop_nfs restart
2010-10-14 01:12:41 +04:00
startstop_nfslock restart
exit 1
}
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
# once every 60 seconds, update the statd state database for which
# 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"`
2010-11-16 11:42:31 +03:00
[ $CURRENT_TIME -ge $(($LAST_UPDATE + 60)) ] && {
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