Old pgs_register.ksh
1 #!/usr/bin/ksh
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the License).
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/CDDL.txt
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/CDDL.txt.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets [] replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #ident "%Z%%M% %I% %E% SMI"
29
30 #
31 # This script takes 1 options.
32 # -f filename states a config file different from pgs_config.
33 # This file will be sourced instead of pgs_config if -f filename is specified
34 #
35
36
37 # Set generic variables:
38
39 BINDIR=/opt/SUNWscPostgreSQL/bin
40 UTILDIR=/opt/SUNWscPostgreSQL/util
41 SMFUTILDIR=/opt/SUNWsczone/sczsmf/util
42 DIRNAME=/usr/bin/dirname
43 ECHO=/usr/bin/${ECHO}
44
45 MYNAME=`basename ${0}`
46 MYDIR=`dirname ${0}`
47
48 . ${MYDIR}/../etc/config
49 . ${MYDIR}/../lib/functions_static
50 . ${MYDIR}/../bin/functions
51
52
53 global_zone()
54 {
55 # function to register a resource in the Solaris 10 global zone or on Solaris 8 or 9
56
57 RESOURCEGROUP=${RG}
58
59 if ! create_pfile
60 then
61 return 1
62 fi
63
64 # define your start, stop, probe an validate command
65
66 start_command="${BINDIR}/control_pgs -R ${RS} -G ${RG} -P ${PFILE} start"
67 stop_command="${BINDIR}/control_pgs -R ${RS} -G ${RG} -P ${PFILE} stop"
68 probe_command="${BINDIR}/control_pgs -R ${RS} -G ${RG} -P ${PFILE} probe"
69 validate_command="${BINDIR}/control_pgs -R ${RS} -G ${RG} -P ${PFILE} validate"
70
71 # register your resource
72
73 if /usr/cluster/bin/scrgadm -pvv -t SUNW.gds | /usr/bin/grep Validate_command>/dev/null 2>&1
74 then
75
76 # register in 3.2 style
77
78 if [ -n "${LH}" ]
79 then
80 /usr/cluster/bin/scrgadm -a -j ${RS} -g ${RG} -t SUNW.gds \
81 -x Start_command="${start_command}" \
82 -x Stop_command="${stop_command}" \
83 -x Probe_command="${probe_command}" \
84 -x Validate_command="${validate_command}" \
85 -y Port_list=${PORT}/tcp -y Network_resources_used=${LH} \
86 -x Stop_signal=9 -y Retry_interval=900 \
87 -y Resource_dependencies=${HAS_RS}
88
89 St=$?
90 else
91 /usr/cluster/bin/scrgadm -a -j ${RS} -g ${RG} -t SUNW.gds \
92 -x Start_command="${start_command}" \
93 -x Stop_command="${stop_command}" \
94 -x Probe_command="${probe_command}" \
95 -x Validate_command="${validate_command}" \
96 -x Network_aware=false \
97 -x Stop_signal=9 -y Retry_interval=900 \
98 -y Resource_dependencies=${HAS_RS}
99
100 St=$?
101 fi
102 else
103
104 # register in 3.1 style
105
106 if [ -n "${LH}" ]
107 then
108 /usr/cluster/bin/scrgadm -a -j ${RS} -g ${RG} -t SUNW.gds \
109 -x Start_command="${start_command}" \
110 -x Stop_command="${stop_command}" \
111 -x Probe_command="${probe_command}" \
112 -y Port_list=${PORT}/tcp -y Network_resources_used=${LH} \
113 -x Stop_signal=9 -y Retry_interval=900 \
114 -y Resource_dependencies=${HAS_RS}
115
116 St=$?
117 else
118 /usr/cluster/bin/scrgadm -a -j ${RS} -g ${RG} -t SUNW.gds \
119 -x Start_command="${start_command}" \
120 -x Stop_command="${stop_command}" \
121 -x Probe_command="${probe_command}" \
122 -x Network_aware=false \
123 -x Stop_signal=9 -y Retry_interval=900 \
124 -y Resource_dependencies=${HAS_RS}
125
126 St=$?
127 fi
128
129 fi
130
131 if [ "${St}" -ne 0 ]; then
132 ${ECHO} "Registration of resource ${RS} failed, please correct the wrong parameters."
133
134 return 1
135 else
136 ${ECHO} "Registration of resource ${RS} succeeded."
137 fi
138
139 # validate the resource only, if the validation is not present
140
141 if ! /usr/cluster/bin/scrgadm -pvv -t SUNW.gds | /usr/bin/grep Validate_command>/dev/null 2>&1
142 then
143
144 # VALIDATE RESOURCE
145
146 ${ECHO} "Validate resource ${RS} in resourcegroup ${RG}"
147
148 # determine whether the resource runs in the global zone or in a prepared zone
149 # and set the zcommand to the appropriate zlogin comand
150
151 zcommand=
152 rgs_zone=$(rgs_zonename)
153 if [ -n "${rgs_zone}" ]
154 then
155 zcommand="/usr/sbin/zlogin ${rgs_zone} "
156 fi
157
158 # validate the contents of the parameter file
159
160 ${zcommand} ${BINDIR}/control_pgs -R ${RS} -G ${RG} -P ${PFILE} validate
161
162 St=$?
163
164 if [ "${St}" -ne 0 ]; then
165 ${ECHO} "Validation of resource ${RS} failed, please correct the wrong parameters."
166 ${ECHO} "Removing resource ${RS} from the cluster configuration."
167
168 /usr/cluster/bin/scrgadm -r -j ${RS}
169
170 return 1
171 else
172 ${ECHO} "Validation of resource ${RS} succeeded."
173 fi
174 fi
175
176 return 0
177
178 }
179
180 local_zone_smf()
181 {
182
183 # function to register a smf resource
184
185 SERVICE_TAG=svc:/application/sczone-agents:${RS}
186
187 if [ ! -f ${SMFUTILDIR}/sczsmf_config ]
188 then
189 ${ECHO} ${SMFUTILDIR}/sczsmf_config does not exist. Make sure, that \
190 Sun Cluster HA for Solaris container is intalled in the global zone
191 return 1
192 fi
193
194 # prepare the config file
195
196 cp ${SMFUTILDIR}/sczsmf_config ${SMFUTILDIR}/sczsmf_config.work
197 cat << EOF > ${SMFUTILDIR}/sczsmf_config
198
199 #
200 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
201 # Use is subject to license terms.
202 #
203 # This file will be sourced in by sczsmf_register and the parameters
204 # listed below will be used.
205 #
206 # These parameters can be customized in (key=value) form
207 #
208 # RS - Name of the resource
209 # RG - Name of the resource group containing RS
210 # SCZBT_RS - Name of the SC Zone boot resource
211 # ZONE - Name of the Zone
212 #
213 # For SERVICE, RECURSIVE and STATE, refer to the svcadm(1M)
214 # man page
215 #
216 # SERVICE - {FMRI | pattern}
217 # FMRI - Fault management resource identifier
218 # pattern - Pattern matching a service
219 #
220 # RECURSIVE - {false | true} Default: true
221 # False - Just enable the service and no dependents
222 # True - Enable the service and recursively enable
223 # its dependents
224 #
225 # RECURSIVE=true equates to svcadm enable "-r"
226 #
227 # STATE - {false | true} Default: true
228 # False - Do not wait until service state is reached
229 # True - Wait until service state is reached
230 #
231 # STATE=true equates to svcadm enable/disable "-s"
232 #
233 # SERVICE_PROBE - Script to check the SMF service
234 #
235 # The optional parameter, SERVICE_PROBE, provides the
236 # ability to check that the SMF service is working.
237 # This must be a script within the zone and must
238 # adhere to these return codes,
239 #
240 # 0 - The SMF service is working
241 # 100 - The SMF service should be restarted
242 # 201 - The SMF service should initiate a failover of
243 # the Resource Group
244 #
245 # Note: That return code 201, requires that this resource
246 # has an appropriate extension property value for
247 # FAILOVER_MODE and FAILOVER_ENABLED=TRUE
248 #
249 # For FAILOVER_MODE refer to the r_properties(5) man page.
250 #
251
252 RS=${RS}
253 RG=${RG}
254 SCZBT_RS=${ZONE_BT}
255 ZONE=${ZONE}
256 SERVICE=${SERVICE_TAG}
257 RECURSIVE=false
258 STATE=true
259 SERVICE_PROBE="${BINDIR}/control_pgs probe ${SERVICE_TAG}"
260
261 EOF
262
263 # determine if a working copy of the config file was created if yes use the -f option
264
265 REGOPT=""
266 if [ -f ${UTILDIR}/pgs_config.work ]
267 then
268 /usr/bin/cat ${UTILDIR}/pgs_config.work | /usr/sbin/zlogin ${ZONE} /usr/bin/cat - \>/tmp/pgs_config.work
269 REGOPT="-f /tmp/pgs_config.work"
270 else
271 /usr/bin/cat ${UTILDIR}/pgs_config | /usr/sbin/zlogin ${ZONE} /usr/bin/cat - \>/tmp/pgs_config.work
272 REGOPT="-f /tmp/pgs_config.work"
273 fi
274
275 ${ECHO} clean up the manifest / smf resource
276 ${UTILDIR}/pgs_smf_remove ${REGOPT} 2>/dev/null
277
278 # register the manifest
279
280 if /usr/sbin/zlogin ${ZONE} ${UTILDIR}/pgs_smf_register ${REGOPT}
281 then
282 ${ECHO} "Manifest svc:/application/sczone-agents:${RS} was created in zone ${ZONE}"
283 ${ECHO} "Registering the zone smf resource"
284 ksh ${SMFUTILDIR}/sczsmf_register
285 ret_code=${?}
286 if [ ${ret_code} -eq 0 ]
287 then
288 ${ECHO} "set the Retry_interval to 900"
289 /usr/cluster/bin/scrgadm -c -j ${RS} -y Retry_interval=900
290 fi
291 mv ${SMFUTILDIR}/sczsmf_config.work ${SMFUTILDIR}/sczsmf_config
292 else
293 ${ECHO} "The registration of the manifest did not complete, fix the errors and retry"
294 ret_code=0
295 fi
296
297 /usr/sbin/zlogin ${ZONE} /usr/bin/rm /tmp/pgs_config.work
298
299 return ${ret_code}
300
301 }
302
303
304 MYCONFIG=
305 ZONETYPE=global
306
307 typeset opt
308
309 while getopts 'f:' opt
310 do
311 case "${opt}" in
312 f) MYCONFIG=${OPTARG};;
313 *) ${ECHO} "ERROR: ${MYNAME} Option ${OPTARG} unknown - early End. Only -f is valid"
314 exit 1;;
315 esac
316 done
317
318 # Sourcing the specified config file, either the default one,
319 # or the one supplied with -f
320
321 if [ -n "${MYCONFIG}" ] && [ -f "${MYCONFIG}" ]
322 then
323 ${ECHO} "sourcing ${MYCONFIG} and create a working copy under ${UTILDIR}/pgs_config.work"
324 cp ${MYCONFIG} ${UTILDIR}/pgs_config.work
325 . ${MYCONFIG}
326 else
327 PKGCONF=`dirname $0`/pgs_config
328 ${ECHO} "sourcing ${PKGCONF}"
329 . ${PKGCONF}
330 fi
331
332 # Registering the resource
333
334 if [ -n "${ZONE}" ]
335 then
336 local_zone_smf
337 else
338 global_zone
339 fi
340
341 if [ -f ${UTILDIR}/pgs_config.work ]
342 then
343 ${ECHO} " remove the working copy ${UTILDIR}/pgs_config.work"
344 rm ${UTILDIR}/pgs_config.work
345 fi
346
347 exit 0