/[gentoo-x86]/eclass/mysql.eclass
Gentoo

Diff of /eclass/mysql.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.174 Revision 1.176
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2012 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/mysql.eclass,v 1.174 2012/09/10 02:07:08 ferringb Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/mysql.eclass,v 1.176 2012/11/01 20:22:57 robbat2 Exp $
4 4
5# @ECLASS: mysql.eclass 5# @ECLASS: mysql.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# MySQL Team <mysql-bugs@gentoo.org> 7# MySQL Team <mysql-bugs@gentoo.org>
8# Luca Longinotti <chtekk@gentoo.org> 8# Luca Longinotti <chtekk@gentoo.org>
31 EGIT_REPO_URI="git://git.overlays.gentoo.org/proj/mysql-extras.git" 31 EGIT_REPO_URI="git://git.overlays.gentoo.org/proj/mysql-extras.git"
32 inherit git-2 32 inherit git-2
33fi 33fi
34 34
35case "${EAPI:-0}" in 35case "${EAPI:-0}" in
36 2 | 3 | 4) 36 2|3|4|5)
37 EXPORT_FUNCTIONS pkg_setup \ 37 EXPORT_FUNCTIONS pkg_setup \
38 src_unpack src_prepare \ 38 src_unpack src_prepare \
39 src_configure src_compile \ 39 src_configure src_compile \
40 src_install \ 40 src_install \
41 pkg_preinst pkg_postinst \ 41 pkg_preinst pkg_postinst \
712 fi 712 fi
713 fi 713 fi
714 714
715 if pbxt_available && [[ "${PBXT_NEWSTYLE}" == "1" ]]; then 715 if pbxt_available && [[ "${PBXT_NEWSTYLE}" == "1" ]]; then
716 use pbxt \ 716 use pbxt \
717 && plugins_dyn="${plugins_dyn} pbxt" \ 717 && plugins_sta="${plugins_sta} pbxt" \
718 || plugins_dis="${plugins_dis} pbxt" 718 || plugins_dis="${plugins_dis} pbxt"
719 fi 719 fi
720 720
721 use static && \ 721 use static && \
722 plugins_sta="${plugins_sta} ${plugins_dyn}" && \ 722 plugins_sta="${plugins_sta} ${plugins_dyn}" && \
1267 elog "mysql_upgrade tool." 1267 elog "mysql_upgrade tool."
1268 einfo 1268 einfo
1269 fi 1269 fi
1270 1270
1271 if pbxt_available && use pbxt ; then 1271 if pbxt_available && use pbxt ; then
1272 # TODO: explain it better 1272 elog "Note: PBXT is now statically built when enabled."
1273 elog " mysql> INSTALL PLUGIN pbxt SONAME 'libpbxt.so';" 1273 elog ""
1274 elog " mysql> CREATE TABLE t1 (c1 int, c2 text) ENGINE=pbxt;" 1274 elog "If, you previously installed as a plugin and "
1275 elog "if, after that, you cannot start the MySQL server," 1275 elog "you cannot start the MySQL server,"
1276 elog "remove the ${MY_DATADIR}/mysql/plugin.* files, then" 1276 elog "remove the ${MY_DATADIR}/mysql/plugin.* files, then"
1277 elog "use the MySQL upgrade script to restore the table" 1277 elog "use the MySQL upgrade script to restore the table"
1278 elog "or execute the following SQL command:" 1278 elog "or execute the following SQL command:"
1279 elog " CREATE TABLE IF NOT EXISTS plugin (" 1279 elog " CREATE TABLE IF NOT EXISTS plugin ("
1280 elog " name char(64) binary DEFAULT '' NOT NULL," 1280 elog " name char(64) binary DEFAULT '' NOT NULL,"
1286 mysql_check_version_range "4.0 to 5.0.99.99" \ 1286 mysql_check_version_range "4.0 to 5.0.99.99" \
1287 && use berkdb \ 1287 && use berkdb \
1288 && elog "Berkeley DB support is deprecated and will be removed in future versions!" 1288 && elog "Berkeley DB support is deprecated and will be removed in future versions!"
1289} 1289}
1290 1290
1291# @FUNCTION: mysql_getopt
1292# @DESCRIPTION:
1293# Use my_print_defaults to extract specific config options
1294mysql_getopt() {
1295 local mypd="${EROOT}"/usr/bin/my_print_defaults
1296 section="$1"
1297 flag="--${2}="
1298 "${mypd}" $section | sed -n "/^${flag}/p"
1299}
1300
1301# @FUNCTION: mysql_getoptval
1302# @DESCRIPTION:
1303# Use my_print_defaults to extract specific config options
1304mysql_getoptval() {
1305 local mypd="${EROOT}"/usr/bin/my_print_defaults
1306 section="$1"
1307 flag="--${2}="
1308 "${mypd}" $section | sed -n "/^${flag}/s,${flag},,gp"
1309}
1310
1291# @FUNCTION: mysql_pkg_config 1311# @FUNCTION: mysql_pkg_config
1292# @DESCRIPTION: 1312# @DESCRIPTION:
1293# Configure mysql environment. 1313# Configure mysql environment.
1294mysql_pkg_config() { 1314mysql_pkg_config() {
1295 local old_MY_DATADIR="${MY_DATADIR}" 1315 local old_MY_DATADIR="${MY_DATADIR}"
1316 local old_HOME="${HOME}"
1317 # my_print_defaults needs to read stuff in $HOME/.my.cnf
1318 export HOME=/root
1296 1319
1297 # Make sure the vars are correctly initialized 1320 # Make sure the vars are correctly initialized
1298 mysql_init_vars 1321 mysql_init_vars
1299 1322
1300 [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR" 1323 [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
1307 local MY_DATADIR_s="${ROOT}/${MY_DATADIR}" 1330 local MY_DATADIR_s="${ROOT}/${MY_DATADIR}"
1308 MY_DATADIR_s="${MY_DATADIR_s%%/}" 1331 MY_DATADIR_s="${MY_DATADIR_s%%/}"
1309 local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}" 1332 local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
1310 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}" 1333 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
1311 1334
1312 if [[ -d "${old_MY_DATADIR_s}" ]]; then 1335 if [[ -d "${old_MY_DATADIR_s}" ]] && [[ "${old_MY_DATADIR_s}" != / ]]; then
1313 if [[ -d "${MY_DATADIR_s}" ]]; then 1336 if [[ -d "${MY_DATADIR_s}" ]]; then
1314 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist" 1337 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
1315 ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}" 1338 ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
1316 else 1339 else
1317 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}" 1340 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
1331 1354
1332 local pwd1="a" 1355 local pwd1="a"
1333 local pwd2="b" 1356 local pwd2="b"
1334 local maxtry=15 1357 local maxtry=15
1335 1358
1336 if [ -z "${MYSQL_ROOT_PASSWORD}" -a -f "${EROOT}/root/.my.cnf" ]; then 1359 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
1337 MYSQL_ROOT_PASSWORD="$(sed -n -e '/^password=/s,^password=,,gp' "${EROOT}/root/.my.cnf")" 1360 MYSQL_ROOT_PASSWORD="$(mysql_getoptval 'client mysql' password)"
1361 fi
1362 MYSQL_TMPDIR="$(mysql_getoptval mysqld tmpdir)"
1363 # These are dir+prefix
1364 MYSQL_RELAY_LOG="$(mysql_getoptval mysqld relay-log)"
1365 MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
1366 MYSQL_LOG_BIN="$(mysql_getoptval mysqld log-bin)"
1367 MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
1368
1369 if [[ ! -d "${EROOT}"/$MYSQL_TMPDIR ]]; then
1370 einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
1371 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_TMPDIR
1372 fi
1373 if [[ ! -d "${EROOT}"/$MYSQL_LOG_BIN ]]; then
1374 einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
1375 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_LOG_BIN
1376 fi
1377 if [[ ! -d "${EROOT}"/$MYSQL_RELAY_LOG ]]; then
1378 einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
1379 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_RELAY_LOG
1338 fi 1380 fi
1339 1381
1340 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then 1382 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
1341 ewarn "You have already a MySQL database in place." 1383 ewarn "You have already a MySQL database in place."
1342 ewarn "(${ROOT}/${MY_DATADIR}/*)" 1384 ewarn "(${ROOT}/${MY_DATADIR}/*)"
1363 fi 1405 fi
1364 MYSQL_ROOT_PASSWORD="${pwd1}" 1406 MYSQL_ROOT_PASSWORD="${pwd1}"
1365 unset pwd1 pwd2 1407 unset pwd1 pwd2
1366 fi 1408 fi
1367 1409
1368 local options="" 1410 local options="--log-warnings=0"
1369 local sqltmp="$(emktemp)" 1411 local sqltmp="$(emktemp)"
1370 1412
1371 local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql" 1413 local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql"
1372 [[ -r "${help_tables}" ]] \ 1414 [[ -r "${help_tables}" ]] \
1373 && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \ 1415 && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \
1374 || touch "${TMPDIR}/fill_help_tables.sql" 1416 || touch "${TMPDIR}/fill_help_tables.sql"
1375 help_tables="${TMPDIR}/fill_help_tables.sql" 1417 help_tables="${TMPDIR}/fill_help_tables.sql"
1376 1418
1419 # Figure out which options we need to disable to do the setup
1420 helpfile="${TMPDIR}/mysqld-help"
1421 ${EROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null
1422 for opt in grant-tables host-cache name-resolve networking slave-start bdb \
1423 federated innodb ssl log-bin relay-log slow-query-log external-locking \
1424 ndbcluster log-slave-updates \
1425 ; do
1426 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
1427 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
1428 done
1429 # But some options changed names
1430 egrep -sq external-locking "${helpfile}" && \
1431 options="${options/skip-locking/skip-external-locking}"
1432
1433 use prefix || options="${options} --user=mysql"
1434
1377 pushd "${TMPDIR}" &>/dev/null 1435 pushd "${TMPDIR}" &>/dev/null
1378 "${EROOT}/usr/bin/mysql_install_db" >"${TMPDIR}"/mysql_install_db.log 2>&1 1436 #cmd="'${EROOT}/usr/share/mysql/scripts/mysql_install_db' '--basedir=${EPREFIX}/usr' ${options}"
1437 cmd=${EROOT}usr/share/mysql/scripts/mysql_install_db
1438 [ -f ${cmd} ] || cmd=${EROOT}usr/bin/mysql_install_db
1439 cmd="'$cmd' '--basedir=${EPREFIX}/usr' ${options}"
1440 einfo "Command: $cmd"
1441 eval $cmd \
1442 >"${TMPDIR}"/mysql_install_db.log 2>&1
1379 if [ $? -ne 0 ]; then 1443 if [ $? -ne 0 ]; then
1380 grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2 1444 grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2
1381 die "Failed to run mysql_install_db. Please review /var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log" 1445 die "Failed to run mysql_install_db. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log"
1382 fi 1446 fi
1383 popd &>/dev/null 1447 popd &>/dev/null
1384 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \ 1448 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
1385 || die "MySQL databases not installed" 1449 || die "MySQL databases not installed"
1386 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null 1450 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null
1387 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null 1451 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null
1388 1452
1389 # Figure out which options we need to disable to do the setup
1390 helpfile="${TMPDIR}/mysqld-help"
1391 ${EROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null
1392 for opt in grant-tables host-cache name-resolve networking slave-start bdb \
1393 federated innodb ssl log-bin relay-log slow-query-log external-locking \
1394 ndbcluster \
1395 ; do
1396 optexp="--(skip-)?${opt}" optfull="--skip-${opt}"
1397 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
1398 done
1399 # But some options changed names
1400 egrep -sq external-locking "${helpfile}" && \
1401 options="${options/skip-locking/skip-external-locking}"
1402
1403 if mysql_version_is_at_least "4.1.3" ; then 1453 if mysql_version_is_at_least "4.1.3" ; then
1404 # Filling timezones, see 1454 # Filling timezones, see
1405 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html 1455 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
1406 "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null 1456 "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
1407 1457
1410 fi 1460 fi
1411 fi 1461 fi
1412 1462
1413 einfo "Creating the mysql database and setting proper" 1463 einfo "Creating the mysql database and setting proper"
1414 einfo "permissions on it ..." 1464 einfo "permissions on it ..."
1415
1416 use prefix || options="${options} --user=mysql"
1417 1465
1418 local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock" 1466 local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
1419 local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid" 1467 local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
1420 local mysqld="${EROOT}/usr/sbin/mysqld \ 1468 local mysqld="${EROOT}/usr/sbin/mysqld \
1421 ${options} \ 1469 ${options} \
1422 --user=mysql \ 1470 --user=mysql \
1471 --log-warnings=0 \
1423 --basedir=${EROOT}/usr \ 1472 --basedir=${EROOT}/usr \
1424 --datadir=${ROOT}/${MY_DATADIR} \ 1473 --datadir=${ROOT}/${MY_DATADIR} \
1425 --max_allowed_packet=8M \ 1474 --max_allowed_packet=8M \
1426 --net_buffer_length=16K \ 1475 --net_buffer_length=16K \
1427 --default-storage-engine=MyISAM \ 1476 --default-storage-engine=MyISAM \
1428 --socket=${socket} \ 1477 --socket=${socket} \
1429 --pid-file=${pidfile}" 1478 --pid-file=${pidfile}"
1430 #einfo "About to start mysqld: ${mysqld}" 1479 #einfo "About to start mysqld: ${mysqld}"
1431 ebegin "Starting mysqld" 1480 ebegin "Starting mysqld"
1481 einfo "Command ${mysqld}"
1432 ${mysqld} & 1482 ${mysqld} &
1433 rc=$? 1483 rc=$?
1434 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do 1484 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
1435 maxtry=$((${maxtry}-1)) 1485 maxtry=$((${maxtry}-1))
1436 echo -n "." 1486 echo -n "."
1454 ebegin "Loading \"zoneinfo\", this step may require a few seconds ..." 1504 ebegin "Loading \"zoneinfo\", this step may require a few seconds ..."
1455 "${EROOT}/usr/bin/mysql" \ 1505 "${EROOT}/usr/bin/mysql" \
1456 --socket=${socket} \ 1506 --socket=${socket} \
1457 -hlocalhost \ 1507 -hlocalhost \
1458 -uroot \ 1508 -uroot \
1459 -p"${MYSQL_ROOT_PASSWORD}" \ 1509 --password="${MYSQL_ROOT_PASSWORD}" \
1460 mysql < "${sqltmp}" 1510 mysql < "${sqltmp}"
1461 rc=$? 1511 rc=$?
1462 eend $? 1512 eend $?
1463 [ $rc -ne 0 ] && ewarn "Failed to load zoneinfo!" 1513 [ $rc -ne 0 ] && ewarn "Failed to load zoneinfo!"
1464 1514

Legend:
Removed from v.1.174  
changed lines
  Added in v.1.176

  ViewVC Help
Powered by ViewVC 1.1.20