Print this page
| Split |
Close |
| Expand all |
| Collapse all |
--- /workspace/du105637/oscposthot/webrev/usr/src/cmd/ha-services/gds-agents/PostgreSQL/functions_static.ksh-
+++ functions_static.ksh
1 1 #
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 TASK_COMMAND=""
31 31
32 32 ZONENAME=/usr/bin/zonename
33 33
34 34 SCLOGGER=/usr/cluster/lib/sc/scds_syslog
35 35 LOGGER=/usr/bin/logger
36 36 SCHA_RESOURCE_SETSTATUS=/usr/cluster/bin/scha_resource_setstatus
37 37 SCHA_RESOURCE_GET=/usr/cluster/bin/scha_resource_get
38 38 SCHA_RESOURCEGROUP_GET=/usr/cluster/bin/scha_resourcegroup_get
39 39 PMFADM=/usr/cluster/bin/pmfadm
40 40 UNAME=/usr/bin/uname
41 41 ECHO=/usr/bin/echo
42 42 AWK=/usr/bin/awk
43 43 EGREP=/usr/bin/egrep
44 +GREP=/usr/bin/grep
44 45 PROJECTS=/usr/bin/projects
46 +WC=/usr/bin/wc
47 +CAT=/usr/bin/cat
48 +ENV=/usr/bin/env
49 +RM=/usr/bin/rm
50 +SSH_AGENT=/usr/bin/ssh-agent
51 +SSH_ADD=/usr/bin/ssh-add
52 +CHMOD=/usr/bin/chmod
45 53
46 54 terminate()
47 55 {
48 56
49 57 debug_message "Function: terminate - Begin"
50 58 ${SET_DEBUG}
51 59
52 60 exiting_func=${1}
53 61 exit_code=${2}
54 62
55 63 # determine the right return code, it is either the return code from the functions or
56 64 # the appropriate smf return code
57 65
58 66 if in_cluster
59 67 then
60 68
61 69 # called in a clustered global zone
62 70
63 71 debug_message "Method: ${MYNAME} ${exiting_func} - End (${exit_code})"
64 72 exit ${exit_code}
65 73
66 74 else
67 75 if [ -n "${SMF_FMRI}" ]
68 76 then
69 77 if [ "${exit_code}" -ne 0 ]
70 78 then
71 79
72 80 # honour the gds specific probe values like 100 or 201
73 81
74 82 if [ "${exiting_func}" == "probe" -o "${exiting_func}" == "validate" ]
75 83 then
76 84 debug_message "Method: ${MYNAME} ${exiting_func} - End (${exit_code})"
77 85 exit ${exit_code}
78 86 else
79 87 debug_message "Method: ${MYNAME} ${exiting_func} - End (${SMF_EXIT_ERR_PERM})"
80 88 exit ${SMF_EXIT_ERR_PERM}
81 89 fi
82 90 fi
83 91
84 92 debug_message "Method: ${MYNAME} ${exiting_func} - End (${SMF_EXIT_OK})"
85 93 exit ${SMF_EXIT_OK}
86 94 else
87 95 debug_message "Method: ${MYNAME} ${exiting_func} - End (${exit_code})"
88 96 exit ${exit_code}
89 97 fi
90 98 fi
91 99
92 100 debug_message "Function: terminate - End"
93 101
94 102 }
95 103 syslog_tag()
96 104 {
97 105 #
98 106 # Data Service message format
99 107 #
100 108
101 109 ${SET_DEBUG}
102 110
103 111 print "SC[${PKG:-??}.${METHOD:-??}]:${RESOURCEGROUP:-??}:${RESOURCE:-??}"
104 112 }
105 113
106 114 scds_syslog()
107 115 {
108 116
109 117 #
110 118 # Log a message
111 119 #
112 120
113 121 ${SET_DEBUG}
114 122
115 123 if [ -f ${SCLOGGER} ]
116 124 then
117 125 ${SCLOGGER} "$@" &
118 126 else
119 127
120 128 # eliminate -m and honour -p and -t option
121 129 while getopts 'p:t:m' opt
122 130 do
123 131 case "${opt}" in
124 132 t) TAG=${OPTARG};;
125 133 p) PRI=${OPTARG};;
126 134 esac
127 135 done
128 136
129 137 shift $((${OPTIND} - 1))
130 138 LOG_STRING=`/usr/bin/printf "$@"`
131 139
132 140 ${LOGGER} -p ${PRI} -t ${TAG} ${LOG_STRING}
133 141 fi
134 142
135 143 }
136 144
|
↓ open down ↓ |
82 lines elided |
↑ open up ↑ |
137 145 rgs_zonename()
138 146 {
139 147
140 148 # Determine wether the host specified by uname -n is combined with a zonename in the
141 149 # current resourcegroups nodelist. The seperator beween nodename and zonename is ":".
142 150 #
143 151 # This function assume the resource group name preset in the variable ${RESOURCEGROUP} and should be called
144 152 #
145 153 # $(rgs_zonename)
146 154 #
147 -# It passes back the zonename or nothing.
155 +# It passes back a zonename or nothing.
156 +# If there are more than one zones in the nodelist, it passes back either the zone where the resource group
157 +# is online or first one in the list.
148 158
149 159 debug_message "Function: rg_zonename - Begin "
150 160 ${SET_DEBUG}
151 161
152 162 nodes_zone=
153 163 nodename=`${UNAME} -n`
154 - node=`${SCHA_RESOURCEGROUP_GET} -G ${RESOURCEGROUP} -O NODELIST|grep ${nodename}`
164 + node=`${SCHA_RESOURCEGROUP_GET} -G ${RESOURCEGROUP} -O NODELIST|${EGREP} "${nodename}$|${nodename}:"`
155 165
156 - if ${ECHO} ${node} | grep : >/dev/null 2>&1
166 + if ${ECHO} ${node} | ${GREP} : >/dev/null 2>&1
157 167 then
158 - nodes_zone=`${ECHO} ${node} | ${AWK} -F: '{print $2}'`
168 + if [ `${ECHO} ${node}|${WC} -w` -gt 1 ]
169 + then
170 + online=0
171 + for i in ${node}
172 + do
173 + if ${SCHA_RESOURCEGROUP_GET} -G ${RESOURCEGROUP} -O RG_state_node ${i}| ${GREP} -i online >/dev/null 2>&1
174 + then
175 + nodes_zone=`${ECHO} ${i} | ${AWK} -F: '{print $2}'`
176 + online=1
177 + fi
178 + done
179 +
180 + # check if we found a zone where the resource group is online, if not pick the first zone in the list
181 +
182 + if [ ${online} -eq 0 ]
183 + then
184 + first_node=`${ECHO} ${node} | ${AWK} '{print $1}'`
185 + nodes_zone=`${ECHO} ${first_node} | ${AWK} -F: '{print $2}'`
186 + fi
187 + else
188 + nodes_zone=`${ECHO} ${node} | ${AWK} -F: '{print $2}'`
189 + fi
159 190
160 191 fi
161 192
162 193 print ${nodes_zone}
163 194
164 195 debug_message "Function: rg_zonename - End "
165 196 }
166 197
167 198 debug_message()
168 199 {
169 200 #
170 201 # Output a debug message to syslog if required
171 202 #
172 203
173 204 if [ -n "${DEBUG}" ]
174 205 then
175 206
176 207 # determine if we should display a message and do it
177 208
178 209 if [ "${DEBUG}" = "ALL" ]
179 210 then
180 211 SET_DEBUG="set -x"
181 212
182 213 DEBUG_TEXT=${1}
183 214
184 215 scds_syslog -p daemon.debug -t $(syslog_tag) -m \
185 216 "%s" "${DEBUG_TEXT}"
186 217 else
187 218
188 219 # check if the actual resource matches one of the list of resources
189 220 # if it matches, display a message
190 221
191 222 DEBUG=`echo ${DEBUG}|tr "," " "`
192 223 for i in ${DEBUG}
193 224 do
194 225 if [ "${i}" = "${RESOURCE}" ]
195 226 then
196 227 SET_DEBUG="set -x"
197 228
198 229 DEBUG_TEXT=${1}
199 230
200 231 scds_syslog -p daemon.debug -t $(syslog_tag) -m \
201 232 "%s" "${DEBUG_TEXT}"
202 233 fi
203 234 done
204 235 fi
205 236 else
206 237 SET_DEBUG=
207 238 fi
208 239 }
209 240
210 241 log_message()
211 242 {
212 243 #
213 244 # Output a message to syslog as required
214 245 #
215 246
216 247 debug_message "Function: log_message - Begin"
217 248 ${SET_DEBUG}
218 249
219 250 if [ -s "${LOGFILE}" ]
220 251 then
221 252 PRIORITY=${1}
222 253 HEADER=${2}
223 254
224 255 #
225 256 # Ensure the while loop only reads a closed file
226 257 #
227 258
228 259 strings ${LOGFILE} > ${LOGFILE}.copy
229 260 while read MSG_TXT
230 261 do
231 262 scds_syslog -p daemon.${PRIORITY} -t $(syslog_tag) -m \
232 263 "%s - %s" \
233 264 "${HEADER}" "${MSG_TXT}"
234 265 done < ${LOGFILE}.copy
235 266
236 267 fi
237 268
238 269 debug_message "Function: log_message - End"
239 270 }
240 271
241 272 srm_function()
242 273 {
243 274 debug_message "Function: srm_function - Begin"
244 275 ${SET_DEBUG}
245 276
246 277 USER=${1}
247 278
248 279 #
249 280 # If Solaris 8 just return
250 281 #
251 282
252 283 if [ `/usr/bin/uname -r` = "5.8" ];
253 284 then
254 285 return 0
255 286 fi
256 287
257 288 #
258 289 # Retrieve RESOURCE_PROJECT_NAME
259 290 #
260 291
261 292 if in_cluster
262 293 then
263 294 RESOURCE_PROJECT_NAME=`${SCHA_RESOURCE_GET} -R ${RESOURCE} -G ${RESOURCEGROUP} -O RESOURCE_PROJECT_NAME`
264 295
265 296 #
266 297 # Retrieve RG_PROJECT_NAME if RESOURCE_PROJECT_NAME is not set
267 298 #
268 299
269 300 if [ -z "${RESOURCE_PROJECT_NAME}" ] || [ "${RESOURCE_PROJECT_NAME}" = "default" ];then
270 301
271 302 RESOURCE_PROJECT_NAME=`${SCHA_RESOURCEGROUP_GET} -G ${RESOURCEGROUP} -O RG_PROJECT_NAME`
272 303 fi
273 304 else
274 305 RESOURCE_PROJECT_NAME=${ZONE_PROJECT}
275 306 fi
276 307
277 308 #
278 309 # Return if no projects are defined
279 310 #
280 311
281 312 if [ -z "${RESOURCE_PROJECT_NAME}" ] || [ "${RESOURCE_PROJECT_NAME}" = "default" ]; then
282 313 return 0
283 314 fi
284 315
285 316 #
286 317 # Validate that $USER belongs to the project defined by
287 318 # ${RESOURCE_PROJECT_NAME}
288 319 #
289 320
290 321 PROJ_MEMBER=`${PROJECTS} ${USER} | ${EGREP} "^${RESOURCE_PROJECT_NAME} | ${RESOURCE_PROJECT_NAME} | ${RESOURCE_PROJECT_NAME}$|^${RESOURCE_PROJECT_NAME}$"`
291 322
292 323 if [ -z "${PROJ_MEMBER}" ];
293 324 then
294 325 # SCMSGS
295 326 # @explanation
296 327 # The specified user does not belong to the project defined by
297 328 # Resource_project_name or Rg_project_name.
298 329 # @user_action
299 330 # Add the user to the defined project in /etc/project.
300 331 scds_syslog -p daemon.err -t $(syslog_tag) -m \
301 332 "srm_function - The user %s does not belongs to project %s" \
302 333 "${USER}" "${RESOURCE_PROJECT_NAME}"
303 334 return 1
304 335 else
305 336 debug_message "srm_function - User ${USER} belongs to project ${RESOURCE_PROJECT_NAME}"
306 337 fi
307 338
308 339 #
309 340 # Set TASK_COMMAND
310 341 #
311 342
312 343 TASK_COMMAND="/usr/bin/newtask -p ${RESOURCE_PROJECT_NAME}"
313 344
314 345 debug_message "Function: srm_function - End"
315 346
316 347 return 0
317 348 }
318 349
319 350 zone_function()
320 351 {
321 352 debug_message "Function: zone_function - Begin"
322 353 ${SET_DEBUG}
323 354
324 355 #
325 356 # Initialize PZONEOPT as empty
326 357 PZONEOPT=""
327 358
328 359 #
329 360 # If Solaris does not have /usr/bin/zonename just return 0
330 361 # else add "-z <zonename>" to PZONEOPT
331 362 #
332 363
333 364 if [ -x "${ZONENAME}" ];
334 365 then
335 366 PZONEOPT="-z `${ZONENAME}`"
336 367 fi
337 368
338 369 debug_message "Function: zone_function - End"
339 370 return 0
340 371 }
341 372
342 373 in_cluster()
343 374 {
344 375 #
345 376 # determine if we are started in a clustered global zone
346 377 #
347 378
348 379 debug_message "Function: in_cluster - Begin"
349 380 ${SET_DEBUG}
350 381
351 382 in_cluster_val=0
352 383
353 384 if [ ! -d /etc/cluster ]
354 385 then
355 386 in_cluster_val=1
356 387 fi
357 388
358 389 debug_message "Function: in_cluster - End"
359 390
360 391 return ${in_cluster_val}
361 392 }
362 393
363 394 start_dependency()
364 395 {
365 396 debug_message "Function: start_dependency - Begin"
366 397 ${SET_DEBUG}
367 398
368 399 # RETRIEVE START_TIMEOUT
369 400
370 401 if [-z "${ZONE_START_TIMOUT}" ]
371 402 then
372 403 START_TIMEOUT=`standard_resource_get START_TIMEOUT`
373 404 else
374 405 START_TIMEOUT=${ZONE_START_TIMOUT}
375 406 fi
376 407
377 408 # 80 % OF THE START-TIMEOUT CAN BE SPENT ON WAITING
378 409
379 410 MAX_START_TIMEOUT=`expr ${START_TIMEOUT} \* 80 \/ 100`
380 411
381 412 # GET CURRENT TIME IN SEC ON 24H BASE
382 413
383 414 CUR_HOUR=`date '+%H'`
384 415 CUR_MIN=`date '+%M'`
385 416 CUR_SEC=`date '+%S'`
386 417 CUR_TIME=`expr ${CUR_HOUR} \* 3600 + ${CUR_MIN} \* 60 + ${CUR_SEC}`
387 418
388 419 # RUN A TEST LOOP UNTIL THE DEPENDENT RESOURCE IS UP OR
389 420 # A TIMEOUT HAS OCCURED
390 421
391 422 while [ 1 -eq 1 ]
392 423 do
393 424
394 425 # GET NEW CURRENT TIMEOUT
395 426 NEW_HOUR=`date '+%H'`
396 427 NEW_MIN=`date '+%M'`
397 428 NEW_SEC=`date '+%S'`
398 429 NEW_TIME=`expr ${NEW_HOUR} \* 3600 + ${NEW_MIN} \* 60 + ${NEW_SEC}`
399 430
400 431 # HAVE WE EXEEDED TIMEOUT
401 432
402 433 s1=`expr ${CUR_TIME} + ${MAX_START_TIMEOUT}`
403 434
404 435 if [ ${s1} -le ${NEW_TIME} ]; then
405 436 # SCMSGS
406 437 # @explanation
407 438 # The start of a dependent resource takes too long.
408 439 # @user_action
409 440 # None
410 441 scds_syslog -p daemon.err -t $(syslog_tag) -m \
411 442 "start_dependency: Exeeded ${MAX_START_TIMEOUT} seconds for waiting on dependent resource for resource ${RESOURCE} to come online"
412 443
413 444 St=1
414 445 break
415 446 fi
416 447
417 448 # CALL check_start_dependency
418 449
419 450 debug_message "Function: start_dependency - Call check_start_dependency function with argument "$*
420 451
421 452 check_start_dependency $*
422 453 St=$?
423 454
424 455 if [ ${St} -eq 0 ]; then
425 456 St=0
426 457 break
427 458 fi
428 459
429 460 # Wait 5 seconds
430 461
431 462 sleep 5
432 463 done
433 464
434 465
435 466 debug_message "Function: start_dependency - End"
436 467
437 468 return ${St}
438 469 }
439 470
440 471 restart_dependency()
441 472 {
442 473 debug_message "Function: restart_dependency - Begin"
443 474 ${SET_DEBUG}
444 475
445 476
446 477 # CALL check_restart_dependency
447 478
448 479 debug_message "Function: start_dependency - Call check_restart_dependency function with argument "$*
449 480 check_restart_dependency $*
450 481 St=$?
451 482
452 483 if [ ${St} -ne 0 ]; then
453 484 # SCMSGS
454 485 # @explanation
455 486 # The dependent resource was restarted, the resource is restarting
456 487 # now.
457 488 # @explanation-2
458 489 # A restart of the dependant resource has been noticed,
459 490 # it might be necessary to restart the resource depending on
460 491 # @explanation-3
461 492 # a restart of the dependant resource has been noticed, it might be
462 493 # necessary to restart the resource depending on
463 494 # @explanation-4
464 495 # a restart of the dependant resource has been noticed, it might be
465 496 # necessary to restart the resource depending on
466 497 # @user_action
467 498 # None
468 499 # @user_action-2
469 500 # check the validity of the service. there might be a dependency
470 501 # problem, a sub resource has been restarted, and functionality
471 502 # might have been impaired
472 503 # @user_action-3
473 504 # check the validity of the service. there might be a dependency
474 505 # problem, a sub resource has been restarted, and functionality
475 506 # might have been impaired
476 507 # @user_action-4
477 508 # check the validity of the service. there might be a dependency
478 509 # problem, a sub resource has been restarted, and functionality
479 510 # might have been impaired
480 511 scds_syslog -p daemon.err -t $(syslog_tag) -m \
481 512 "restart_dependency - Dependent resource to resource %s has been restarted, restart this resource %s" \
|
↓ open down ↓ |
313 lines elided |
↑ open up ↑ |
482 513 "${RESOURCE}" "${RESOURCE}"
483 514
484 515 St=100
485 516 else
486 517 St=0
487 518 fi
488 519
489 520 debug_message "Function: restart_dependency - End"
490 521
491 522 return ${St}
523 +}
524 +
525 +start_ssh_agent()
526 +{
527 + #
528 + # Start an ssh-agent and add the decrypted private key.
529 + # Only when the ssh-agent contains the private key, a ssh login without a
530 + # passphrase challenge is possible.
531 + #
532 + # This function stores the environment variables SSH_AUTH_SOCK and
533 + # SSH_AGENT_PID in /tmp/${RESOURCE}-ssh in a ksh compatible format.
534 + #
535 + # The start_ssh_agent function is meant to be called in the target users
536 + # environment.
537 + #
538 + # The only necessary parameter is the passphrase of the target users
539 + # private ssh key.
540 + # If you use this function you should kill the started ssh-agent in your
541 + # stop function.
542 + #
543 + # To do this you have to export the SSH_AGENT_PID from tmp/${RESOURCE}-ssh
544 + # in the users environment and call /usr/bin/ssh-agent -k.
545 + #
546 + # The returncode of the start_ssh_agent function is 0 for success, and 1 for error.
547 +
548 + debug_message "Function: start_ssh_agent - Begin"
549 + ${SET_DEBUG}
550 +
551 + SSH_PASS=${1}
552 +
553 + rc_start_ssh_agent=0
554 + export DISPLAY=""
555 +
556 + # remove the SSH_ASKPASS script and the temporary store of SSH_AUTH_SOCK
557 + # and SSH_AGENT_PID to satisfy noclobber
558 +
559 + ${RM} /tmp/${RESOURCE}-askpass 2>/dev/null
560 + ${RM} /tmp/${RESOURCE}-ssh 2>/dev/null
561 +
562 + # start the ssh-agent
563 +
564 + eval `${SSH_AGENT} -s` >/dev/null 2>&1
565 + if [ ${?} -eq 0 ]
566 + then
567 + debug_message "Function: start_ssh_agent - ssh-agent started"
568 +
569 + ${ENV} | ${EGREP} "SSH_AUTH_SOCK|SSH_AGENT_PID">/tmp/${RESOURCE}-ssh
570 +
571 + # create the SSH_ASKPASS script needed for a headless ssh-agent
572 +
573 + export SSH_ASKPASS=/tmp/${RESOURCE}-askpass
574 + ${CAT} > ${SSH_ASKPASS} <<EOF
575 +#!/usr/bin/ksh
576 +# reads a passphrase at the ssh-agent command
577 +read x
578 +${ECHO} \${x}
579 +EOF
580 + ${CHMOD} +x ${SSH_ASKPASS}
581 +
582 + # decrypt the private key and store it in memory
583 +
584 + if print ${SSH_PASS}|${SSH_ADD} >/dev/null 2>&1
585 + then
586 + debug_message "Function: start_ssh_agent - ssh-add successful, private key decryped and stored"
587 + else
588 + # SCMSGS
589 + # @explanation
590 + # The ssh passphrase passed to the start_ssh_agent function is wrong
591 + # @user_action
592 + # Fix the ssh passphrase entry in your parameters
593 + scds_syslog -p daemon.err -t $(syslog_tag) -m \
594 + "start_ssh_agent: The passphrase %s is wrong" \
595 + "${SSH_PASS}"
596 + rc_start_ssh_agent=1
597 + fi
598 +
599 + # remove the previously created askpass script
600 +
601 + ${RM} ${SSH_ASKPASS}
602 + else
603 + # SCMSGS
604 + # @explanation
605 + # The ssh-agent is not startable for the given user
606 + # @user_action
607 + # Determine and fix the root cause by running the ssh-agent manually
608 + # as the target user
609 + scds_syslog -p daemon.err -t $(syslog_tag) -m \
610 + "start_ssh_agent: The start of the ssh-agent was unsuccessful"
611 + rc_start_ssh_agent=1
612 +
613 + fi
614 +
615 + debug_message "Function: start_ssh_agent - End"
616 + return ${rc_start_ssh_agent}
617 +
492 618 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX