1 #!/usr/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 2008 Sun Microsystems, Inc. All rights reserved. 25 # Use is subject to license terms. 26 # 27 28 #ident "@(#)ha_mysql_smf_register.ksh 1.9 08/04/10 SMI" 29 # 30 31 MYDIR=/opt/SUNWscmys 32 MYFILE= 33 MYCONFIG= 34 MANIFEST_DIR=/var/svc/manifest/application/sczone-agents 35 36 ############################################################# 37 # create_xml() 38 # 39 # This function creates the xml manifest that will get called 40 # by SMF, i.e. svcadm enable <service> . This allows the SMF 41 # service to be called in a zone by the 42 # 43 # Sun Cluster Data Service for Solaris Container 44 # - sczsmf component 45 # 46 ############################################################# 47 48 create_xml() 49 { 50 MYDIR=$1 51 MYFILE=$2 52 53 if [ ! -d "${MANIFEST_DIR}" ] 54 then 55 mkdir -p ${MANIFEST_DIR} 56 fi 57 58 cat > ${MANIFEST_DIR}/${MYFILE}.xml <<-EOF 59 <?xml version="1.0"?> 60 <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1"> 61 62 <!-- 63 Copyright 2006 Sun Microsystems, Inc. All rights reserved. 64 Use is subject to license terms. 65 66 --> 67 68 <service_bundle type='manifest' name='${MYFILE}'> 69 70 <service 71 name='application/sczone-agents' 72 type='service' 73 version='1'> 74 75 <!-- 76 Common dependencies for the service 77 --> 78 79 <dependency name='mysql_services' 80 grouping='require_all' 81 restart_on='none' 82 type='service'> 83 <service_fmri value='svc:/network/loopback'/> 84 </dependency> 85 86 <instance name='${MYFILE}' enabled='false'> 87 88 <!-- 89 Instance specific dependencies allows for multiple instances 90 add application specific path dependencies here 91 --> 92 93 <dependency name='mysql_paths' 94 grouping='require_all' 95 restart_on='none' 96 type='path'> 97 <service_fmri value='file://${BASEDIR}'/> 98 <service_fmri value='file://${DATADIR}'/> 99 <service_fmri value='file://${LOGDIR}'/> 100 </dependency> 101 102 <exec_method 103 type='method' 104 name='start' 105 exec='${MYDIR}/bin/control_mysql start' 106 timeout_seconds='300' > 107 <method_context project='${PROJECT}' > 108 <method_credential user='root' /> 109 </method_context> 110 </exec_method> 111 112 <exec_method 113 type='method' 114 name='stop' 115 exec='${MYDIR}/bin/control_mysql stop' 116 timeout_seconds='300' > 117 <method_context project='${PROJECT}' > 118 <method_credential user='root' /> 119 </method_context> 120 </exec_method> 121 122 123 <!-- 124 Instance specific parameters 125 126 add as many as you need, one per option 127 128 --> 129 130 <property_group name='parameters' type='general'> 131 <propval name='Resource' type='astring' value='${RS}'/> 132 <propval name='Resource_group' type='astring' value='${RG}'/> 133 <propval name='Mysql_basedir' type='astring' value='${BASEDIR}'/> 134 <propval name='Mysql_datadir' type='astring' value='${DATADIR}'/> 135 <propval name='Mysql_user' type='astring' value='${MYSQLUSER}'/> 136 <propval name='Mysql_host' type='astring' value='${MYSQLHOST}'/> 137 <propval name='Mysql_fmuser' type='astring' value='${FMUSER}%${FMPASS}'/> 138 <propval name='Mysql_logdir' type='astring' value='${LOGDIR}'/> 139 <propval name='Mysql_check' type='astring' value='${CHECK}'/> 140 </property_group> 141 142 </instance> 143 144 <stability value='Evolving' /> 145 146 <template> 147 <common_name> 148 <loctext xml:lang='C'> 149 Application mysql 150 </loctext> 151 </common_name> 152 </template> 153 </service> 154 155 </service_bundle> 156 157 EOF 158 } 159 160 typeset opt 161 162 while getopts 'f:' opt 163 do 164 case "${opt}" in 165 f) MYCONFIG=${OPTARG};; 166 *) exit 1;; 167 esac 168 done 169 170 # Sourcing the specified config file, either the default one, 171 # or the one supplied with -f 172 173 if [ -n "${MYCONFIG}" ] && [ -f "${MYCONFIG}" ] 174 then 175 echo "sourcing ${MYCONFIG}" 176 . ${MYCONFIG} 177 else 178 PKGCONF=`dirname $0`/ha_mysql_config 179 echo "sourcing ${PKGCONF}" 180 . ${PKGCONF} 181 fi 182 183 # checking and predefining user and project, if they are not set 184 185 if [ -z "${PROJECT}" ] 186 then 187 PROJECT=:default 188 fi 189 190 MYFILE=${RS} 191 192 if create_xml $MYDIR $MYFILE 193 then 194 printf "${MANIFEST_DIR}/${MYFILE}.xml successfully created\n" 195 else 196 printf "${MANIFEST_DIR}/${MYFILE}.xml failed\n" 197 exit 1 198 fi 199 200 if /usr/sbin/svccfg validate ${MANIFEST_DIR}/${MYFILE}.xml 201 then 202 printf "${MANIFEST_DIR}/${MYFILE}.xml successfully validated\n" 203 else 204 exit 1 205 fi 206 207 if /usr/sbin/svccfg import ${MANIFEST_DIR}/${MYFILE}.xml 208 then 209 printf "${MANIFEST_DIR}/${MYFILE}.xml successfully imported\n" 210 else 211 exit 1 212 fi 213 214 exit 0 215