Home | History | Annotate | Download | only in mys
      1 #!/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 2006 Sun Microsystems, Inc.  All rights reserved.
     25 # Use is subject to license terms.
     26 #
     27 
     28 #ident	"@(#)ha_mysql_register.ksh	1.7	07/06/06 SMI"
     29 
     30 #
     31 #  This script takes 2 options, both are optional.
     32 #  -f filename states a config file different from ha_mysql_config.
     33 #     This file will be sourced instead of ha_mysql_config if -f filename is specified
     34 #
     35 #  -z smf/zsh 
     36 #     This option  is used for local zone instances only. smf stands for a 
     37 #     Sun Cluster Agent for Containder SMF Component, zsh stands for the 
     38 #     zsh component
     39 
     40 MYNAME=`basename ${0}`
     41 MYDIR=`dirname ${0}`
     42 
     43 # Set generic variables:
     44 
     45 BINDIR=/opt/SUNWscmys/bin
     46 UTILDIR=/opt/SUNWscmys/util
     47 SMFUTILDIR=/opt/SUNWsczone/sczsmf/util
     48 ZSHUTILDIR=/opt/SUNWsczone/sczsh/util
     49 ECHO=/usr/bin/echo
     50 
     51 . ${MYDIR}/../etc/config
     52 . ${MYDIR}/../lib/functions_static
     53 . ${MYDIR}/../bin/functions
     54 
     55 global_zone()
     56 {
     57 
     58 # function to register a resource in the global zone or on solaris 8 or 9
     59 
     60 # define your start, stop, probe an validate command
     61 
     62 	start_command="${BINDIR}/start_mysql -R $RS -G $RG -B $BASEDIR -D $DATADIR -U $MYSQLUSER \
     63 	-H ${MYSQLHOST} -F ${FMUSER}%${FMPASS} -L $LOGDIR ${CHECK} "
     64 	stop_command="${BINDIR}/stop_mysql -R $RS -G $RG -B $BASEDIR -D $DATADIR -U $MYSQLUSER \
     65 	-H ${MYSQLHOST} -F ${FMUSER}%${FMPASS} -L $LOGDIR ${CHECK} "
     66 	probe_command="${BINDIR}/probe_mysql -R $RS -G $RG -B $BASEDIR -D $DATADIR -U $MYSQLUSER \
     67 	-H ${MYSQLHOST} -F ${FMUSER}%${FMPASS} -L $LOGDIR ${CHECK} "
     68 	validate_command="${BINDIR}/control_mysql -R $RS -G $RG -B $BASEDIR -D $DATADIR -U $MYSQLUSER \
     69 	-H ${MYSQLHOST} -F ${FMUSER}%${FMPASS} -L $LOGDIR ${CHECK} 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 		scrgadm -a -j $RS -g $RG -t SUNW.gds \
     79 		-x Start_command="${start_command}" \
     80 		-x Probe_command="${probe_command}" \
     81 		-x Stop_command="${stop_command}" \
     82 		-x Validate_command="${validate_command}" \
     83 		-y Port_list=23/tcp -y Network_resources_used=$LH \
     84 		-x Stop_signal=9 \
     85 		-y Resource_dependencies=$HAS_RS
     86 		
     87 		St=$?
     88 	else
     89 
     90 		# register in 3.1 style
     91 
     92 		scrgadm -a -j $RS -g $RG -t SUNW.gds \
     93 		-x Start_command="${start_command}" \
     94 		-x Probe_command="${probe_command}" \
     95 		-x Stop_command="${stop_command}" \
     96 		-y Port_list=23/tcp -y Network_resources_used=$LH \
     97 		-x Stop_signal=9 \
     98 		-y Resource_dependencies=$HAS_RS
     99 		
    100 		St=$?
    101 	fi
    102 	
    103 	if [ "${St}" -ne 0 ]; then
    104 	        echo "Registration of resource ${RS} failed, please correct the wrong parameters."
    105 	
    106 	        return 1
    107 	else
    108 	        echo "Registration of resource ${RS} succeeded."
    109 	fi
    110 	
    111 	if ! /usr/cluster/bin/scrgadm -pvv -t SUNW.gds | /usr/bin/grep Validate_command>/dev/null 2>&1
    112 	then
    113 
    114 		# VALIDATE RESOURCE
    115 		
    116 		echo "Validate resource ${RS} in resourcegroup ${RG}"
    117 		
    118 		${BINDIR}/control_mysql -R ${RS} -G ${RG} -B $BASEDIR -D $DATADIR -U $MYSQLUSER \
    119 	        -H ${MYSQLHOST} -F ${FMUSER}%${FMPASS} -L $LOGDIR ${CHECK} validate
    120 		
    121 		St=$?
    122 		
    123 		if [ "${St}" -ne 0 ]; then
    124 		        echo "Validation of resource ${RS} failed, please correct the wrong parameters."
    125 		        echo "Removing resource ${RS} from the cluster configuration."
    126 		
    127 		        /usr/cluster/bin/scrgadm -r -j ${RS}
    128 		
    129 		        return 1
    130 		else
    131 		        echo "Validation of resource ${RS} succeeded."
    132 		fi
    133 	fi
    134 
    135 }
    136 
    137 local_zone_smf()
    138 {
    139 
    140 # function to register a smf resource
    141 
    142 	SERVICE_TAG=svc:/application/sczone-agents:${RS}
    143 
    144 	if [ ! -f ${SMFUTILDIR}/sczsmf_config ]
    145 	then
    146 		echo  ${SMFUTILDIR}/sczsmf_config does not exist. Make sure, that \
    147 		      Sun Cluster HA for Solaris container is intalled in the global zone
    148 		return 1
    149 	fi
    150 
    151 # prepare the config file
    152 
    153 	cp ${SMFUTILDIR}/sczsmf_config ${SMFUTILDIR}/sczsmf_config.work
    154 	cat << EOF > ${SMFUTILDIR}/sczsmf_config 
    155 #
    156 # Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
    157 # Use is subject to license terms.
    158 #
    159 # This file will be sourced in by sczsmf_register and the parameters
    160 # listed below will be used.
    161 #
    162 # These parameters can be customized in (key=value) form
    163 #
    164 #               RS - Name of the resource
    165 #               RG - Name of the resource group containing RS
    166 #         SCZBT_RS - Name of the SC Zone boot resource
    167 #             ZONE - Name of the Zone
    168 #
    169 #       For SERVICE, RECURSIVE and STATE, refer to the svcadm(1M)
    170 #                 man page
    171 #
    172 #          SERVICE - {FMRI | pattern}
    173 #               FMRI - Fault management resource identifier
    174 #               pattern - Pattern matching a service
    175 #
    176 #        RECURSIVE - {false | true}     Default: true
    177 #               False - Just enable the service and no dependents
    178 #               True - Enable the service and recursively enable
    179 #                 its dependents
    180 #
    181 #               RECURSIVE=true equates to svcadm enable "-r"
    182 #
    183 #            STATE - {false | true}     Default: true
    184 #               False - Do not wait until service state is reached
    185 #               True - Wait until service state is reached
    186 #
    187 #               STATE=true equates to svcadm enable/disable "-s"
    188 #
    189 #    SERVICE_PROBE - Script to check the SMF service
    190 #
    191 #               The optional parameter, SERVICE_PROBE, provides the
    192 #                 ability to check that the SMF service is working.
    193 #                 This must be a script within the zone and must
    194 #                 adhere to these return codes,
    195 #
    196 #                 0 - The SMF service is working
    197 #               100 - The SMF service should be restarted
    198 #               201 - The SMF service should initiate a failover of
    199 #                       the Resource Group
    200 #
    201 #               Note: That return code 201, requires that this resource
    202 #                 has an appropriate extension property value for
    203 #                 FAILOVER_MODE and FAILOVER_ENABLED=TRUE
    204 #
    205 #               For FAILOVER_MODE refer to the r_properties(5) man page.
    206 #
    207 
    208 RS=${RS}
    209 RG=${RG}
    210 SCZBT_RS=${ZONE_BT}
    211 ZONE=${ZONE}
    212 SERVICE=${SERVICE_TAG}
    213 RECURSIVE=false
    214 STATE=true
    215 SERVICE_PROBE="${BINDIR}/control_mysql probe ${SERVICE_TAG}"
    216   
    217 EOF
    218 
    219 	# determine if a working copy of the config file was created if yes use the -f option
    220 
    221 	REGOPT=""
    222 	if [ -f ${UTILDIR}/ha_mysql_config.work ]
    223 	then
    224 		/usr/bin/cat ${UTILDIR}/ha_mysql_config.work | /usr/sbin/zlogin ${ZONE} /usr/bin/cat - \>/tmp/ha_mysql_config.work
    225 		REGOPT="-f /tmp/ha_mysql_config.work"
    226 	else
    227 		/usr/bin/cat ${UTILDIR}/ha_mysql_config | /usr/sbin/zlogin ${ZONE} /usr/bin/cat - \>/tmp/ha_mysql_config.work
    228 		REGOPT="-f /tmp/ha_mysql_config.work"
    229 	fi
    230 
    231 	echo clean up the manifest / smf resource
    232 	${UTILDIR}/ha_mysql_smf_remove ${REGOPT} 2>/dev/null
    233 	
    234 
    235 	# register the manifest
    236 
    237 	if /usr/sbin/zlogin ${ZONE} ${UTILDIR}/ha_mysql_smf_register ${REGOPT}
    238 	then
    239 		echo "Manifest svc:/application/sczone-agents:${RS} was created in zone ${ZONE}"
    240 		echo "Registering the zone smf resource"
    241 		ksh ${SMFUTILDIR}/sczsmf_register
    242 		ret_code=${?}
    243                 mv ${SMFUTILDIR}/sczsmf_config.work ${SMFUTILDIR}/sczsmf_config
    244 	else
    245 		echo "The registration of the manifest did not complete, fix the errors and retry"
    246 		ret_code=0
    247 	fi
    248 	return ${ret_code}
    249 
    250 }
    251 
    252 MYCONFIG=
    253 
    254 typeset opt
    255 
    256 while getopts 'f:' opt
    257 do
    258         case "${opt}" in
    259                 f)      MYCONFIG=${OPTARG};;
    260                 *)      echo "ERROR: ${MYNAME} Option ${OPTARG} unknown - early End. Only -f is valid"
    261                         exit 1;;
    262         esac
    263 done
    264 
    265 # Sourcing the specified config file, either the default one,
    266 # or the one supplied with -f
    267 
    268 if [ -n "${MYCONFIG}" ] && [ -f "${MYCONFIG}" ]
    269 then
    270 	echo "sourcing ${MYCONFIG} and create a working copy under ${UTILDIR}/ha_mysql_config.work"
    271 	cp ${MYCONFIG} ${UTILDIR}/ha_mysql_config.work
    272 	. ${MYCONFIG}
    273 else
    274 	PKGCONF=`dirname $0`/ha_mysql_config
    275 	echo "sourcing ${PKGCONF}"
    276 	. ${PKGCONF}
    277 fi
    278 
    279 if [ "${CHECK}" = "YES" ]; then
    280    CHECK=" -C"
    281 else
    282    CHECK=""
    283 fi
    284 
    285 
    286 # Registering the resource
    287 
    288 if [ -z "${ZONE}" ]
    289 then
    290 	global_zone
    291 else
    292 	local_zone_smf
    293 fi
    294 
    295 if [ -f ${UTILDIR}/ha_mysql_config.work ]
    296 then
    297         echo " remove the working copy ${UTILDIR}/ha_mysql_config.work"
    298 	rm ${UTILDIR}/ha_mysql_config.work
    299 fi
    300 
    301 exit 0
    302