Skip to content

Commit

Permalink
MDEV-33750: Rename mysql to mariadb in Debian directory
Browse files Browse the repository at this point in the history
Take a change and rename '$mysql_'-variable to '$mariadb_'-variable
in server postinst and preinst as we are MariaDB.

Make sure that we are using mariadbd-safe not mysqld_safe.
  • Loading branch information
illuusio committed Apr 17, 2024
1 parent ccbacfd commit 6fe07c0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 60 deletions.
4 changes: 2 additions & 2 deletions debian/mariadb-server.mariadb.init
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Default-Stop: 0 1 6
# Short-Description: Start and stop the MariaDB database server daemon
# Description: Controls the main MariaDB database server daemon "mariadbd"
# and its wrapper script "mysqld_safe".
# and its wrapper script "mariadbd-safe".
### END INIT INFO
#
set -e
Expand Down Expand Up @@ -206,7 +206,7 @@ case "${1:-''}" in
else
ERROR_LOG_FILE="$(mktemp).err"
echo # ensure newline
timeout --kill-after=20 10 /usr/bin/mysqld_safe "${@:2}" --log-error="$ERROR_LOG_FILE"
timeout --kill-after=20 10 /usr/bin/mariadbd-safe "${@:2}" --log-error="$ERROR_LOG_FILE"
echo "Running '/etc/init.d/mariadb start' failed with error log:"
cat "$ERROR_LOG_FILE"
fi
Expand Down
70 changes: 35 additions & 35 deletions debian/mariadb-server.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ case "$1" in
fi
fi

mysql_statedir=/usr/share/mysql
mysql_datadir=/var/lib/mysql
mysql_logdir=/var/log/mysql
mysql_cfgdir=/etc/mysql
mysql_upgradedir=/var/lib/mysql-upgrade
mariadb_statedir=/usr/share/mysql
mariadb_datadir=/var/lib/mysql
mariadb_logdir=/var/log/mysql
mariadb_cfgdir=/etc/mysql
mariadb_upgradedir=/var/lib/mysql-upgrade

# 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
Expand All @@ -74,12 +74,12 @@ case "$1" in

if [ "$dir" = "DATADIR" ]
then
targetdir=$mysql_datadir
targetdir=$mariadb_datadir
else
targetdir=$mysql_logdir
targetdir=$mariadb_logdir
fi

savelink="$mysql_upgradedir/$dir.link"
savelink="$mariadb_upgradedir/$dir.link"
if [ -L "$savelink" ]
then
# If the targetdir was a symlink before we upgraded it is supposed
Expand All @@ -92,10 +92,10 @@ case "$1" in
mv "$savelink" "$targetdir"
else
# this should never even happen, but just in case...
mysql_tmp=$(mktemp -d -t mysql-symlink-restore-XXXXXX)
echo "this is very strange! see $mysql_tmp/README..." >&2
mv "$targetdir" "$mysql_tmp"
cat << EOF > "$mysql_tmp/README"
mariadb_tmp=$(mktemp -d -t mysql-symlink-restore-XXXXXX)
echo "this is very strange! see $mariadb_tmp/README..." >&2
mv "$targetdir" "$mariadb_tmp"
cat << EOF > "$mariadb_tmp/README"
If you're reading this, it's most likely because you had replaced /var/lib/mysql
with a symlink, then upgraded to a new version of mysql, and then dpkg
Expand All @@ -110,7 +110,7 @@ this all away.
EOF
fi
fi
rmdir $mysql_upgradedir 2>/dev/null || true
rmdir $mariadb_upgradedir 2>/dev/null || true

done # end 'for dir' loop

Expand All @@ -122,38 +122,38 @@ EOF
# This direct update is needed to enable an authentication mechanism to
# perform mariadb-upgrade, (MDEV-22678). To keep the impact minimal, we
# skip innodb and set key-buffer-size to 0 as it isn't reused.
if [ -f "$mysql_datadir/auto.cnf" ] &&
[ -f "$mysql_datadir/mysql/user.MYD" ] &&
! lsof -nt "$mysql_datadir"/mysql/user.MYD > /dev/null &&
[ ! -f "$mysql_datadir/undo_001" ]
if [ -f "$mariadb_datadir/auto.cnf" ] &&
[ -f "$mariadb_datadir/mysql/user.MYD" ] &&
! lsof -nt "$mariadb_datadir"/mysql/user.MYD > /dev/null &&
[ ! -f "$mariadb_datadir/undo_001" ]
then
echo "UPDATE mysql.user SET plugin='unix_socket' WHERE plugin='auth_socket';" | \
mariadbd --skip-innodb --key_buffer_size=0 --default-storage-engine=MyISAM --bootstrap 2> /dev/null
fi

