Home | History | Annotate | Download | only in zone
      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 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
     24 # Use is subject to license terms.
     25 #
     26 # ident	"@(#)functions_common.ksh	1.7	08/07/25 SMI"
     27 #
     28 
     29 SCHA_RESOURCE_GET=/usr/cluster/bin/scha_resource_get
     30 SCHA_CLUSTER_GET=/usr/cluster/bin/scha_cluster_get
     31 SCRGADM=/usr/cluster/bin/scrgadm
     32 SCSTAT=/usr/cluster/bin/scstat
     33 
     34 ZONEADM=/usr/sbin/zoneadm
     35 ZONECFG=/usr/sbin/zonecfg
     36 ZLOGIN=/usr/sbin/zlogin
     37 
     38 PMFADM=/usr/cluster/bin/pmfadm
     39 CLINFO=/usr/sbin/clinfo
     40 IFCONFIG=/usr/sbin/ifconfig
     41 PING=/usr/sbin/ping
     42 
     43 get_zone_state()
     44 {
     45         # Elaborates the zone state of a given zone
     46         # returns the state in the variable ZONE_STATE
     47 
     48         debug_message "Function: get_zone_state - Begin"
     49         ${SET_DEBUG}
     50 
     51         ZONE_STATE=`${ZONEADM} -z ${1} list -p | awk -F: '{print $3}'`
     52 	rc_get_zone_state=$?
     53 
     54         debug_message "Function: get_zone_state - End"
     55 	return ${rc_get_zone_state}
     56 }
     57 
     58 get_svc_state()
     59 {
     60 	# Elaborates the status of a given smf service in a zone
     61 	# returns the state in the variable SVC_STATE
     62 
     63         debug_message "Function: get_svc_state - Begin"
     64 	${SET_DEBUG}
     65 
     66 	SVC_STATE=`(${ZLOGIN} ${1} /bin/svcs -H ${2} 2> /dev/null ) | /bin/awk '{print $1}'`
     67 	rc_get_svc_state=$?
     68 
     69 	debug_message "Function: get_svc_state - End"
     70 	return ${rc_get_svc_state}
     71 }
     72 
     73 get_lx_state()
     74 {
     75 	# Elaborates the status of a given Linux runlevel in a zone
     76 	# returns the state in the variable LX_STATE
     77 
     78 	debug_message "Function: get_lx_state - Begin"
     79 	${SET_DEBUG}
     80 
     81 	LX_STATE=`(${ZLOGIN} ${1} /sbin/runlevel ) | awk '{print $2}'`
     82 	rc_get_lx_state=$?
     83 
     84 	debug_message "Function: get_lx_state - End"
     85 	return ${rc_get_lx_state}
     86 }
     87 
     88 get_solaris_legacy_state()
     89 {
     90 	# Elaborates the status of a given Solaris legacy runlevel in a zone
     91 	# returns the state in the variable SOLARIS_LEGACY_STATE
     92 
     93 	debug_message "Function: get_solaris_legacy_state - Begin"
     94 	${SET_DEBUG}
     95 
     96 	SOLARIS_LEGACY_STATE=`(${ZLOGIN} ${1} /bin/who -r ) | awk '{print $3}'`
     97 	rc_get_solaris_legacy_state=$?
     98 
     99 	debug_message "Function: get_solaris_legacy_state - End"
    100 	return ${rc_get_solaris_legacy_state}
    101 }
    102 
    103 val_parfile()
    104 {
    105 	# Common valdation for parameter file
    106 	
    107         debug_message "Function: val_parfile - Begin"
    108 	${SET_DEBUG}
    109 
    110 	rc_val_pfile=0
    111 
    112         # Validate that parameter file exists
    113 
    114 	PARFILE=${1}
    115         PARLIST=${2}
    116         PARDIR=${3}
    117 
    118         if [ ! -d "${PARDIR}" ]; then
    119                 # SCMSGS
    120                 # @explanation
    121                 # The parameter file directory you specified in the config
    122                 # file does not exist.
    123                 # @user_action
    124                 # Fix the appropriate config file, either sczbt_config or
    125                 # sczsh_config with an existing directory.
    126                 scds_syslog -p daemon.err -t $(syslog_tag) -m \
    127         	  "Function: val_parfile - Directory %s does not exist or is not a directory" \
    128                   "${PARDIR}"
    129                 rc_val_parfile=1
    130 	else
    131 		debug_message "Function: val_parfile - ${PARDIR} exists"	
    132  	fi
    133 
    134         if [ ! -f "${PARFILE}" ]; then
    135                 scds_syslog -p daemon.err -t $(syslog_tag) -m \
    136                   "Function: val_parfile - File %s does not exist" \
    137                   "${PARFILE}"
    138                 rc_val_parfile=1
    139 	else
    140 		debug_message "Function: val_parfile - ${PARFILE} exists"	
    141  	fi
    142 
    143 	if ! ksh -n ${PARFILE} >/dev/null 2>&1
    144 	then
    145         	scds_syslog -p daemon.err -t $(syslog_tag) -m \
    146                   "Function: validate - Syntax errors in %s" \
    147                	  "${PARFILE}"
    148                rc_val_parfile=1
    149 	else
    150 		debug_message "Function: val_parfile - validated ${PARFILE}"	
    151        	fi
    152 
    153 	# Test if all the mandatory variables are included and set correctly in the parameter file
    154 
    155 	PARAMETERS=`cat ${PARFILE} |grep -v "^#"|grep -v "^ "|nawk -F= '{print $1}'`
    156 
    157 	for i in ${PARLIST}
    158 	do
    159 		if ! `echo ${PARAMETERS} |grep ${i} > /dev/null `; then
    160                 	scds_syslog -p daemon.err -t $(syslog_tag) -m \
    161                           "Function: val_parfile - %s not specified in %s, which is required" \
    162                           "${i}" "${PARFILE}"
    163 		rc_val_parfile=1
    164 		else
    165 			debug_message "Function: val_parfile - ${i} included in ${PARFILE}"	
    166                 fi
    167 	done
    168 
    169 	debug_message "Function: val_parfile - End"
    170 	return ${rc_val_parfile}
    171 }
    172 
    173 val_in_global()
    174 {
    175 	# Validate that we are in the global zone
    176 	
    177         debug_message "Function: val_in_global - Begin"
    178 	${SET_DEBUG}
    179 
    180 	rc_val_in_global=0
    181 
    182 	if ! /usr/bin/zonename | grep "^global$" >/dev/null 2>&1
    183 	then
    184    		# SCMSGS
    185    		# @explanation
    186    		# A start, stop or probe command was used from the local zone.
    187    		# @user_action
    188    		# Use the start, stop and probe commands from th eglobal zone
    189    		# only.
    190    		scds_syslog -p daemon.err -t $(syslog_tag) -m \
    191 		  "Function: val_in_global - Not in the global zone" 
    192 		rc_val_in_global=1
    193 	else
    194 		debug_message "Function: val_in_global - Global zone"
    195 	fi
    196 
    197 	debug_message "Function: val_in_global - End"
    198 	return ${rc_val_in_global}
    199 }
    200