summaryrefslogtreecommitdiffstats
path: root/heartbeat/nfsserver-redhat.sh
blob: aec096605082413e91415812fe5b3ea4d5b4b378 (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
NFS_SYSCONFIG="/etc/sysconfig/nfs"
NFS_SYSCONFIG_LOCAL_BACKUP="/etc/sysconfig/nfs.ha.bu"
NFS_SYSCONFIG_AUTOGEN_TAG="AUTOGENERATED by $0 high availability resource-agent"
NFSCONVERT="$HA_BIN/nfsconvert"

nfsserver_redhat_meta_data() {
cat<<EOF
<parameter name="nfsd_args" unique="0" required="0">
<longdesc lang="en">
Specifies what arguments to pass to the nfs daemon on startup. View the rpc.nfsd man page for information on what arguments are available.
Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file.
</longdesc>
<shortdesc lang="en">
rpc.nfsd options
</shortdesc>
<content type="string" />
</parameter>

<parameter name="lockd_udp_port" unique="0" required="0">
<longdesc lang="en">
The udp port lockd should listen on.
Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file.
</longdesc>
<shortdesc lang="en">
lockd udp port
</shortdesc>
<content type="integer" />
</parameter>

<parameter name="lockd_tcp_port" unique="0" required="0">
<longdesc lang="en">
The tcp port lockd should listen on.
Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file.
</longdesc>
<shortdesc lang="en">
lockd tcp port
</shortdesc>
<content type="integer" />
</parameter>

<parameter name="statd_outgoing_port" unique="0" required="0">
<longdesc lang="en">
The source port number sm-notify uses when sending reboot notifications.
Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file.
</longdesc>
<shortdesc lang="en">
sm-notify source port
</shortdesc>
<content type="integer" />
</parameter>

<parameter name="statd_port" unique="0" required="0">
<longdesc lang="en">
The port number used for RPC listener sockets.
Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file.
</longdesc>
<shortdesc lang="en">
rpc.statd listener port
</shortdesc>
<content type="integer" />
</parameter>

<parameter name="mountd_port" unique="0" required="0">
<longdesc lang="en">
The port number used for rpc.mountd listener sockets.
Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file.
</longdesc>
<shortdesc lang="en">
rpc.mountd listener port
</shortdesc>
<content type="integer" />
</parameter>

<parameter name="rquotad_port" unique="0" required="0">
<longdesc lang="en">
The port number used for rpc.rquotad.
Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file.
</longdesc>
<shortdesc lang="en">
rpc.rquotad port
</shortdesc>
<content type="integer" />
</parameter>
EOF
}

set_arg()
{
	local key="$1"
	local value="$2"
	local file="$3"
	local requires_sysconfig="$4"

	if [ -z "$value" ]; then
		return
	fi

	# only write to the tmp /etc/sysconfig/nfs if sysconfig exists.
	# otherwise this distro does not support setting these options.
	if [ -d "/etc/sysconfig" ]; then
		# replace if the value exists, append otherwise
		if grep "^\s*${key}=" $file ; then
			sed -i "s/\s*${key}=.*$/${key}=\"${value}\"/" $file
		else
			echo "${key}=\"${value}\"" >> $file
		fi
	elif [ "$requires_sysconfig" = "true" ]; then
		ocf_log warn "/etc/sysconfig/nfs not found, unable to set port and nfsd args."
	fi

	export ${key}="${value}"
}

set_env_args()
{
	local tmpconfig=$(mktemp ${HA_RSCTMP}/nfsserver-tmp-XXXXX)
	local statd_args

	if [ -f "$NFS_SYSCONFIG" ]; then
		## Take the $NFS_SYSCONFIG file as our skeleton
		cp $NFS_SYSCONFIG $tmpconfig
	fi

	# nfsd args
	set_arg "RPCNFSDARGS" "$OCF_RESKEY_nfsd_args" "$tmpconfig" "true"

	# mountd args
	if [ -n "$OCF_RESKEY_mountd_port" ]; then
		set_arg "RPCMOUNTDOPTS" "-p $OCF_RESKEY_mountd_port" "$tmpconfig" "true"
	fi

	# statd args. we always want to perform the notify using sm-notify after
	# both rpc.statd and the nfsd daemons are initialized
	statd_args="--no-notify"
	if [ -n "$OCF_RESKEY_statd_outgoing_port" ]; then
		statd_args="$statd_args -o $OCF_RESKEY_statd_outgoing_port"
	fi
	if [ -n "$OCF_RESKEY_statd_port" ]; then
		statd_args="$statd_args -p $OCF_RESKEY_statd_port"
	fi
	set_arg "STATDARG" "$statd_args" "$tmpconfig" "false"

	# lockd ports
	set_arg "LOCKD_UDPPORT" "$OCF_RESKEY_lockd_udp_port" "$tmpconfig" "true"
	set_arg "LOCKD_TCPPORT" "$OCF_RESKEY_lockd_tcp_port" "$tmpconfig" "true"

	# rquotad_port
	if [ -n "$OCF_RESKEY_rquotad_port" ]; then
		set_arg "RPCRQUOTADOPTS" "-p $OCF_RESKEY_rquotad_port" "$tmpconfig" "true"
	fi

	# override local nfs config. preserve previous local config though.
	if [ -s $tmpconfig ]; then
		if [ -f "$NFS_SYSCONFIG" ]; then
			cat $NFS_SYSCONFIG | grep -q -e "$NFS_SYSCONFIG_AUTOGEN_TAG" > /dev/null 2>&1
			if [ $? -ne 0 ]; then
				# backup local nfs config if it doesn't have our HA autogen tag in it.
				mv -f $NFS_SYSCONFIG $NFS_SYSCONFIG_LOCAL_BACKUP
			fi
		fi

		cat $tmpconfig | grep -q -e "$NFS_SYSCONFIG_AUTOGEN_TAG" > /dev/null 2>&1 
		if [ $? -ne 0 ]; then
			echo "# $NFS_SYSCONFIG_AUTOGEN_TAG" > $NFS_SYSCONFIG
			echo "# local config backup stored here, '$NFS_SYSCONFIG_LOCAL_BACKUP'" >> $NFS_SYSCONFIG
			cat $tmpconfig >> $NFS_SYSCONFIG
		else
			cat $tmpconfig > $NFS_SYSCONFIG
		fi
	fi
	rm -f $tmpconfig

	if [ -e "$NFSCONVERT" ]; then
		ocf_log debug "Running $NFSCONVERT"
		$NFSCONVERT
	fi
}