Skip to content

Commit

Permalink
Merge 10.10 into 10.11
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-m committed May 11, 2023
2 parents 45a879f + 616ced8 commit 1916bf2
Show file tree
Hide file tree
Showing 15 changed files with 343 additions and 178 deletions.
2 changes: 1 addition & 1 deletion debian/mariadb-common.postinst
Expand Up @@ -35,7 +35,7 @@ case "$1" in
then
update-alternatives --install /etc/mysql/my.cnf my.cnf "/etc/mysql/mariadb.cnf" 500 || true
fi
;;
;;
esac

#DEBHELPER#
2 changes: 1 addition & 1 deletion debian/mariadb-common.postrm
Expand Up @@ -10,7 +10,7 @@ case "$1" in
then
/usr/share/mysql-common/configure-symlinks remove mariadb "/etc/mysql/mariadb.cnf"
fi
;;
;;
esac

#DEBHELPER#
139 changes: 87 additions & 52 deletions debian/mariadb-server.postinst
@@ -1,9 +1,15 @@
#!/bin/bash
set -e

# shellcheck source=/dev/null
. /usr/share/debconf/confmodule

if [ -n "$DEBIAN_SCRIPT_DEBUG" ]; then set -v -x; DEBIAN_SCRIPT_TRACE=1; fi
if [ -n "$DEBIAN_SCRIPT_DEBUG" ]
then
set -v -x
DEBIAN_SCRIPT_TRACE=1
fi

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

export PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin
Expand All @@ -21,7 +27,9 @@ case "$1" in
# and because changed configuration options should take effect immediately.
# In case the server wasn't running at all it should be ok if the stop
# script fails. I can't tell at this point because of the cleaned /run.
set +e; invoke-rc.d mariadb stop; set -e
set +e
invoke-rc.d mariadb stop
set -e

# An existing /etc/init.d/mysql might be on the system if there was a
# previous MySQL or MariaDB installation, since /etc/init.d files are
Expand Down Expand Up @@ -61,21 +69,26 @@ case "$1" in
# 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.
for dir in DATADIR LOGDIR; do
for dir in DATADIR LOGDIR
do

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

savelink="$mysql_upgradedir/$dir.link"
if [ -L "$savelink" ]; then
if [ -L "$savelink" ]
then
# If the targetdir was a symlink before we upgraded it is supposed
# to be either still be present or not existing anymore now.
if [ -L "$targetdir" ]; then
if [ -L "$targetdir" ]
then
rm "$savelink"
elif [ ! -d "$targetdir" ]; then
elif [ ! -d "$targetdir" ]
then
mv "$savelink" "$targetdir"
else
# this should never even happen, but just in case...
Expand All @@ -97,7 +110,7 @@ this all away.
EOF
fi
fi
rmdir $mysql_upgradedir 2>/dev/null || true
rmdir $mysql_upgradedir 2>/dev/null || true

done

Expand All @@ -109,17 +122,29 @@ 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 ]; 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
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" ]
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" ]; then mkdir -Z "$mysql_statedir"; fi
if [ ! -d "$mysql_datadir" ] && [ ! -L "$mysql_datadir" ]; then mkdir -Z "$mysql_datadir" ; fi
if [ ! -d "$mysql_logdir" ] && [ ! -L "$mysql_logdir" ]; then mkdir -Z "$mysql_logdir" ; fi
if [ ! -d "$mysql_statedir" ] && [ ! -L "$mysql_statedir" ]
then
mkdir -Z "$mysql_statedir"
fi
if [ ! -d "$mysql_datadir" ] && [ ! -L "$mysql_datadir" ]
then
mkdir -Z "$mysql_datadir"
fi
if [ ! -d "$mysql_logdir" ] && [ ! -L "$mysql_logdir" ]
then
mkdir -Z "$mysql_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
Expand Down Expand Up @@ -168,8 +193,8 @@ EOF
# Debian: can safely run on upgrades with existing databases
set +e
bash /usr/bin/mariadb-install-db --rpm --cross-bootstrap --user=mysql \
--disable-log-bin --skip-test-db 2>&1 | \
$ERR_LOGGER
--disable-log-bin --skip-test-db 2>&1 | \
$ERR_LOGGER
set -e

