Skip to content

mysql: find sockets on default mariadb installation on Debian - #934

Open
mueller-ma wants to merge 3 commits into
Checkmk:masterfrom
dahag-ag:mariadb-sockets
Open

mueller-ma wants to merge 3 commits into
Checkmk:masterfrom
dahag-ag:mariadb-sockets

Conversation

@mueller-ma

Copy link
Copy Markdown
Contributor

General information

The current auto-detect command doesn't work on a default MariaDB installation on Debian for two reasons:

  • The account is called mariadbd
  • No "socket" is in the CMD printed by ps

Bug reports

No output of the current auto-detect code:

[root@mariadb ~]# ps -fww -C mysqld | grep "socket"
[root@mariadb ~]# ps -fww -C mariadbd | grep "socket"
[root@mariadb ~]#

Proposed changes

As the default socket is /run/mysqld/mysqld.sock, use all sockets in /run/mysqld to support multi-instance setups.

From new Debian installation:

root@ca9b0a452ef5:/# grep socket -Ri /etc/mysql/
/etc/mysql/my.cnf:# Port or socket location where to connect
/etc/mysql/my.cnf:socket = /run/mysqld/mysqld.sock
/etc/mysql/my.cnf.fallback:# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
/etc/mysql/debian.cnf:# anyway thanks to unix socket authentication and hence
/etc/mysql/mariadb.cnf:# Port or socket location where to connect
/etc/mysql/mariadb.cnf:socket = /run/mysqld/mysqld.sock

The current auto-detect command doesn't work on a default MariaDB installation on Debian for two reasons:

- The account is called mariadbd
- No "socket" is in the CMD printed by ps

As the default socket is `/run/mysqld/mysqld.sock`, use all sockets in `/run/mysqld` to support multi-instance setups.

From new Debian installation:

```
root@ca9b0a452ef5:/# grep socket -Ri /etc/mysql/
/etc/mysql/my.cnf:# Port or socket location where to connect
/etc/mysql/my.cnf:socket = /run/mysqld/mysqld.sock
/etc/mysql/my.cnf.fallback:# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
/etc/mysql/debian.cnf:# anyway thanks to unix socket authentication and hence
/etc/mysql/mariadb.cnf:# Port or socket location where to connect
/etc/mysql/mariadb.cnf:socket = /run/mysqld/mysqld.sock
```
andrea-vaccaro

This comment was marked as outdated.

@andrea-vaccaro andrea-vaccaro left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to preserves the "mysql" name when exactly one socket is found and only use paths for multiple sockets so that existing service names are kept?

@mueller-ma

Copy link
Copy Markdown
Contributor Author

I pushed a commit that keeps the default name.

@mueller-ma

Copy link
Copy Markdown
Contributor Author

Failed pipeline seems unrelated to me: WARNING: Download from https://artifacts.lan.tribe29.com/repository/upstream-archives/base-2.18.tar.gz failed: class java.io.IOException Connect timed out

Comment thread agents/plugins/mk_mysql Outdated
@TimotheusBachinger

Copy link
Copy Markdown
Contributor

Thanks for the quick update, the mysqlx exclusion works as intended (verified on Ubuntu 24.04 with MySQL 8.0.46).

One more compatibility gap came up in internal review, and I could reproduce it on a Debian bookworm container: MariaDB multi-instance setups.
With mariadb@foo.service the directory contains mysqld.sock and mysqld.foo.sock, so find returns two sockets and the multi-instance branch is taken:

$ find /run/mysqld -type s ! -name 'mysqlx*'
/run/mysqld/mysqld.foo.sock
/run/mysqld/mysqld.sock

instance headers with the current PR:
[[/run/mysqld/mysqld.foo.sock]]
[[/run/mysqld/mysqld.sock]]

Before this change the plugin fell back to do_query "" "" on such hosts, and the client connected to its compiled-in default socket, which is mysqld.sock. So the default instance was already monitored under the instance name mysql. The second instance was invisible, which is what your PR fixes. But the PR also renames the default instance to /run/mysqld/mysqld.sock, so its existing services vanish and the metric history is lost. The single-socket special case does not cover this, since two sockets are found.

Suggested fix: keep the empty instance name for the auto-detected default socket inside the loop, instead of keying on the socket count:

for i in "${!mysql_sockets[@]}"; do
    socket="${mysql_sockets[i]}"
    alias="${aliases[i]}"
    if [ -n "$alias" ]; then
        do_query "$socket" "$alias"
    elif [ -n "$mysql_socket_count" ] && [ "$socket" = "/run/mysqld/mysqld.sock" ]; then
        # auto-detected default socket: keep the instance name "mysql"
        do_query "$socket" ""
    else
        do_query "$socket" "$socket"
    fi
done

mysql_socket_count is only set in the auto-detect branch, so sockets configured explicitly in mysql.cfg keep their path names as today. With this rule the separate elif [ "$mysql_socket_count" = 1 ] branch is no longer needed and can be removed.

I tested this variant on all three setups:

Host Sockets found Instance headers
Debian MariaDB, two instances mysqld.foo.sock, mysqld.sock [[/run/mysqld/mysqld.foo.sock]], [[]]
Ubuntu MySQL 8 mysqld.sock (mysqlx excluded) [[]]
Debian, both sockets in mysql.cfg from config [[/run/mysqld/mysqld.sock]], [[/run/mysqld/mysqld.foo.sock]]

All existing service names stay the same, new instances get their socket path as name, and the change can ship as a compatible fix.

@mueller-ma

Copy link
Copy Markdown
Contributor Author

Good catch. Can you push that fix to my branch?

checkmkreporeplicator Bot pushed a commit that referenced this pull request Oct 1, 2026
closes #934

Change-Id: Ica2e3a11a1febdafc6388f1a29f9a16775325479
JIRA-Ref: CMK-36798
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants