summaryrefslogtreecommitdiffstats
path: root/ctdb/config/events.d/60.nfs
blob: f424f8cb2951759270a3bd59c98af2166e5d8ae5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/sh
# script to manage nfs in a clustered environment

start_nfs() {
	/bin/mkdir -p $CTDB_VARDIR/state/nfs
	/bin/mkdir -p $CTDB_VARDIR/state/statd/ip
	startstop_nfs stop
	startstop_nfs start
	echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
}

. $CTDB_BASE/functions

service_name="nfs"
service_start="start_nfs"
service_stop="startstop_nfs stop"

loadconfig

ctdb_start_stop_service

case "$1" in 
     init)
	# read statd from persistent database
	;;
     startup)
	ctdb_service_start
	mkdir -p $CTDB_VARDIR/state/statd
	touch $CTDB_VARDIR/state/statd/update-trigger
	;;

     shutdown)
	ctdb_service_stop
	;;

     takeip)
	ctdb_service_set_reconfigure
	;;

     releaseip)
	ctdb_service_set_reconfigure
	;;

      monitor)
	if ctdb_service_needs_reconfigure ; then
	    ctdb_service_reconfigure
	    exit 0
	fi

	update_tickles 2049

	# check that statd responds to rpc requests
	# if statd is not running we try to restart it
	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


	# check that NFS responds to rpc requests
	[ "$CTDB_NFS_SKIP_KNFSD_ALIVE_CHECK" = "yes" ] || {
	    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
			ctdb_check_counter_limit 10 quiet >/dev/null
		) || {
			echo "$ctdb_check_rpc_out"
			echo "Trying to restart NFS service"
			startstop_nfs restart
			exit 1
		}
		# we haven't hit the failure limit so restart quietly
		startstop_nfs restart >/dev/null 2>&1 &
	    fi
	}

	# 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 $?

	# check that lockd responds to rpc requests
	ctdb_check_rpc "LOCKD" 100021 1 || {
		echo "Trying to restart lock manager service"
		startstop_nfs restart
		startstop_nfslock restart
		exit 1
	}

	# mount needs special handling since it is sometimes not started
	# correctly on RHEL5
	ctdb_check_rpc "MOUNTD" 100005 1 || {
		p="rpc.mountd"
		cmd="${p}${MOUNTD_PORT:+ -p }${MOUNTD_PORT}"
		echo "Trying to restart MOUNTD [${cmd}]"
		killall -q -9 $p
		$cmd &
		exit 1
	}
	# 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
	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 &
	}

	# once every 60 seconds, update the statd state database for which
	# clients need notifications
	LAST_UPDATE=`stat --printf="%Y" $CTDB_VARDIR/state/statd/update-trigger`
	CURRENT_TIME=`date +"%s"`
	expr "$CURRENT_TIME" ">" "(" "$LAST_UPDATE" "+" "60" ")" >/dev/null 2>/dev/null
	[ $? = "0" ] && {
	    mkdir -p $CTDB_VARDIR/state/statd
	    touch $CTDB_VARDIR/state/statd/update-trigger
	    $CTDB_BASE/statd-callout updatelocal &
	    $CTDB_BASE/statd-callout updateremote &
	}
       	;;

    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
	;;
    *)
	ctdb_standard_event_handler "$@"
	;;
esac

exit 0