# On new installations root user can connect via unix_socket.
Expand All @@ -180,26 +205,30 @@ 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" ]; then
dc="$mysql_cfgdir/debian.cnf"
if [ ! -d "$mysql_cfgdir" ]
then
install -o 0 -g 0 -m 0755 -d $mysql_cfgdir
fi
if [ ! -e "$dc" ]; then
cat /dev/null > $dc
echo "# THIS FILE IS OBSOLETE. STOP USING IT IF POSSIBLE." >>$dc
echo "# This file exists only for backwards compatibility for" >>$dc
echo "# tools that run '--defaults-file=/etc/mysql/debian.cnf'" >>$dc
echo "# and have root level access to the local filesystem." >>$dc
echo "# With those permissions one can run 'mariadb' directly" >>$dc
echo "# anyway thanks to unix socket authentication and hence" >>$dc
echo "# this file is useless. See package README for more info." >>$dc
echo "[client]" >>$dc
echo "host = localhost" >>$dc
echo "user = root" >>$dc
echo "[mysql_upgrade]" >>$dc
echo "host = localhost" >>$dc
echo "user = root" >>$dc
echo "# THIS FILE WILL BE REMOVED IN A FUTURE DEBIAN RELEASE." >>$dc
if [ ! -e "$dc" ]
then
cat /dev/null > $dc
{
echo "# THIS FILE IS OBSOLETE. STOP USING IT IF POSSIBLE.";
echo "# This file exists only for backwards compatibility for";
echo "# tools that run '--defaults-file=/etc/mysql/debian.cnf'";
echo "# and have root level access to the local filesystem.";
echo "# With those permissions one can run 'mariadb' directly";
echo "# anyway thanks to unix socket authentication and hence";
echo "# this file is useless. See package README for more info.";
echo "[client]";
echo "host = localhost";
echo "user = root";
echo "[mysql_upgrade]";
echo "host = localhost";
echo "user = root";
echo "# THIS FILE WILL BE REMOVED IN A FUTURE DEBIAN RELEASE.";
} >> $dc
fi
# Keep it only root-readable, as it always was
chown 0:0 $dc
Expand All @@ -212,8 +241,10 @@ EOF
# on by default) to work both to disable a default profile, and to keep
# any profile installed and maintained by users themselves.
profile="/etc/apparmor.d/usr.sbin.mariadbd"
if [ -f "$profile" ] && aa-status --enabled 2>/dev/null; then
if grep -q /usr/sbin/mariadbd "$profile" 2>/dev/null ; then
if [ -f "$profile" ] && aa-status --enabled 2>/dev/null
then
if grep -q /usr/sbin/mariadbd "$profile" 2>/dev/null
then
apparmor_parser -r "$profile" || true
else
echo "/usr/sbin/mariadbd { }" | apparmor_parser --remove 2>/dev/null || true
Expand All @@ -232,24 +263,24 @@ EOF
# Note that file cannot be empty, otherwise systemd version in Ubuntu Bionic
# will think the service is masked
echo "# empty placeholder" > /etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf

;;
;;

abort-upgrade|abort-remove|abort-configure)
;;
;;

triggered)
if [ -d /run/systemd/system ]; then
if [ -d /run/systemd/system ]
then
systemctl --system daemon-reload
else
invoke-rc.d mariadb restart
fi
;;
;;

*)
echo "postinst called with unknown argument '$1'" 1>&2
exit 1
;;
;;
esac

db_stop # in case invoke fails
Expand All @@ -259,19 +290,23 @@ db_stop # in case invoke fails
# systemctl. If we upgrade from MySQL mysql.service may be masked, which also
# means init.d script is disabled. Unmask mysql service explicitly.
# Check first that the command exists, to avoid emitting any warning messages.
if [ -x "$(command -v deb-systemd-helper)" ]; then
if [ -x "$(command -v deb-systemd-helper)" ]
then
deb-systemd-helper unmask mysql.service > /dev/null
fi

#DEBHELPER#

