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