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 2007 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 27 #ident "@(#)mysql_register.ksh 1.7 07/08/07 SMI" 28 29 30 BINDIR=/opt/SUNWscmys/bin 31 UTILDIR=/opt/SUNWscmys/util 32 MYCONFIG= 33 34 typeset opt 35 36 while getopts 'f:' opt 37 do 38 case "${opt}" in 39 f) MYCONFIG=${OPTARG};; 40 *) exit 1;; 41 esac 42 done 43 44 # source the necessary functions for defining the PORT variable 45 46 . `dirname $0`/../etc/config 47 . `dirname $0`/../bin/functions 48 . `dirname $0`/../lib/functions_static 49 50 # Sourcing the specified config file, either the default one, 51 # or the one supplied with -f 52 53 if [ -n "${MYCONFIG}" ] && [ -f "${MYCONFIG}" ] 54 then 55 echo "sourcing ${MYCONFIG} and create a working copy under ${UTILDIR}/mysql_config.work" 56 cp ${MYCONFIG} ${UTILDIR}/mysql_config.work 2>/dev/null 57 . ${MYCONFIG} 58 else 59 PKGCONF=`dirname $0`/mysql_config 60 echo "sourcing ${PKGCONF}" 61 . ${PKGCONF} 62 fi 63 64 # initialize the variables common with start, stop and check 65 66 MYSQL_BASEDIR=${MYSQL_BASE} 67 variables_init 68 69 # initialize the rest 70 71 TEST_DB="sc3_test_database" 72 SOLARIS_RELEASE=`uname -r` 73 CLUSTER_RELEASE=`pkginfo -l SUNWscgds 2>/dev/null | /bin/grep VERSION | /bin/awk '{print $2}' | /bin/cut -d'.' -f1-2` 74 75 76 if [ ! -f "${MYSQL_DEFAULT_FILE}" ]; then 77 echo "${MYSQL_DEFAULT_FILE} don't exist" 78 exit 1 79 fi 80 81 if [ ! -x "${MYSQL_MYSQL}" ]; then 82 echo "${MYSQL_MYSQL} don't exist" 83 exit 1 84 fi 85 86 # get the PORT variable out of the mysql configuration, which then will contain --port=3306 or whatever port is specified 87 88 get_mysql_port 89 90 echo 91 echo "MySQL version ${MYSQL_VERSION} detected on ${SOLARIS_RELEASE}/SC${CLUSTER_RELEASE}" 92 echo 93 94 # 95 # SPECIAL CARE FOR > SC3.0 96 # 97 98 if [ "${CLUSTER_RELEASE}" != "3.0" ]; then 99 100 # CHECK THAT MYSQL_NIC_HOSTNAME IS SET 101 102 if [ -z "${MYSQL_NIC_HOSTNAME}" ]; then 103 echo "Variable MYSQL_NIC_HOSTNAME is not set in mysql_config" 104 exit 1 105 fi 106 107 node_array=${MYSQL_NIC_HOSTNAME} 108 else 109 node_array=${MYSQL_HOST} 110 fi 111 112 113 cd ${MYSQL_BASEDIR} 114 115 # 116 # Check that MySQL is running and accessible. 117 # Whenever the MySQL daemon is running, mysql_admin returns with 0. 118 # Only the absence of messages on STDERR confirms a real success. 119 # 120 121 echo 122 echo Check if the MySQL server is running and accepting connections 123 echo 124 125 ${MYSQL_MYSQLADMIN} -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWD} ${PORT} ping > ${MYSQL_RESULTF} 2> ${MYSQL_ERRORF} 126 if [ -s "${MYSQL_ERRORF}" ] 127 then 128 echo 129 echo "The MySQL server is not running or not accepting connections" 130 echo 131 echo "The Mysql configuration for HA failed" 132 echo 133 exit 1 134 fi 135 136 config_errors=0 137 138 for node in ${node_array} 139 do 140 141 echo 142 echo "Add faulmonitor user (${FMUSER}) with password (${FMPASS}) with Process-,Select-, Reload- and Shutdown-privileges to user table for mysql database for host ${node}" 143 echo 144 145 ${MYSQL_MYSQL} -S ${MYSQL_SOCK} -u${MYSQL_USER} -p${MYSQL_PASSWD} ${PORT} -e "GRANT PROCESS,SELECT,RELOAD,SHUTDOWN ON *.* TO ${FMUSER}@'${node}' IDENTIFIED BY '${FMPASS}'" 146 147 if [ $? -ne 0 ]; then 148 echo "Add faulmonitor user ${FMUSER} with Process-, Select-, Reload- and Shutdown-privileges to user table for mysql database for ${node} failed" 149 fi 150 151 if [ "${MYSQL_VERSION}" -gt 3 ]; then 152 # 153 # ADD SUPER PRIVILEGE FOR ${FMUSER} 154 # 155 156 echo 157 echo "Add SUPER privilege for ${FMUSER}@${node}" 158 echo 159 160 ${MYSQL_MYSQL} -S ${MYSQL_SOCK} -u${MYSQL_USER} -p${MYSQL_PASSWD} ${PORT} -e "use mysql; UPDATE user SET Super_priv='Y' WHERE user='${FMUSER}' AND Host='${node}';" 161 if [ $? -ne 0 ]; then 162 echo "Add GRANT privilege for ${MYSQL_USER}@${node} failed" 163 let config_errors=${config_errors}+1 164 fi 165 fi 166 done 167 168 169 echo 170 echo "Create test-database ${TEST_DB}" 171 echo 172 ${MYSQL_MYSQL} -S ${MYSQL_SOCK} -u${MYSQL_USER} -p${MYSQL_PASSWD} ${PORT} -e "CREATE DATABASE ${TEST_DB};" 173 174 if [ $? -ne 0 ]; then 175 echo "Create test-database ${TEST_DB} failed" 176 let config_errors=${config_errors}+1 177 fi 178 179 for node in ${node_array} 180 do 181 echo 182 echo "Grant all privileges to ${TEST_DB} for faultmonitor-user ${FMUSER} for host ${node}" 183 echo 184 185 ${MYSQL_MYSQL} -S ${MYSQL_SOCK} -u${MYSQL_USER} -p${MYSQL_PASSWD} ${PORT} -e "GRANT ALL ON ${TEST_DB}.* TO ${FMUSER}@'${node}'" 186 187 if [ $? -ne 0 ]; then 188 echo "Adding all privileges to ${TEST_DB} for faultmonitor-user ${FMUSER} for host ${node} failed" 189 let config_errors=${config_errors}+1 190 fi 191 done 192 193 echo 194 echo "Flush all privileges" 195 echo 196 ${MYSQL_MYSQLADMIN} -S ${MYSQL_SOCK} -u${MYSQL_USER} -p${MYSQL_PASSWD} ${PORT} flush-privileges 197 198 if [ $? -ne 0 ]; then 199 echo "Flush all privileges failed" 200 let config_errors=${config_errors}+1 201 fi 202 203 204 if [ ${config_errors} -eq 0 ] 205 then 206 echo 207 echo "Mysql configuration for HA is done" 208 echo 209 exit 0 210 else 211 echo 212 echo "Mysql configuration for HA reported errors" 213 echo "Some errors like database exists are acceptable" 214 echo "Check the previous output" 215 echo 216 exit 1 217 fi 218 219