diff options
author | Robin H. Johnson <robbat2@gentoo.org> | 2012-11-01 20:22:57 +0000 |
---|---|---|
committer | Robin H. Johnson <robbat2@gentoo.org> | 2012-11-01 20:22:57 +0000 |
commit | f78103e499cf2370c63bfdb66372ba0d2eb0f948 (patch) | |
tree | 2323590fc30e521d37c9da1ba8381d0729508fa3 /eclass/mysql.eclass | |
parent | initial commit (diff) | |
download | historical-f78103e499cf2370c63bfdb66372ba0d2eb0f948.tar.gz historical-f78103e499cf2370c63bfdb66372ba0d2eb0f948.tar.bz2 historical-f78103e499cf2370c63bfdb66372ba0d2eb0f948.zip |
Bug #392361: Fix mysql_install_db cases to work between all versions & variations of MySQL. Also add in checks for tmpdir/log-bin/relay-log directories that must exist otherwise the install_db will fail.
Diffstat (limited to 'eclass/mysql.eclass')
-rw-r--r-- | eclass/mysql.eclass | 104 |
1 files changed, 77 insertions, 27 deletions
diff --git a/eclass/mysql.eclass b/eclass/mysql.eclass index 0448cbe9d78f..18367624f54d 100644 --- a/eclass/mysql.eclass +++ b/eclass/mysql.eclass @@ -1,6 +1,6 @@ # Copyright 1999-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/mysql.eclass,v 1.175 2012/09/27 16:35:41 axs Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/mysql.eclass,v 1.176 2012/11/01 20:22:57 robbat2 Exp $ # @ECLASS: mysql.eclass # @MAINTAINER: @@ -714,7 +714,7 @@ configure_51() { if pbxt_available && [[ "${PBXT_NEWSTYLE}" == "1" ]]; then use pbxt \ - && plugins_dyn="${plugins_dyn} pbxt" \ + && plugins_sta="${plugins_sta} pbxt" \ || plugins_dis="${plugins_dis} pbxt" fi @@ -1269,10 +1269,10 @@ mysql_pkg_postinst() { fi if pbxt_available && use pbxt ; then - # TODO: explain it better - elog " mysql> INSTALL PLUGIN pbxt SONAME 'libpbxt.so';" - elog " mysql> CREATE TABLE t1 (c1 int, c2 text) ENGINE=pbxt;" - elog "if, after that, you cannot start the MySQL server," + elog "Note: PBXT is now statically built when enabled." + elog "" + elog "If, you previously installed as a plugin and " + elog "you cannot start the MySQL server," elog "remove the ${MY_DATADIR}/mysql/plugin.* files, then" elog "use the MySQL upgrade script to restore the table" elog "or execute the following SQL command:" @@ -1288,11 +1288,34 @@ mysql_pkg_postinst() { && elog "Berkeley DB support is deprecated and will be removed in future versions!" } +# @FUNCTION: mysql_getopt +# @DESCRIPTION: +# Use my_print_defaults to extract specific config options +mysql_getopt() { + local mypd="${EROOT}"/usr/bin/my_print_defaults + section="$1" + flag="--${2}=" + "${mypd}" $section | sed -n "/^${flag}/p" +} + +# @FUNCTION: mysql_getoptval +# @DESCRIPTION: +# Use my_print_defaults to extract specific config options +mysql_getoptval() { + local mypd="${EROOT}"/usr/bin/my_print_defaults + section="$1" + flag="--${2}=" + "${mypd}" $section | sed -n "/^${flag}/s,${flag},,gp" +} + # @FUNCTION: mysql_pkg_config # @DESCRIPTION: # Configure mysql environment. mysql_pkg_config() { local old_MY_DATADIR="${MY_DATADIR}" + local old_HOME="${HOME}" + # my_print_defaults needs to read stuff in $HOME/.my.cnf + export HOME=/root # Make sure the vars are correctly initialized mysql_init_vars @@ -1309,7 +1332,7 @@ mysql_pkg_config() { local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}" old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}" - if [[ -d "${old_MY_DATADIR_s}" ]]; then + if [[ -d "${old_MY_DATADIR_s}" ]] && [[ "${old_MY_DATADIR_s}" != / ]]; then if [[ -d "${MY_DATADIR_s}" ]]; then ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist" ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}" @@ -1333,8 +1356,27 @@ mysql_pkg_config() { local pwd2="b" local maxtry=15 - if [ -z "${MYSQL_ROOT_PASSWORD}" -a -f "${EROOT}/root/.my.cnf" ]; then - MYSQL_ROOT_PASSWORD="$(sed -n -e '/^password=/s,^password=,,gp' "${EROOT}/root/.my.cnf")" + if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then + MYSQL_ROOT_PASSWORD="$(mysql_getoptval 'client mysql' password)" + fi + MYSQL_TMPDIR="$(mysql_getoptval mysqld tmpdir)" + # These are dir+prefix + MYSQL_RELAY_LOG="$(mysql_getoptval mysqld relay-log)" + MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*} + MYSQL_LOG_BIN="$(mysql_getoptval mysqld log-bin)" + MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*} + + if [[ ! -d "${EROOT}"/$MYSQL_TMPDIR ]]; then + einfo "Creating MySQL tmpdir $MYSQL_TMPDIR" + install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_TMPDIR + fi + if [[ ! -d "${EROOT}"/$MYSQL_LOG_BIN ]]; then + einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN" + install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_LOG_BIN + fi + if [[ ! -d "${EROOT}"/$MYSQL_RELAY_LOG ]]; then + einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG" + install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_RELAY_LOG fi if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then @@ -1365,7 +1407,7 @@ mysql_pkg_config() { unset pwd1 pwd2 fi - local options="" + local options="--log-warnings=0" local sqltmp="$(emktemp)" local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql" @@ -1374,32 +1416,40 @@ mysql_pkg_config() { || touch "${TMPDIR}/fill_help_tables.sql" help_tables="${TMPDIR}/fill_help_tables.sql" - pushd "${TMPDIR}" &>/dev/null - "${EROOT}/usr/bin/mysql_install_db" >"${TMPDIR}"/mysql_install_db.log 2>&1 - if [ $? -ne 0 ]; then - grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2 - die "Failed to run mysql_install_db. Please review /var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log" - fi - popd &>/dev/null - [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \ - || die "MySQL databases not installed" - chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null - chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null - # Figure out which options we need to disable to do the setup helpfile="${TMPDIR}/mysqld-help" ${EROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null for opt in grant-tables host-cache name-resolve networking slave-start bdb \ federated innodb ssl log-bin relay-log slow-query-log external-locking \ - ndbcluster \ + ndbcluster log-slave-updates \ ; do - optexp="--(skip-)?${opt}" optfull="--skip-${opt}" + optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}" egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}" done # But some options changed names egrep -sq external-locking "${helpfile}" && \ options="${options/skip-locking/skip-external-locking}" + use prefix || options="${options} --user=mysql" + + pushd "${TMPDIR}" &>/dev/null + #cmd="'${EROOT}/usr/share/mysql/scripts/mysql_install_db' '--basedir=${EPREFIX}/usr' ${options}" + cmd=${EROOT}usr/share/mysql/scripts/mysql_install_db + [ -f ${cmd} ] || cmd=${EROOT}usr/bin/mysql_install_db + cmd="'$cmd' '--basedir=${EPREFIX}/usr' ${options}" + einfo "Command: $cmd" + eval $cmd \ + >"${TMPDIR}"/mysql_install_db.log 2>&1 + if [ $? -ne 0 ]; then + grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2 + die "Failed to run mysql_install_db. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log" + fi + popd &>/dev/null + [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \ + || die "MySQL databases not installed" + chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null + chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null + if mysql_version_is_at_least "4.1.3" ; then # Filling timezones, see # http://dev.mysql.com/doc/mysql/en/time-zone-support.html @@ -1413,13 +1463,12 @@ mysql_pkg_config() { einfo "Creating the mysql database and setting proper" einfo "permissions on it ..." - use prefix || options="${options} --user=mysql" - local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock" local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid" local mysqld="${EROOT}/usr/sbin/mysqld \ ${options} \ --user=mysql \ + --log-warnings=0 \ --basedir=${EROOT}/usr \ --datadir=${ROOT}/${MY_DATADIR} \ --max_allowed_packet=8M \ @@ -1429,6 +1478,7 @@ mysql_pkg_config() { --pid-file=${pidfile}" #einfo "About to start mysqld: ${mysqld}" ebegin "Starting mysqld" + einfo "Command ${mysqld}" ${mysqld} & rc=$? while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do @@ -1456,7 +1506,7 @@ mysql_pkg_config() { --socket=${socket} \ -hlocalhost \ -uroot \ - -p"${MYSQL_ROOT_PASSWORD}" \ + --password="${MYSQL_ROOT_PASSWORD}" \ mysql < "${sqltmp}" rc=$? eend $? |