From 794bebf9ee18de4138c4d2c93853d49ff3af7f12 Mon Sep 17 00:00:00 2001 From: anel Date: Fri, 1 Apr 2022 07:17:43 -0700 Subject: [PATCH] Use proper pid namespace Problem: ============== By testing `pgrep` with `--ns` option, introduced with MDEV-21331, commit fb7c1b9415c9a8b0dc2e86ae44f0e7a2634e5d7e, I noted that: a) `--ns` cannot use more than single PID. b) `--ns` is returning the processes of the namespace to which supplied PID belongs to. So by that sense command `pgrep -x --ns $$ mysqld` will always return an error and skip checking of the existing PID of the server. Solution: ============== Suggested solution is to add `--nslist pid`, since `--ns` needs to know in which namespace type it should look for. See `pgrep --help` for different namespace types. Note also that this works *only* if script is run as a `root` (we have that case here). Current PR is a part of: 1. MDEV-21331: sync preinst and postrm script 2. MDEV-15718: check for exact mysqld process This commit: a) fixes fb7c1b9415c9a8b0dc2e86ae44f0e7a2634e5d7e b) Closes PR #2068 (obsolete) c) Closes PR #2069 (obsolete) Thanks Faustin Lammler for testing and verifying Reviewed by <> --- debian/mariadb-server-10.2.postrm | 5 +++++ debian/mariadb-server-10.2.preinst | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/debian/mariadb-server-10.2.postrm b/debian/mariadb-server-10.2.postrm index f8a95df54ea..1ead4098906 100644 --- a/debian/mariadb-server-10.2.postrm +++ b/debian/mariadb-server-10.2.postrm @@ -11,6 +11,11 @@ MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf" # do it himself. No database directories should be removed while the server # is running! stop_server() { + # Return immediately if there are no mysql processes running + # as there is no point in trying to shutdown in that case. + # Compatibility with versions that ran 'mariadbd' + if ! pgrep -x --nslist pid --ns $$ "mysqld|mariadbd" > /dev/null; then return; fi + set +e if [ -x /usr/sbin/invoke-rc.d ]; then invoke-rc.d mysql stop diff --git a/debian/mariadb-server-10.2.preinst b/debian/mariadb-server-10.2.preinst index 161d9caee6e..13dda71998a 100644 --- a/debian/mariadb-server-10.2.preinst +++ b/debian/mariadb-server-10.2.preinst @@ -22,10 +22,11 @@ mysql_upgradedir=/var/lib/mysql-upgrade # is running! Another mysqld in e.g. a different chroot is fine for us. stop_server() { if [ ! -x /etc/init.d/mysql ]; then return; fi - - # Return immediately if there are no mysql processes running + # Return immediately if there are no mysql processes running on a host + # (leave containerized processes with the same name in other namespaces) # as there is no point in trying to shutdown in that case. - if ! pgrep --ns $$ mysqld > /dev/null; then return; fi + # Compatibility with versions that ran 'mariadbd' + if ! pgrep -x --nslist pid --ns $$ "mysqld|mariadbd" > /dev/null; then return; fi set +e if [ -x /usr/sbin/invoke-rc.d ]; then