# Ensure the existence and right permissions for the database and
# log files. Use mkdir option 'Z' to create with correct SELinux context.
if [ ! -d "$mysql_statedir" ] && [ ! -L "$mysql_statedir" ]
if [ ! -d "$mariadb_statedir" ] && [ ! -L "$mariadb_statedir" ]
then
mkdir -Z "$mysql_statedir"
mkdir -Z "$mariadb_statedir"
fi
if [ ! -d "$mysql_datadir" ] && [ ! -L "$mysql_datadir" ]
if [ ! -d "$mariadb_datadir" ] && [ ! -L "$mariadb_datadir" ]
then
mkdir -Z "$mysql_datadir"
mkdir -Z "$mariadb_datadir"
fi
if [ ! -d "$mysql_logdir" ] && [ ! -L "$mysql_logdir" ]
if [ ! -d "$mariadb_logdir" ] && [ ! -L "$mariadb_logdir" ]
then
mkdir -Z "$mysql_logdir"
mkdir -Z "$mariadb_logdir"
fi
# When creating an ext3 jounal on an already mounted filesystem like e.g.
# /var/lib/mysql, you get a .journal file that is not modifiable by chown.
# The mysql_statedir must not be writable by the mysql user under any
# The mariadb_statedir must not be writable by the mysql user under any
# circumstances as it contains scripts that are executed by root.
set +e
find $mysql_statedir ! -uid 0 -print0 -or ! -gid 0 -print0 | xargs -0 -r sudo chown 0:0
find $mysql_datadir ! -uid "$(id -u mysql)" -print0 | xargs -0 -r chown mysql
chown -R mysql:adm $mysql_logdir
chmod 2750 $mysql_logdir
find $mariadb_statedir ! -uid 0 -print0 -or ! -gid 0 -print0 | xargs -0 -r sudo chown 0:0
find $mariadb_datadir ! -uid "$(id -u mysql)" -print0 | xargs -0 -r chown mysql
chown -R mysql:adm $mariadb_logdir
chmod 2750 $mariadb_logdir
set -e

## Set the correct filesystem ownership for the PAM v2 plugin
Expand Down Expand Up @@ -181,11 +181,11 @@ EOF
db_set mariadb-server/postrm_remove_database false || true

# Clean up old flags before setting new one
rm -f $mysql_datadir/debian-*.flag
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
# @TODO: Rewrite this to use the new upstream /var/lib/mariadb_upgrade_info file
# instead of the legacy /var/lib/debian-XX.X.flag file
touch "$mysql_datadir/debian-__MARIADB_MAJOR_VER__.flag"
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 @@ -211,10 +211,10 @@ EOF
# --defaults-file option for tools (for the sake of upgrades)
# and thus need /etc/mysql/debian.cnf to exist, even if it's empty.
# In the long run the goal is to obsolete this file.
dc="$mysql_cfgdir/debian.cnf"
if [ ! -d "$mysql_cfgdir" ]
dc="$mariadb_cfgdir/debian.cnf"
if [ ! -d "$mariadb_cfgdir" ]
then
install -o 0 -g 0 -m 0755 -d $mysql_cfgdir
install -o 0 -g 0 -m 0755 -d $mariadb_cfgdir
fi

if [ ! -e "$dc" ]
Expand All @@ -231,7 +231,7 @@ EOF
echo "[client]";
echo "host = localhost";
echo "user = root";
echo "[mysql_upgrade]";
echo "[mariadb_upgrade]";
echo "host = localhost";
echo "user = root";
echo "# THIS FILE WILL BE REMOVED IN A FUTURE DEBIAN RELEASE.";
Expand Down
44 changes: 22 additions & 22 deletions debian/mariadb-server.preinst
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ fi
${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 }

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

MARIADBD_USERS="root"

Expand Down Expand Up @@ -67,21 +67,21 @@ stop_server() {

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

# @TODO: Rewrite this to use the new upstream /var/lib/mysql_upgrade_info file
# @TODO: Rewrite this to use the new upstream /var/lib/mariadb_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 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 "$mysql_datadir"/debian-*.flag
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" = "$mysql_datadir/debian-*.flag" ]
if [ "$flag" = "$mariadb_datadir/debian-*.flag" ]
then
break
fi
Expand Down Expand Up @@ -119,13 +119,13 @@ 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 "$mysql_datadir/undo_001" ]
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 "$mysql_datadir: found previous version $found_version"
echo "$mariadb_datadir: found previous version $found_version"

