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

Diff of /eclass/mysql.eclass

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

Revision 1.172 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.172 2012/07/23 10:57:15 jmbsvicetto 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}" && \
788 fi 788 fi
789 789
790 # bug 350844 790 # bug 350844
791 case "${EAPI:-0}" in 791 case "${EAPI:-0}" in
792 0 | 1) 792 0 | 1)
793 if use static && !built_with_use sys-libs/ncurses static-libs; then 793 if use static && ! built_with_use sys-libs/ncurses static-libs; then
794 die "To build MySQL statically you need to enable static-libs for sys-libs/ncurses" 794 die "To build MySQL statically you need to enable static-libs for sys-libs/ncurses"
795 fi 795 fi
796 ;; 796 ;;
797 esac 797 esac
798 798
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"
1302 if built_with_use ${CATEGORY}/${PN} minimal ; then 1325 if built_with_use ${CATEGORY}/${PN} minimal ; then
1303 die "Minimal builds do NOT include the MySQL server" 1326 die "Minimal builds do NOT include the MySQL server"
1304 fi 1327 fi
1305 1328
1306 if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then 1329 if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then
1307 local MY_DATADIR_s="$(strip_duplicate_slashes ${ROOT}/${MY_DATADIR})" 1330 local MY_DATADIR_s="${ROOT}/${MY_DATADIR}"
1331 MY_DATADIR_s="${MY_DATADIR_s%%/}"
1308 local old_MY_DATADIR_s="$(strip_duplicate_slashes ${ROOT}/${old_MY_DATADIR})" 1332 local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
1333 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
1309 1334
1310 if [[ -d "${old_MY_DATADIR_s}" ]]; then 1335 if [[ -d "${old_MY_DATADIR_s}" ]] && [[ "${old_MY_DATADIR_s}" != / ]]; then
1311 if [[ -d "${MY_DATADIR_s}" ]]; then 1336 if [[ -d "${MY_DATADIR_s}" ]]; then
1312 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist" 1337 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
1313 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}"
1314 else 1339 else
1315 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}"
1329 1354
1330 local pwd1="a" 1355 local pwd1="a"
1331 local pwd2="b" 1356 local pwd2="b"
1332 local maxtry=15 1357 local maxtry=15
1333 1358
1334 if [ -z "${MYSQL_ROOT_PASSWORD}" -a -f "${EROOT}/root/.my.cnf" ]; then 1359 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
1335 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
1336 fi 1380 fi
1337 1381
1338 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then 1382 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
1339 ewarn "You have already a MySQL database in place." 1383 ewarn "You have already a MySQL database in place."
1340 ewarn "(${ROOT}/${MY_DATADIR}/*)" 1384 ewarn "(${ROOT}/${MY_DATADIR}/*)"
1361 fi 1405 fi
1362 MYSQL_ROOT_PASSWORD="${pwd1}" 1406 MYSQL_ROOT_PASSWORD="${pwd1}"
1363 unset pwd1 pwd2 1407 unset pwd1 pwd2
1364 fi 1408 fi
1365 1409
1366 local options="" 1410 local options="--log-warnings=0"
1367 local sqltmp="$(emktemp)" 1411 local sqltmp="$(emktemp)"
1368 1412
1369 local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql" 1413 local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql"
1370 [[ -r "${help_tables}" ]] \ 1414 [[ -r "${help_tables}" ]] \
1371 && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \ 1415 && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \
1372 || touch "${TMPDIR}/fill_help_tables.sql" 1416 || touch "${TMPDIR}/fill_help_tables.sql"
1373 help_tables="${TMPDIR}/fill_help_tables.sql" 1417 help_tables="${TMPDIR}/fill_help_tables.sql"
1374 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
1375 pushd "${TMPDIR}" &>/dev/null 1435 pushd "${TMPDIR}" &>/dev/null
1376 "${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
1377 if [ $? -ne 0 ]; then 1443 if [ $? -ne 0 ]; then
1378 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
1379 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"
1380 fi 1446 fi
1381 popd &>/dev/null 1447 popd &>/dev/null
1382 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \ 1448 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
1383 || die "MySQL databases not installed" 1449 || die "MySQL databases not installed"
1384 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null 1450 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null
1385 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null 1451 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null
1386 1452
1387 # Figure out which options we need to disable to do the setup
1388 helpfile="${TMPDIR}/mysqld-help"
1389 ${EROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null
1390 for opt in grant-tables host-cache name-resolve networking slave-start bdb \
1391 federated innodb ssl log-bin relay-log slow-query-log external-locking \
1392 ndbcluster \
1393 ; do
1394 optexp="--(skip-)?${opt}" optfull="--skip-${opt}"
1395 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
1396 done
1397 # But some options changed names
1398 egrep -sq external-locking "${helpfile}" && \
1399 options="${options/skip-locking/skip-external-locking}"
1400
1401 if mysql_version_is_at_least "4.1.3" ; then 1453 if mysql_version_is_at_least "4.1.3" ; then
1402 # Filling timezones, see 1454 # Filling timezones, see
1403 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html 1455 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
1404 "${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
1405 1457
1408 fi 1460 fi
1409 fi 1461 fi
1410 1462
1411 einfo "Creating the mysql database and setting proper" 1463 einfo "Creating the mysql database and setting proper"
1412 einfo "permissions on it ..." 1464 einfo "permissions on it ..."
1413
1414 use prefix || options="${options} --user=mysql"
1415 1465
1416 local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock" 1466 local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
1417 local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid" 1467 local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
1418 local mysqld="${EROOT}/usr/sbin/mysqld \ 1468 local mysqld="${EROOT}/usr/sbin/mysqld \
1419 ${options} \ 1469 ${options} \
1420 --user=mysql \ 1470 --user=mysql \
1471 --log-warnings=0 \
1421 --basedir=${EROOT}/usr \ 1472 --basedir=${EROOT}/usr \
1422 --datadir=${ROOT}/${MY_DATADIR} \ 1473 --datadir=${ROOT}/${MY_DATADIR} \
1423 --max_allowed_packet=8M \ 1474 --max_allowed_packet=8M \
1424 --net_buffer_length=16K \ 1475 --net_buffer_length=16K \
1425 --default-storage-engine=MyISAM \ 1476 --default-storage-engine=MyISAM \
1426 --socket=${socket} \ 1477 --socket=${socket} \
1427 --pid-file=${pidfile}" 1478 --pid-file=${pidfile}"
1428 #einfo "About to start mysqld: ${mysqld}" 1479 #einfo "About to start mysqld: ${mysqld}"
1429 ebegin "Starting mysqld" 1480 ebegin "Starting mysqld"
1481 einfo "Command ${mysqld}"
1430 ${mysqld} & 1482 ${mysqld} &
1431 rc=$? 1483 rc=$?
1432 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do 1484 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
1433 maxtry=$((${maxtry}-1)) 1485 maxtry=$((${maxtry}-1))
1434 echo -n "." 1486 echo -n "."
1452 ebegin "Loading \"zoneinfo\", this step may require a few seconds ..." 1504 ebegin "Loading \"zoneinfo\", this step may require a few seconds ..."
1453 "${EROOT}/usr/bin/mysql" \ 1505 "${EROOT}/usr/bin/mysql" \
1454 --socket=${socket} \ 1506 --socket=${socket} \
1455 -hlocalhost \ 1507 -hlocalhost \
1456 -uroot \ 1508 -uroot \
1457 -p"${MYSQL_ROOT_PASSWORD}" \ 1509 --password="${MYSQL_ROOT_PASSWORD}" \
1458 mysql < "${sqltmp}" 1510 mysql < "${sqltmp}"
1459 rc=$? 1511 rc=$?
1460 eend $? 1512 eend $?
1461 [ $rc -ne 0 ] && ewarn "Failed to load zoneinfo!" 1513 [ $rc -ne 0 ] && ewarn "Failed to load zoneinfo!"
1462 1514

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

  ViewVC Help
Powered by ViewVC 1.1.20