Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/install_layout.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ SET(INSTALL_MYSQLTESTDIR_DEB "share/mariadb/mariadb-test")
SET(INSTALL_SQLBENCHDIR_DEB ".")
SET(INSTALL_SUPPORTFILESDIR_DEB "share/mariadb")
#
SET(INSTALL_MYSQLDATADIR_DEB "/var/lib/mysql")
SET(INSTALL_MYSQLDATADIR_DEB "/var/lib/mariadb")

SET(INSTALL_RUNDATADIR_DEB "/run/mysqld")
SET(INSTALL_UNIX_ADDRDIR_DEB "${INSTALL_RUNDATADIR_DEB}/mysqld.sock")
Expand Down
2 changes: 1 addition & 1 deletion debian/additions/mariadb.conf.d/50-server.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#user = mysql
pid-file = /run/mysqld/mysqld.pid
basedir = /usr
#datadir = /var/lib/mysql
#datadir = /var/lib/mariadb # Starting with MariaDB 1:11.8.6-5, /var/lib/mariadb is used by default for better MySQL co-installability in Debian/Ubuntu.
#tmpdir = /tmp

# Broken reverse DNS slows down connections considerably and name resolve is
Expand Down
4 changes: 4 additions & 0 deletions debian/additions/source_mariadb.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def add_info(report):
_add_my_conf_files(report, os.path.join('/etc/mysql/conf.d', f))
for f in os.listdir('/etc/mysql/mariadb.conf.d'):
_add_my_conf_files(report, os.path.join('/etc/mysql/mariadb.conf.d', f))
try:
report['MariaDBVarLibDirListing'] = str(os.listdir('/var/lib/mariadb'))
except OSError:
report['MariaDBVarLibDirListing'] = str(False)
try:
report['MySQLVarLibDirListing'] = str(os.listdir('/var/lib/mysql'))
except OSError:
Expand Down
2 changes: 1 addition & 1 deletion debian/mariadb-server.mariadb.init
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ sanity_checks() {
# and this should fall back to a sane default value
if [ -z "$datadir" ]
then
datadir="/var/lib/mysql"
datadir="/var/lib/mariadb"
fi

# Verify the datadir location exists
Expand Down
28 changes: 22 additions & 6 deletions debian/mariadb-server.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,30 @@ case "$1" in
fi

mariadb_statedir=/usr/share/mariadb
mariadb_datadir=/var/lib/mysql
mariadb_datadir=/var/lib/mariadb
legacy_mariadb_datadir=/var/lib/mysql
mariadb_logdir=/var/log/mysql
mariadb_cfgdir=/etc/mysql
mariadb_upgradedir=/var/lib/mysql-upgrade

# If new mariadb data directory does not exist, assume we are continuing
# to use the legacy directory. Add a config entry to override datadir's
# value back to the original.
if [ ! -d "$mariadb_datadir" ]
then
mariadb_datadir="$legacy_mariadb_datadir"

mkdir -p /etc/mysql/mariadb.conf.d

{
echo "# Override the data directory config to continue using the legacy directory."
echo "[mariadbd]"
echo "datadir = $legacy_mariadb_datadir"
} > /etc/mysql/mariadb.conf.d/99-legacy-datadir.cnf

echo "Created /etc/mysql/mariadb.conf.d/99-legacy-datadir.cnf for MariaDB to continue using /var/lib/mysql on upgrade."
fi

# If the following symlink exists, it is a preserved copy the old data dir
# created by the preinst script during a upgrade that would have otherwise
# been replaced by an empty mysql dir. This should restore it.
Expand Down Expand Up @@ -181,12 +200,8 @@ EOF
# data directory and then somehow gets purged by the admin.
db_set mariadb-server/postrm_remove_database false || true

# Clean up old flags before setting new one
# Clean up old debian version flag files
rm -f $mariadb_datadir/debian-*.flag
# Flag data dir to avoid downgrades
# @TODO: Rewrite this to use the new upstream /var/lib/mysql_upgrade_info file
# instead of the legacy /var/lib/debian-XX.X.flag file
touch "$mariadb_datadir/debian-__MARIADB_MAJOR_VER__.flag"

# initiate databases. Output is not allowed by debconf :-(
# This will fail if we are upgrading an existing database; in this case
Expand All @@ -198,6 +213,7 @@ EOF
# working with libpam-tmpdir (by setting TMPDIR to empty value).
set +e
TMPDIR='' bash /usr/bin/mariadb-install-db \
--datadir="$mariadb_datadir" \
--rpm --cross-bootstrap \
--user=mysql --disable-log-bin \
--skip-test-db 2>&1 | \
Expand Down
97 changes: 86 additions & 11 deletions debian/mariadb-server.postrm
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,70 @@ fi

${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 }

mariadb_datadir=/var/lib/mariadb
legacy_mariadb_datadir=/var/lib/mysql

# Check if the version file mariadb_upgrade_info or mysql_upgrade_info is
# included with the provided data directory. If it is a MariaDB version, then
# return the major version number only (XX.XX). Return empty if this directory
# does not belong to MariaDB.
get_mariadb_upgrade_info_major_version() {
datadir="$1"

# Check both mariadb_upgrade_info (higher priority) and mysql_upgrade_info.
if [ -f "$datadir/mysql_upgrade_info" ]
then
read -r full_version < "$datadir/mysql_upgrade_info"
fi

if [ -f "$datadir/mariadb_upgrade_info" ]
then
read -r full_version < "$datadir/mariadb_upgrade_info"
fi

# If version is not empty and contains 'MariaDB', get the version number.
if [ -n "$full_version" ] && echo "$full_version" | grep -q "MariaDB"
then
# The major version number should the first two components of the version
# string (e.g. 11.8 from 11.8.6).
echo "$full_version" | awk -F'.' '{print $1"."$2}'
fi
}

#
# - Purge logs and data only if they are ours (#307473)
# - Remove the mysql user only after all his owned files are purged.
# - Cleanup the initscripts only if this was the last provider of them
#
if [ "$1" = "purge" ] && [ -f "/var/lib/mysql/debian-__MARIADB_MAJOR_VER__.flag" ]
if [ "$1" = "purge" ]
then
# we remove the mysql user only after all his owned files are purged
rm -f /var/log/mysql.{log,err}{,.0,.[1234567].gz}
rm -rf /var/log/mysql
rm -f /etc/mysql/mariadb.conf.d/99-legacy-datadir.cnf

# Mark data directories for removal if they match the current MariaDB version.
remove_mariadb_datadir="false"
remove_legacy_mariadb_datadir="false"

mariadb_datadir_version=$(get_mariadb_upgrade_info_major_version "$mariadb_datadir")

if [ "$mariadb_datadir_version" = "__MARIADB_MAJOR_VER__" ]
then
remove_mariadb_datadir="true"
fi

legacy_mariadb_datadir_version=$(get_mariadb_upgrade_info_major_version "$legacy_mariadb_datadir")

if [ "$legacy_mariadb_datadir_version" = "__MARIADB_MAJOR_VER__" ]
then
remove_legacy_mariadb_datadir="true"
fi

# Remove logs in /var/log/mysql only if they are ours.
# These must be removed before mysql user is removed.
if [ "$remove_mariadb_datadir" = "true" ] || [ "$remove_legacy_mariadb_datadir" = "true" ]
then
rm -f /var/log/mysql.{log,err}{,.0,.[1234567].gz}
rm -rf /var/log/mysql
fi

db_input high "mariadb-server/postrm_remove_databases" || true
db_go || true
Expand All @@ -30,26 +84,47 @@ then
then
# never remove the debian.cnf when the databases are still existing
# else we ran into big trouble on the next install!
rm -f /etc/mysql/debian.cnf
# Remove all contents from /var/lib/mysql except if it's a
if [ "$remove_mariadb_datadir" = "true" ] || [ "$remove_legacy_mariadb_datadir" = "true" ]
then
rm -f /etc/mysql/debian.cnf
fi
# Remove all contents from /var/lib/mariadb except if it's a
# directory with file system data. See #829491 for details and
# #608938 for potential mysql-server leftovers which erroneously
# had been renamed.
# Attempt removal only if the directory hasn't already been removed
# by dpkg to avoid failing on "No such file or directory" errors.
if [ -d /var/lib/mysql ]
if [ "$remove_mariadb_datadir" = "true" ]
then
find /var/lib/mysql -mindepth 1 \
find "$mariadb_datadir" -mindepth 1 \
-not -path '*/lost+found/*' -not -name 'lost+found' \
-not -path '*/lost@002bfound/*' -not -name 'lost@002bfound' \
-delete

# "|| true" still needed as rmdir still exits with non-zero if
# /var/lib/mariadb is a mount point
rmdir --ignore-fail-on-non-empty "$mariadb_datadir" || true
fi
# Remove all contents from /var/lib/mysql if it's owned by us, with same
# checks as /var/lib/mariadb.
if [ "$remove_legacy_mariadb_datadir" = "true" ]
then
find "$legacy_mariadb_datadir" -mindepth 1 \
-not -path '*/lost+found/*' -not -name 'lost+found' \
-not -path '*/lost@002bfound/*' -not -name 'lost@002bfound' \
-delete

# "|| true" still needed as rmdir still exits with non-zero if
# /var/lib/mysql is a mount point
rmdir --ignore-fail-on-non-empty /var/lib/mysql || true
rmdir --ignore-fail-on-non-empty "$legacy_mariadb_datadir" || true
fi

# Remove /run/mysqld and mysql user if owned by us.
if [ "$remove_mariadb_datadir" = "true" ] || [ "$remove_legacy_mariadb_datadir" = "true" ]
then
rm -rf /run/mysqld # this directory is created by the init script, don't leave behind
userdel mysql || true
fi
rm -rf /run/mysqld # this directory is created by the init script, don't leave behind
userdel mysql || true
fi

fi
Expand Down
91 changes: 38 additions & 53 deletions debian/mariadb-server.preinst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ fi
${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 }

export PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin
mariadb_datadir=/var/lib/mysql
mariadb_datadir=/var/lib/mariadb
legacy_mariadb_datadir=/var/lib/mysql
mariadb_upgradedir=/var/lib/mysql-upgrade

MARIADBD_USERS="root"
Expand Down Expand Up @@ -67,46 +68,53 @@ stop_server() {
fi
}

################################ main() ##########################

# @TODO: Rewrite this to use the new upstream /var/lib/mysql_upgrade_info file
# instead of the legacy /var/lib/debian-XX.X.flag file
this_version=__MARIADB_MAJOR_VER__
max_upgradeable_version=5.7
# Check if the version file mariadb_upgrade_info or mysql_upgrade_info is
# included with the provided data directory. If it is a MariaDB version, then
# return the major version number only (XX.XX). Return empty if this directory
# does not belong to MariaDB.
get_mariadb_upgrade_info_major_version() {
datadir="$1"

# Check if a flag file is found that indicates a previous MariaDB or MySQL
# version was installed. If multiple flags are found, check which one was
# the biggest version number.
for flag in "$mariadb_datadir"/debian-*.flag
do

# The for loop leaves $flag as the query string if there are no results,
# so the check below is needed to stop further processing when there are
# no real results.
if [ "$flag" = "$mariadb_datadir/debian-*.flag" ]
# Check both mariadb_upgrade_info (higher priority) and mysql_upgrade_info.
if [ -f "$datadir/mysql_upgrade_info" ]
then
break
read -r full_version < "$datadir/mysql_upgrade_info"
fi

# The whole flag_version thing should be rewritten, so ignore minor Shellcheck
# nag for now
# shellcheck disable=SC2001
flag_version=$(echo "$flag" | sed 's/.*debian-\([0-9\.]\+\).flag/\1/')

# Initialize value if empty
if [ -z "$found_version" ]
if [ -f "$datadir/mariadb_upgrade_info" ]
then
found_version=$flag_version
read -r full_version < "$datadir/mariadb_upgrade_info"
fi

# Update value if now bigger then before
if dpkg --compare-versions "$flag_version" '>>' "$found_version"
# If version is not empty and contains 'MariaDB', get the version number.
if [ -n "$full_version" ] && echo "$full_version" | grep -q "MariaDB"
then
found_version=$flag_version
# The major version number should the first two components of the version
# string (e.g. 11.8 from 11.8.6).
echo "$full_version" | awk -F'.' '{print $1"."$2}'
fi
}

done
################################ main() ##########################

this_version=__MARIADB_MAJOR_VER__
max_upgradeable_version=5.7

# Check for previous mariadb version in the new datadir.
found_version=$(get_mariadb_upgrade_info_major_version "$mariadb_datadir")

# If nothing was found in the new datadir, check the legacy datadir to see if
# it has a MariaDB instance.
if [ -z "$found_version" ] && [ -d "$legacy_mariadb_datadir" ]
then
found_version=$(get_mariadb_upgrade_info_major_version "$legacy_mariadb_datadir")

# If a mariadb version was found in the legacy datadir, continue using it.
if [ -n "$found_version" ]
then
mariadb_datadir="$legacy_mariadb_datadir"
fi
fi

# If an upgrade is detected, proceed with it automatically without
# requiring any user interaction.
Expand All @@ -117,16 +125,6 @@ done
# than $max_upgradeable_version.
if [ -n "$found_version" ]
then

# MySQL 8.0 in Ubuntu has a bug in packaging and the file is name wrongly
# 'debian-5.7.flag', so in case '5.7' was encountered an extra check needs to
# be done to see is there is a file called undo_001, which is a sign of 8.0.
if [ "$found_version" == "5.7" ] && [ -f "$mariadb_datadir/undo_001" ]
then
# Seems to be a 8.0, flag has wrongly 5.7 (know bug)
found_version=8.0
fi

echo "$mariadb_datadir: found previous version $found_version"

if dpkg --compare-versions "$found_version" '>>' "$this_version"
Expand All @@ -142,19 +140,6 @@ then

fi

# If there is no debian-*.flag, and no version was detected, but a file that
# indicated MySQL 8.0 is found (undo_001 is created by default in MySQL 8.0+
# installs), then that file is enough of additional indication to trigger the
# move of the data directory.
if [ -z "$found_version" ] &&
[ -z "$(find $mariadb_datadir/debian-*.flag 2> /dev/null)" ] &&
[ -f "$mariadb_datadir/undo_001" ]
then
echo "$mariadb_datadir: no server version flag found, assuming MySQL 8.0 data encountered"
downgrade_detected=true
found_version="previous" # Just use dummy name as we don't know real version
fi

# Don't abort dpkg if downgrade is detected (as was done previously).
# Instead simply move the old datadir and create a new for this_version.
if [ -n "$downgrade_detected" ]
Expand Down
2 changes: 0 additions & 2 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ endif
# As packages does not have major version any more in package name there is no
# way as it not set by dpkg to use this on postinst script. Use sed to
# determine major version instead.
# @TODO: Rewrite this to use the new upstream /var/lib/mysql_upgrade_info file
# instead of the legacy /var/lib/debian-XX.X.flag file
sed -i 's/__MARIADB_MAJOR_VER__/$(DEB_VERSION_MAJOR)/g' debian/mariadb-server.post* debian/mariadb-server.preinst

# Don't build ColumnStore as part of the native build as it does not meet the
Expand Down
Loading