Skip to content

Commit 794bebf

Browse files
committed
Use proper pid namespace
Problem: ============== By testing `pgrep` with `--ns` option, introduced with MDEV-21331, commit fb7c1b9, 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 fb7c1b9 b) Closes PR #2068 (obsolete) c) Closes PR #2069 (obsolete) Thanks Faustin Lammler <faustin@mariadb.org> for testing and verifying Reviewed by <>
1 parent 7055545 commit 794bebf

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

debian/mariadb-server-10.2.postrm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
1111
# do it himself. No database directories should be removed while the server
1212
# is running!
1313
stop_server() {
14+
# Return immediately if there are no mysql processes running
15+
# as there is no point in trying to shutdown in that case.
16+
# Compatibility with versions that ran 'mariadbd'
17+
if ! pgrep -x --nslist pid --ns $$ "mysqld|mariadbd" > /dev/null; then return; fi
18+
1419
set +e
1520
if [ -x /usr/sbin/invoke-rc.d ]; then
1621
invoke-rc.d mysql stop

debian/mariadb-server-10.2.preinst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ mysql_upgradedir=/var/lib/mysql-upgrade
2222
# is running! Another mysqld in e.g. a different chroot is fine for us.
2323
stop_server() {
2424
if [ ! -x /etc/init.d/mysql ]; then return; fi
25-
26-
# Return immediately if there are no mysql processes running
25+
# Return immediately if there are no mysql processes running on a host
26+
# (leave containerized processes with the same name in other namespaces)
2727
# as there is no point in trying to shutdown in that case.
28-
if ! pgrep --ns $$ mysqld > /dev/null; then return; fi
28+
# Compatibility with versions that ran 'mariadbd'
29+
if ! pgrep -x --nslist pid --ns $$ "mysqld|mariadbd" > /dev/null; then return; fi
2930

3031
set +e
3132
if [ -x /usr/sbin/invoke-rc.d ]; then

0 commit comments

Comments
 (0)