# Modified dh_systemd_start snippet that's not added automatically
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
deb-systemd-invoke start mariadb.service >/dev/null || true
# Modified dh_installinit snippet to only run with sysvinit
elif [ -x "/etc/init.d/mariadb" ]; then
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]; then
invoke-rc.d mariadb start || exit $?
fi
if [ -d /run/systemd/system ]
then
systemctl --system daemon-reload >/dev/null || true
deb-systemd-invoke start mariadb.service >/dev/null || true
# Modified dh_installinit snippet to only run with sysvinit
elif [ -x "/etc/init.d/mariadb" ]
then
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]
then
invoke-rc.d mariadb start || exit $?
fi
fi
68 changes: 41 additions & 27 deletions debian/mariadb-server.postrm
@@ -1,9 +1,15 @@
#!/bin/bash
set -e

# shellcheck source=/dev/null
. /usr/share/debconf/confmodule

if [ -n "$DEBIAN_SCRIPT_DEBUG" ]; then set -v -x; DEBIAN_SCRIPT_TRACE=1; fi
if [ -n "$DEBIAN_SCRIPT_DEBUG" ]
then
set -v -x
DEBIAN_SCRIPT_TRACE=1
fi

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

MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
Expand All @@ -12,54 +18,61 @@ MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
# do it himself. No database directories should be removed while the server
# is running! Another mariadbd in e.g. a different chroot is fine for us.
stop_server() {
# Return immediately if there are no mysqld processes running
# as there is no point in trying to shutdown in that case.
if ! pgrep -x --nslist pid --ns $$ "mysqld|mariadbd" > /dev/null; then return; fi
# Return immediately if there are no mysqld processes running
# as there is no point in trying to shutdown in that case.
if ! pgrep -x --nslist pid --ns $$ "mysqld|mariadbd" > /dev/null
then
return
fi

set +e
invoke-rc.d mariadb stop
invoke-rc.d mysql stop # Backwards compatibility
errno=$?
set -e
set +e
invoke-rc.d mariadb stop
invoke-rc.d mysql stop # Backwards compatibility
errno=$?
set -e

# systemctl could emit exit code 100=no init script (fresh install)
if [ "$errno" != 0 -a "$errno" != 100 ]; then
echo "Attempt to stop MariaDB/MySQL server returned exitcode $errno" 1>&2
echo "There is a MariaDB/MySQL server running, but we failed in our attempts to stop it." 1>&2
echo "Stop it yourself and try again!" 1>&2
db_stop
exit 1
fi
# systemctl could emit exit code 100=no init script (fresh install)
if [ "$errno" != 0 ] && [ "$errno" != 100 ]
then
echo "Attempt to stop MariaDB/MySQL server returned exitcode $errno" 1>&2
echo "There is a MariaDB/MySQL server running, but we failed in our attempts to stop it." 1>&2
echo "Stop it yourself and try again!" 1>&2
db_stop
exit 1
fi
}


case "$1" in
purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
if [ -n "`$MYADMIN ping 2>/dev/null`" ]; then
if [ -n "$($MYADMIN ping 2>/dev/null)" ]
then
stop_server
sleep 2
fi
;;
;;
*)
echo "postrm called with unknown argument '$1'" 1>&2
exit 1
;;
;;
esac

#
# - 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" ]; then
if [ "$1" = "purge" ] && [ -f "/var/lib/mysql/debian-__MARIADB_MAJOR_VER__.flag" ]
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

db_input high "mariadb-server/postrm_remove_databases" || true
db_go || true
db_get "mariadb-server/postrm_remove_databases" || true
if [ "$RET" = "true" ]; then
if [ "$RET" = "true" ]
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
Expand All @@ -72,9 +85,9 @@ if [ "$1" = "purge" ] && [ -f "/var/lib/mysql/debian-__MARIADB_MAJOR_VER__.flag"
if [ -d /var/lib/mysql ]
then
find /var/lib/mysql -mindepth 1 \
-not -path '*/lost+found/*' -not -name 'lost+found' \
-not -path '*/lost@002bfound/*' -not -name 'lost@002bfound' \
-delete
-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
Expand All @@ -89,6 +102,7 @@ fi
#DEBHELPER#

# Modified dh_systemd_start snippet that's not added automatically
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
if [ -d /run/systemd/system ]
then
systemctl --system daemon-reload >/dev/null || true
fi

0 comments on commit 1916bf2

Please sign in to comment.