mariadb: Check and fix datadir owner issues during upgrade
authorMichal Hrusecky <michal.hrusecky@turris.com>
Thu, 13 Jan 2022 14:04:57 +0000 (15:04 +0100)
committerJosef Schlehofer <pepe.schlehofer@gmail.com>
Fri, 14 Jan 2022 15:28:29 +0000 (16:28 +0100)
If you are migrating to MariaDB package, you might have old datadir
stored somewhere using different setup with different users. If you
trust us enough to enable autoupgrade, you probably trust us enough to
chown your datadir as well. This can prevent some potential issues.

Signed-off-by: Michal Hrusecky <michal.hrusecky@turris.com>
(cherry picked from commit b41525cef4171c7f3200afc41dca5e3837cbd2ec)

utils/mariadb/Makefile
utils/mariadb/files/mysqld.init

index ac2307cd3285b8258c4b3f54e7120e2139f404db..1cfe943d06736e4d4f5721a2ecba63fd50c1540f 100644 (file)
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=mariadb
 PKG_VERSION:=10.4.22
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL := https://archive.mariadb.org/$(PKG_NAME)-$(PKG_VERSION)/source
index f206971611006a15d7dd8e37bd8d191c8fb0dde4..8fff379e1cf97cafb47a2b6b98e85ccaca096884 100644 (file)
@@ -152,6 +152,12 @@ start_service() {
        # Migration from old versions
        # shellcheck disable=SC2154
        if [ "$(cat "$datadir"/.version 2> /dev/null)" \!= "$version" ] && [ "$autoupgrade" -gt 0 ]; then
+               # Check for correct owner
+               local owner="$(stat --format %U:%G "$datadir" 2> /dev/null)"
+               if [ -n "$owner" ] && [ "$owner" != "$my_user:$my_group" ]; then
+                       chown -Rh "$my_user:$my_group" "$datadir"
+               fi
+
                # Start upgrade instance without credentials
                sudo -u "$my_user" mysqld --skip-networking --skip-grant-tables --socket=/tmp/mysql_upgrade.sock &
                PID="$!"