if dpkg --compare-versions "$found_version" '>>' "$this_version"
then
Expand All @@ -145,10 +145,10 @@ fi
# installs), then that file is enough of additional indication to trigger the
# move of the data directory.
if [ -z "$found_version" ] &&
[ -z "$(find $mysql_datadir/debian-*.flag 2> /dev/null)" ] &&
[ -f "$mysql_datadir/undo_001" ]
[ -z "$(find $mariadb_datadir/debian-*.flag 2> /dev/null)" ] &&
[ -f "$mariadb_datadir/undo_001" ]
then
echo "$mysql_datadir: no server version flag found, assuming MySQL 8.0 data encountered"
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
Expand All @@ -159,12 +159,12 @@ if [ -n "$downgrade_detected" ]
then
db_input critical "mariadb-server/old_data_directory_saved" || true
db_go
echo "The file $mysql_datadir/debian-$found_version.flag indicates a" 1>&2
echo "The file $mariadb_datadir/debian-$found_version.flag indicates a" 1>&2
echo "version that cannot automatically be upgraded. Therefore the" 1>&2
echo "previous data directory will be renamed to $mysql_datadir-$found_version and" 1>&2
echo "a new data directory will be initialized at $mysql_datadir." 1>&2
echo "previous data directory will be renamed to $mariadb_datadir-$found_version and" 1>&2
echo "a new data directory will be initialized at $mariadb_datadir." 1>&2
echo "Please manually export/import your data (e.g. with mysqldump) if needed." 1>&2
mv -f "$mysql_datadir" "$mysql_datadir-$found_version"
mv -f "$mariadb_datadir" "$mariadb_datadir-$found_version"
# Also move away the old debian.cnf file that included credentials that are
# no longer valid. If none existed, ignore error and let dpkg continue.
mv -f /etc/mysql/debian.cnf "/etc/mysql/debian.cnf-$found_version" || true
Expand Down Expand Up @@ -224,24 +224,24 @@ do
if [ -L "$checkdir" ]
then
# Use mkdir option 'Z' to create with correct SELinux context.
mkdir -pZ "$mysql_upgradedir"
cp -dT "$checkdir" "$mysql_upgradedir/$dir.link"
mkdir -pZ "$mariadb_upgradedir"
cp -dT "$checkdir" "$mariadb_upgradedir/$dir.link"
fi
done

# creating mysql home directory
if [ ! -d $mysql_datadir ] && [ ! -L $mysql_datadir ]
if [ ! -d $mariadb_datadir ] && [ ! -L $mariadb_datadir ]
then
# Use mkdir option 'Z' to create with correct SELinux context.
mkdir -Z $mysql_datadir
mkdir -Z $mariadb_datadir
fi

# As preset blocksize of GNU df is 1024 then available bytes is $df_available_blocks * 1024
# 4096 blocks is then lower than 4 MB
df_available_blocks="$(LC_ALL=C BLOCKSIZE='' df --output=avail "$mysql_datadir" | tail -n 1)"
df_available_blocks="$(LC_ALL=C BLOCKSIZE='' df --output=avail "$mariadb_datadir" | tail -n 1)"
if [ "$df_available_blocks" -lt "4096" ]
then
echo "ERROR: There's not enough space in $mysql_datadir/" 1>&2
echo "ERROR: There's not enough space in $mariadb_datadir/" 1>&2
db_stop
exit 1
fi
Expand All @@ -254,8 +254,8 @@ fi
# The "set +e" is necessary as e.g. a ".journal" of a ext3 partition is
# not chgrp'able (#318435).
set +e
find $mysql_datadir ! -uid "$(id -u mysql)" -print0 | xargs -0 -r chown mysql
find $mysql_datadir -follow -not -group mysql -print0 2>/dev/null \
find $mariadb_datadir ! -uid "$(id -u mysql)" -print0 | xargs -0 -r chown mysql
find $mariadb_datadir -follow -not -group mysql -print0 2>/dev/null \
| xargs -0 --no-run-if-empty chgrp mysql
set -e

Expand Down
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ 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
# @TODO: Rewrite this to use the new upstream /var/lib/mariadb_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

Expand Down

0 comments on commit 6fe07c0

Please sign in to comment.