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 2007 Sun Microsystems, Inc. All rights reserved. 25 # Use is subject to license terms. 26 # 27 28 #ident "@(#)control_mysql.ksh 1.8 07/06/06 SMI" 29 30 # Method for the mysql agents smf manifest and for the zsh component 31 # 32 # This method is called by the manifest, by the optional probe script of the smf method 33 # and as start stop and probe for the zsh component. 34 # 35 # it is started with options - up to 2 parameters: 36 # 37 # The options are used it smf_mysql is started for the zsh component. 38 # in example smf_mysql -R resource -G group -S timout -P project start 39 # in the example above are no agent specific options included, obviously they need 40 # to be amended. 41 # 42 # if you use it for smf omit all the options and specify the parameters as stated below. 43 # 44 # $1 start stop or probe 45 # $2 is the smf service tag name. It is used only if the parameter $1 is probe 46 # 47 48 MYNAME=`basename ${0}` 49 MYDIR=`dirname ${0}` 50 51 . ${MYDIR}/functions 52 . ${MYDIR}/../etc/config 53 . ${MYDIR}/../lib/functions_static 54 55 if [ -f /lib/svc/share/smf_include.sh ] 56 then 57 . /lib/svc/share/smf_include.sh 58 fi 59 debug_message "Method: ${MYNAME} ${1} - Begin" 60 ${SET_DEBUG} 61 62 # get the options for gds and the zsh command, amend as appropriate 63 64 while getopts 'R:G:B:D:U:H:F:L:C' opt 65 do 66 case "${opt}" in 67 R) RESOURCE=${OPTARG};; 68 G) RESOURCEGROUP=${OPTARG};; 69 B) MYSQL_BASEDIR=$OPTARG;; 70 D) MYSQL_DATADIR=$OPTARG;; 71 U) MYSQL_USER=$OPTARG;; 72 H) MYSQL_HOST=$OPTARG;; 73 F) MYSQL_FMUSER=$OPTARG;; 74 L) MYSQL_LOGDIR=$OPTARG;; 75 C) MYSQL_CHECK=TRUE;; 76 *) exit 1;; 77 esac 78 done 79 80 # if no option is set ($OPTIND is 1 in this case), use the smf properties 81 82 if [ ${OPTIND} -gt 1 ] 83 then 84 85 86 shift $((${OPTIND} - 1)) 87 else 88 89 # Setting SMF_FMRI in case of validate and probe 90 91 if [ -z "${SMF_FMRI}" ] 92 then 93 SMF_FMRI=${2} 94 fi 95 96 # getting the necessary parameters and filling the variables usually filled 97 # in from options 98 99 get_fmri_parameters 100 101 fi 102 103 104 # Source functions to nail down parameters which are set by options or get_fmri_parameters 105 . ${MYDIR}/functions 106 107 # set some generic variables 108 LOGFILE=/var/tmp/${RESOURCE}_logfile 109 110 case ${1} in 111 start) 112 113 # start application mysql 114 115 # exit from start, if the options are wrong 116 117 validate_options 118 rc_val=${?} 119 if [ ${rc_val} -ne 0 ] 120 then 121 terminate ${1} ${rc_val} 122 fi 123 124 rm ${LOGFILE} 2>/dev/null 125 126 variables_init 127 128 if validate 129 then 130 131 start_mysql 132 rc_val=${?} 133 134 if [ ${rc_val} -eq 0 ] 135 then 136 log_message notice "start_command rc<${rc_val}>" 137 debug_message "Method: ${MYNAME} - End (Exit 0)" 138 else 139 log_message err "start_command rc<${rc_val}>" 140 fi 141 else 142 debug_message "Method: ${MYNAME} - End (Exit 1)" 143 rc_val=1 144 fi;; 145 stop) 146 147 # stop application mysql 148 149 # exit from stop, if the options are wrong 150 151 validate_options 152 rc_val=${?} 153 if [ ${rc_val} -ne 0 ] 154 then 155 terminate ${1} ${rc_val} 156 fi 157 158 variables_init 159 160 stop_mysql 161 rc_val=${?} 162 163 if [ "${rc_val}" -eq 0 ] 164 then 165 log_message notice "stop_command rc<${rc_val}>" 166 else 167 log_message err "stop_command rc<${rc_val}>" 168 fi;; 169 170 probe) 171 172 # probe application mysql 173 174 # exit from probe, if the options are wrong 175 176 validate_options 177 rc_val=${?} 178 if [ ${rc_val} -ne 0 ] 179 then 180 terminate ${1} ${rc_val} 181 fi 182 183 variables_init 184 185 if ! validate 186 then 187 rc_val=100 188 else 189 190 # spin off a project based smf probe if necessary, do the probe with the check function otherwise 191 192 if [ "${Project}" != ":default" ] && [ -n "${SMF_FMRI}" ] 193 then 194 if /usr/bin/newtask -p ${Project} ${MYDIR}/probe_smf_mysql ${SMF_FMRI} 195 then 196 rc_val=0 197 else 198 rc_val=100 199 fi 200 else 201 202 if check_mysql 203 then 204 rc_val=0 205 else 206 rc_val=100 207 fi 208 fi 209 fi;; 210 211 validate) 212 213 # validate the parameters for application mysql 214 215 validate_options 216 rc_val=${?} 217 if [ ${rc_val} -ne 0 ] 218 then 219 terminate ${1} ${rc_val} 220 fi 221 222 rm ${LOGFILE} 2>/dev/null 223 224 variables_init 225 226 if validate 227 then 228 rc_val=0 229 else 230 rc_val=1 231 fi;; 232 233 esac 234 235 # terminate with the right return code, either with an smf specific or the gds/zsh based 236 # return code 237 238 terminate ${1} ${rc_val} 239