Home | History | Annotate | Download | only in impaxapp
      1 #
      2 # CDDL HEADER START
      3 #
      4 # The contents of this file are subject to the terms of the
      5 # Common Development and Distribution License (the License).
      6 # You may not use this file except in compliance with the License.
      7 #
      8 # You can obtain a copy of the license at usr/src/CDDL.txt
      9 # or http://www.opensolaris.org/os/licensing.
     10 # See the License for the specific language governing permissions
     11 # and limitations under the License.
     12 #
     13 # When distributing Covered Code, include this CDDL HEADER in each
     14 # file and include the License file at usr/src/CDDL.txt.
     15 # If applicable, add the following below this CDDL HEADER, with the
     16 # fields enclosed by brackets [] replaced with your own identifying
     17 # information: Portions Copyright [yyyy] [name of copyright owner]
     18 #
     19 # CDDL HEADER END
     20 #
     21 
     22 #
     23 #
     24 # Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
     25 # Use is subject to license terms.
     26 #
     27 #ident	"@(#)functions.ksh	1.7	07/06/06 SMI"
     28 #
     29 
     30 
     31 SCLOGGER=/usr/cluster/lib/sc/scds_syslog
     32 PKG=SUNWscpax
     33 METHOD=`basename $0`
     34 LOGFILE=/var/tmp/${RESOURCE}_logfile
     35 
     36 SCHA_RESOURCE_GET=/usr/cluster/bin/scha_resource_get
     37 SCHA_RESOURCEGROUP_GET=/usr/cluster/bin/scha_resourcegroup_get
     38 TASK_COMMAND=""
     39 
     40 syslog_tag()
     41 {
     42         #
     43         # Data Service message format
     44         #
     45 
     46         $SET_DEBUG
     47 
     48         print "SC[${PKG:-??}.${METHOD:-??}]:${RESOURCEGROUP:-??}:${RESOURCE:-??}"
     49 }
     50 
     51 scds_syslog()
     52 {
     53 
     54         #
     55         # Log a message
     56         #
     57 
     58         $SET_DEBUG
     59 
     60         $SCLOGGER "$@" &
     61 }
     62 
     63 debug_message()
     64 {
     65         #
     66         # Output a debug message to syslog if required
     67         #
     68 
     69         if [ "$DEBUG" = "$RESOURCE" -o "$DEBUG" = "ALL" ]
     70         then
     71                 SET_DEBUG="set -x"
     72 
     73                 DEBUG_TEXT=$1
     74 
     75                 scds_syslog -p daemon.debug -t $(syslog_tag) -m \
     76                         "%s" "$DEBUG_TEXT"
     77         else
     78                 SET_DEBUG=
     79         fi
     80 }
     81 
     82 log_message()
     83 {
     84         #
     85         # Output a message to syslog as required
     86         #
     87 
     88         debug_message "Function: log_message - Begin"
     89         $SET_DEBUG
     90 
     91         if [ -s "${LOGFILE}" ]
     92         then
     93                 PRIORITY=$1
     94                 HEADER=$2
     95 
     96 		# 
     97 		# Ensure the while loop only reads a closed file
     98 		#
     99 
    100 		strings ${LOGFILE} > ${LOGFILE}.copy
    101                 while read MSG_TXT
    102                 do
    103                         scds_syslog -p daemon.${PRIORITY} -t $(syslog_tag) -m \
    104                                 "%s - %s" \
    105                                 "${HEADER}" "${MSG_TXT}"
    106                 done < ${LOGFILE}.copy
    107 
    108                 su $USERID -c "cat /dev/null > $LOGFILE" > /dev/null
    109 		cat /dev/null > ${LOGFILE}.copy
    110         fi
    111 
    112         debug_message "Function: log_message - End"
    113 }
    114 
    115 standard_resource_get()
    116 {
    117         debug_message "Function: standard_resource_get - Begin"
    118         $SET_DEBUG
    119 
    120         PROPERTY=$1
    121 
    122         ${SCHA_RESOURCE_GET} -R ${RESOURCE} -G ${RESOURCEGROUP} -O ${PROPERTY}
    123 
    124         s1=$?
    125 
    126         if [ "${s1}" -ne 0 ]; then
    127                 debug_message "standard_resource_get - Retrievment of property ${PROPERTY} returned ${s1}"
    128         fi
    129 
    130         debug_message "Function: standard_resource_get - End"
    131         return ${s1}
    132 }
    133 
    134 standard_resourcegroup_get()
    135 {
    136         debug_message "Function: standard_resourcegroup_get - Begin"
    137         $SET_DEBUG
    138 
    139         PROPERTY=$1
    140 
    141         ${SCHA_RESOURCEGROUP_GET} -R ${RESOURCE} -G ${RESOURCEGROUP} -O ${PROPERTY}
    142 
    143         s1=$?
    144 
    145         if [ "${s1}" -ne 0 ]; then
    146                 debug_message "standard_resource_get - Retrievment of property ${PROPERTY} returned ${s1}"
    147         fi
    148 
    149         debug_message "Function: standard_resourcegroup_get - End"
    150 
    151         return ${s1}
    152 }
    153 
    154 srm_function()
    155 {
    156 
    157         USER=$1
    158 
    159         debug_message "Function: srm_function - Begin"
    160         $SET_DEBUG
    161 
    162 
    163         #
    164         # If Solaris 8 just return
    165         #
    166 
    167         if [ `/usr/bin/uname -r` = "5.8" ];
    168         then
    169                 return 0
    170         fi
    171 
    172         #
    173         # Retrieve RESOURCE_PROJECT_NAME
    174         #
    175 
    176         RESOURCE_PROJECT_NAME=`standard_resource_get RESOURCE_PROJECT_NAME`
    177 
    178         #
    179         # Retrieve RG_PROJECT_NAME if RESOURCE_PROJECT_NAME is not set
    180         #
    181 
    182         if [ -z "${RESOURCE_PROJECT_NAME}" ]; then
    183 
    184                 RESOURCE_PROJECT_NAME=`standard_resourcegroup_get RG_PROJECT_NAME`
    185         fi
    186 
    187         #
    188         # Return if no projects are defined
    189         #
    190 
    191         if [ -z "${RESOURCE_PROJECT_NAME}" ]; then
    192                 return 0
    193         fi
    194 
    195         #
    196         # Validate that $USER belongs to the project defined by
    197         # ${RESOURCE_PROJECT_NAME}
    198         #
    199 
    200         PROJ_MEMBER=`/usr/bin/projects ${USER} | /usr/bin/grep -w ${RESOURCE_PROJECT_NAME}`
    201 
    202         if [ -z "${PROJ_MEMBER}" ];
    203         then
    204              scds_syslog -p daemon.error -t $(syslog_tag) -m \
    205                         "srm_function - The user %s does not belongs to project %s" \
    206                         "${USER}" "${RESOURCE_PROJECT_NAME}" 
    207                 return 1
    208         else
    209                 debug_message "srm_function - User ${USER} belongs to project ${RESOURCE_PROJECT_NAME}"
    210         fi
    211 
    212         #
    213         # Set TASK_COMMAND
    214         #
    215 
    216         TASK_COMMAND="/usr/bin/newtask -p ${RESOURCE_PROJECT_NAME}"
    217 
    218         debug_message "Function: srm_function - End"
    219 
    220         return 0
    221 }
    222 
    223 
    224 
    225 Check_InterRG_dependency()
    226 {
    227         if [ -z "`/usr/cluster/bin/scrgadm -pvv -j ${RESOURCE} | /bin/grep \
    228         Resource_dependencies_restart`" ]; then
    229 
    230                 # SCMSGS
    231                 # @explanation
    232                 # No restart dependencies are available.
    233                 # @explanation-2
    234                 # Informational : no inter rg dependency defined in the config
    235                 # @explanation-3
    236                 # Informational : no inter rg dependency defined in the config
    237                 # @user_action
    238                 # None
    239                 # @user_action-2
    240                 # none required
    241                 # @user_action-3
    242                 # none required
    243                 scds_syslog -p daemon.error -t ${syslog_tag} -m \
    244                "No Inter RG-dependency found, using internal dependency" 
    245 
    246                 USE_INTERNAL_DEP=TRUE
    247         fi
    248 }
    249 
    250 
    251 check_restart_dependency()
    252 {
    253 
    254         $SET_DEBUG
    255         debug_message "Function: check_restart_dependency - Start called with the following arguments "$*
    256 
    257         #
    258         # Put here the specific application code to report if the dependent
    259 	# application has been restarted or not
    260         #
    261 	# Use hatimerun when calling an external program.
    262 	#
    263         # Return 0 if the dependent resource has NOT been restarted.
    264         # Return 1 if the dependent resource has been restarted.
    265 
    266 
    267         return 0
    268 
    269         debug_message "Function: check_restart_dependency - End"
    270 
    271 }
    272 
    273 
    274 check_start_dependency()
    275 {
    276 
    277 	$SET_DEBUG
    278 	debug_message "Function: check_start_dependency - Start called with the following arguments "$*
    279 
    280         #
    281         # Put here the specific application code to report if the dependent
    282         # application has been started or not
    283 	#
    284 	# Use hatimerun when calling an external program.
    285         #
    286         # Return 0 if the dependent resource is online
    287         # Return 1 if the dependent resource is not online
    288 
    289 
    290 
    291 	return 0
    292 
    293 	debug_message "Function: check_start_dependency - End"
    294 	
    295 }
    296 
    297 start_dependency()
    298 {
    299 	debug_message "Function: start_dependency - Begin"
    300 	$SET_DEBUG
    301 
    302 	# RETRIEVE START_TIMEOUT
    303 
    304 	START_TIMEOUT=`/usr/cluster/bin/scha_resource_get -O START_TIMEOUT -R ${RESOURCE} -G ${RESOURCEGROUP}`
    305 
    306 	# 80 % OF THE START-TIMEOUT CAN BE SPEND ON WAITING
    307 
    308 	MAX_START_TIMEOUT=`expr ${START_TIMEOUT} \* 80 \/ 100`
    309 
    310 	# GET CURRENT TIME IN SEC ON 24H BASE
    311 		
    312 	CUR_HOUR=`date '+%H'`
    313 	CUR_MIN=`date '+%M'`
    314 	CUR_SEC=`date '+%S'`
    315 	CUR_TIME=`expr ${CUR_HOUR} \* 3600 + ${CUR_MIN} \* 60 + ${CUR_SEC}`
    316 
    317 	# RUN A TEST LOOP UNTIL THE DEPENDENT RESOURCE IS UP OR 
    318 	# A TIMEOUT HAS OCCURED
    319 
    320 	while [ 1 -eq 1 ]
    321 	do
    322 
    323 		# GET NEW CURRENT TIMEOUT
    324 		NEW_HOUR=`date '+%H'`
    325 		NEW_MIN=`date '+%M'`
    326 		NEW_SEC=`date '+%S'`
    327 		NEW_TIME=`expr ${NEW_HOUR} \* 3600 + ${NEW_MIN} \* 60 + ${NEW_SEC}`
    328 
    329 		# HAVE WE EXEEDED TIMEOUT
    330 
    331 		s1=`expr ${CUR_TIME} + ${MAX_START_TIMEOUT}`
    332 
    333 		if [ ${s1} -le ${NEW_TIME} ]; then
    334 			# SCMSGS
    335 			# @explanation
    336 			# a resource which the resource depends on has not
    337 			# come online within the specified time
    338 			# @user_action
    339 			# check dependencies, check the resource indicated as
    340 			# the resource depends from.
    341 			scds_syslog -p daemon.error -t $(syslog_tag) -m \
    342        			"start_dependency: Exeeded %s seconds for waiting on dependent resource for resource %s to come online" "${MAX_START_TIMEOUT}" "${RESOURCE}"
    343 
    344 			St=1
    345 			break
    346 		fi
    347 
    348 		# CALL check_start_dependency
    349 
    350 		debug_message "Function: start_dependency - Call check_start_dependency function with argument "$*
    351 
    352 		check_start_dependency $*
    353 		St=$?
    354 
    355 		if [ ${St} -eq 0 ]; then
    356 		  St=0
    357 		  break
    358 		fi
    359 
    360 		# Wait 5 seconds
    361 
    362 		sleep 5
    363 	done
    364 
    365 
    366 	debug_message "Function: start_dependency - End"
    367 
    368 	return ${St}
    369 }
    370 
    371 restart_dependency()
    372 {
    373 	debug_message "Function: restart_dependency - Begin"
    374 	$SET_DEBUG
    375 
    376 
    377 	# CALL check_restart_dependency
    378 
    379 	debug_message "Function: start_dependency - Call check_restart_dependency function with argument "$*
    380 	check_restart_dependency $*
    381 	St=$?
    382 
    383 	if [ ${St} -ne 0 ]; then
    384            scds_syslog -p daemon.error -t $(syslog_tag) -m \
    385            "restart_dependency - Dependent resource to resource %s has been restarted, restart this resource %s" \
    386            "${RESOURCE}" "${RESOURCE}"
    387 
    388 	   St=100
    389         else
    390            St=0
    391 	fi
    392 
    393 	debug_message "Function: restart_dependency - End"
    394 
    395 	return ${St}
    396 }
    397 
    398 
    399 validate_options()
    400 {
    401         #
    402         # Ensure all options are set
    403         #
    404 
    405 	SCRIPTNAME=`basename $0`
    406         for i in RESOURCE RESOURCEGROUP USE_INTERNAL_DEP
    407         do
    408                 case $i in
    409                         RESOURCE)
    410                         if [ -z $RESOURCE ]; then
    411                                 # SCMSGS
    412                                 # @explanation
    413                                 # The option -R of the agent
    414                                 # command $COMMANDNAME is not set,
    415                                 # @user_action
    416                                 # look at previous error messages in the
    417                                 # syslog.
    418                                 scds_syslog -p daemon.err -t $(syslog_tag) -m \
    419                                 "validate_options: %s Option -R not set" \
    420                                 "${SCRIPTNAME}"
    421                                 exit 1
    422                         fi;;
    423 
    424                         RESOURCEGROUP)
    425                         if [ -z $RESOURCEGROUP ]; then
    426                                 # SCMSGS
    427                                 # @explanation
    428                                 # The option -G of the agent
    429                                 # command $COMMANDNAME is not set,
    430                                 # @user_action
    431                                 # look at previous error messages in the
    432                                 # syslog.
    433                                 scds_syslog -p daemon.err -t $(syslog_tag) -m \
    434                                 "validate_options: %s Option -G not set" \
    435                                 "${SCRIPTNAME}"
    436                                 exit 1
    437                         fi;;
    438 
    439                         USE_INTERNAL_DEP)
    440                         if [ ${USE_INTERNAL_DEP} = "FALSE" ]; then
    441 				Check_InterRG_dependency
    442                         fi;;
    443                 esac
    444         done
    445 }
    446 
    447 validate()
    448 {
    449 	#
    450 	# Validate impax
    451 	#
    452 	
    453         debug_message "Function: validate - Begin"
    454 	$SET_DEBUG
    455 
    456 	rc_validate=0
    457 
    458 	#
    459 	# Validate that ${filename} exists
    460 	#
    461 
    462 	if [ ! -f "${filename}" ]
    463 	then
    464    		# SCMSGS
    465    		# @explanation
    466    		# validation that file indicated has not been found by the
    467    		# agent.
    468    		# @user_action
    469    		# Check all required files are available on both nodes,
    470    		# readable and in the same location.
    471    		scds_syslog -p daemon.err -t $(syslog_tag) -m \
    472 			"Validate - file %s does not exist" \
    473 			"${filename}"
    474 		rc_validate=0
    475 	else
    476 		debug_message "Validate - ${filename} exists"
    477 	fi
    478 
    479 	#
    480 	# More validate checks here
    481 	#
    482 
    483 	debug_message "Function: validate - End"
    484 }
    485 
    486 start_impax()
    487 {
    488 	#
    489 	# Start impax
    490 	#
    491 
    492         debug_message "Function: start_impax - Begin"
    493 	$SET_DEBUG
    494 
    495 	#
    496 	# If internal Inter-RG dependencies are needed for start dependencies 
    497 	# then uncomment the lines that starts with 
    498 	# Internal Inter-RG dependency.
    499 
    500 	# You have to provide the code for checking if the dependent resource
    501 	# is online in function check_start_dependency()
    502 	#
    503 	# If needed add any options to the start_dependency function call.
    504 	# The start_dependency function will call the check_start_dependency 
    505 	# function.
    506 
    507 	# Internal Inter-RG dependency
    508 	#
    509 	# if [ ${USE_INTERNAL_DEP} = "TRUE" ]; then
    510 	#	start_dependency # Add any options
    511 	#
    512 	#	St=$?
    513 	#
    514 	#	if [ ${St} -ne 0 ]; then
    515 	#		rc_start_command=1
    516 	#		return
    517 	#	fi
    518 	# fi
    519 	#	   
    520 	# database is taken care off by the Oracle agent
    521 	# This should take care of sh, ksh, csh, tcsh and bash
    522 	#
    523 	#@TG@
    524         debug_message "start_impax - checking Impax licenses"
    525         # this needs to be done to ensure the correct license is in place
    526 	check_impax_license
    527 
    528 	if [ -d /etc/impaxrc ]; then
    529 		# ok the impaxrc script dir exists
    530 		debug_message "found impaxrc script"
    531 	else
    532 		# wrong bail out ... no custom rc scripts available
    533 		debug_message "no impaxrc dir found... see install guide"
    534 		exit 1
    535 	fi
    536 	# check existence and start each sub part in turn...
    537 	for i in `ls -1 /etc/impaxrc/S??*`
    538 	do
    539 	if [ -f $i ]; then
    540 		# ok found first step
    541 		$i start
    542 		if [ $? != 0 ]; then
    543 			# something is wrong, start of $i failed
    544 			debug_message " start of $i failed"
    545 			if [ $i == "S49IMPAXsrvw" ];then
    546                         #this is only the web server... only service tools will not function
    547                         debug_message " Warning could not find start script for web server, service tools might be unavailable"
    548                                                                                       
    549                 
    550                 	else
    551 
    552 				exit 1
    553 			fi
    554 		fi
    555 	else 
    556 		# script not found!
    557 		debug_message " $i start script not found"
    558 		if [ $i == "S49IMPAXsrvw" ];then
    559 			#this is only the web server... only service tools will not function
    560 			debug_message " Warning could not find start script for web server, service tools might be unavailable"
    561 
    562 		
    563 		else
    564 			exit 1
    565 		fi
    566 	fi
    567 	done
    568 
    569 	
    570 	# all hunky dory....
    571 	# start a looping script... to fool pmfadm
    572 	if [ -f /opt/SUNWscpax/impaxapp/bin/loops ]; then
    573 		/opt/SUNWscpax/impaxapp/bin/loops &
    574 	fi
    575 		
    576 	debug_message "Function: start_impax - End"
    577 }
    578 
    579 stop_impax()
    580 {
    581 	#
    582 	# Stop impax
    583 	#
    584 
    585         debug_message "Function: stop_impax - Begin"
    586 	$SET_DEBUG
    587 
    588 	#
    589 	# This should take care of sh, ksh, csh, tcsh and bash
    590 	#
    591 	#if [ -f /usr/local/bin/kb_stop_impax ]; then
    592 	#	# ok stop it
    593 	#	/usr/local/bin/kb_stop_impax
    594 	#	if [ $? != 0 ]; then
    595 	#		# error ! 
    596 	#		log_message " stop of impax app failed bail out"
    597 	#		return 1
    598 	#	fi
    599 	#fi
    600 	#pkill -9 kb_loops
    601 
    602 	#reverse the order and stop the impax scripts... some sanity checks
    603 	if [ -d /etc/impaxrc ]; then
    604 		# ok impaxrc dir is in the place we want it
    605 		debug_message " found the impaxrc in stop method"
    606 	
    607 	else
    608 		# big problem bail out no impaxrc
    609 		debug_message " did not find impaxrc in stop method"
    610 		exit 1
    611 	fi
    612 	
    613 	for i in `ls -1 /etc/impaxrc/S??* | sort -r`
    614 	do
    615 	
    616 	if [ -f $i ];then
    617 		#found the script
    618 		$i stop
    619 		if [ $? != 0 ]; then
    620 			# return code not ok
    621 			debug_message " stop of $i failed"
    622 		fi
    623 	else
    624 		# script not found or error
    625 		debug_message " did not find the script to stop the $i"
    626 	fi
    627 	done
    628 
    629 
    630 	debug_message "Function: stop_impax - End"
    631 }
    632 
    633 check_impax_license()
    634 {
    635         # called as part of check_impax processing
    636         if [ -x /usr/mvf/bin/manage_cluster_mvf_licenses ]; then
    637              debug_message "dispatching /usr/mvf/bin/manage_cluster_mvf_licenses"
    638              /usr/mvf/bin/manage_cluster_mvf_licenses
    639         else
    640              debug_message "/usr/mvf/bin/manage_cluster_mvf_licenses not found"
    641 	     # we should bail out after this part..
    642 	     # as IMPAX will not function with a correct license
    643         fi
    644                                                                                                                    
    645 }
    646 
    647 
    648 check_impax()
    649 {
    650 	# 
    651 	# Probe impax
    652 	#
    653 
    654         debug_message "Function: check_impax - Begin"
    655 	$SET_DEBUG
    656 
    657 	rc_check_impax=0
    658 
    659         #
    660         # If internal Inter-RG dependencies are needed for restart dependencies
    661         # then uncomment the lines that starts with
    662         # Internal Inter-RG dependency.
    663 
    664         # You have to provide the code for checking if the dependent resource
    665         # has been restarted in function check_restart_dependency()
    666 	#
    667 	# You probably have to increase the Probe_timeout value from the
    668 	# default value of 30 seconds.
    669         #
    670         # If needed add any options to the restart_dependency function call.
    671         # The start_dependency function will call the check_restart_dependency
    672         # function.
    673 
    674         # Internal Inter-RG dependency
    675         #
    676         # if [ ${USE_INTERNAL_DEP} = "TRUE" ]; then
    677         #       restart_dependency # Add any options
    678         #
    679         #       St=$?
    680         #
    681         #       if [ ${St} -ne 0 ]; then
    682         #               rc_check_command=100
    683         #               return
    684         #       fi
    685         # fi
    686         #
    687 	#
    688 	# This should take care of sh, ksh, csh, tcsh and bash
    689 	#
    690 	#if getent passwd ${USERID} | awk -F: '{print $7}' | grep csh > /dev/null
    691 	#then
    692 	#	su ${USERID} -c "check_command >& ${LOGFILE}" > /dev/null
    693 	#	rc_check_command=$?
    694 	#else
    695 	#	su ${USERID} -c "check_command >${LOGFILE} 2>&1" > /dev/null
    696 	#	rc_check_command=$?
    697 	#fi
    698         debug_message "Checking Impax license..."
    699                                                                                                                    
    700         check_impax_license
    701 
    702 
    703 	debug_message "Function: check_impax - End"
    704 }
    705 
    706