Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

healthcheck.sh cannot connect on 11.6-ubi #630

Open
sebastianhelbig opened this issue Feb 2, 2025 · 4 comments
Open

healthcheck.sh cannot connect on 11.6-ubi #630

sebastianhelbig opened this issue Feb 2, 2025 · 4 comments
Assignees

Comments

@sebastianhelbig
Copy link

sebastianhelbig commented Feb 2, 2025

Upgraded from 11.5 to 11.6-ubi.

On mariadb startup, socket is created at /run/mariadb/mariadb.sock.

sh-5.1$ healthcheck.sh --connect --innodb_initialized --mariadbupgrade
ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (2)
ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (2)
@grooverdan
Copy link
Member

grooverdan commented Feb 2, 2025

I did find missing flock for --mariadbupgrade missing util-linux-core.

Couldn't replicate the socket;

++ _process_sql --skip-column-names -e 'select 1 from information_schema.ENGINES WHERE engine='\''innodb'\'' AND support in ('\''YES'\'', '\''DEFAULT'\'', '\''ENABLED'\'')'
++ mariadb --defaults-extra-file=/var/lib/mysql/.my-healthcheck.cnf --skip-ssl --skip-ssl-verify-server-cert --protocol socket -B --skip-column-names -e 'select 1 from information_schema.ENGINES WHERE engine='\''innodb'\'' AND support in ('\''YES'\'', '\''DEFAULT'\'', '\''ENABLED'\'')'
+ s=1
+ '[' 1 == 1 ']'
+ test=
+ shift
+ '[' 1 -gt 0 ']'
+ case "$1" in
+ test=mariadbupgrade
+ '[' -n mariadbupgrade ']'
+ _test_exists mariadbupgrade
+ declare -F mariadbupgrade
+ return 0
+ mariadbupgrade
+ local f=/var/lib/mysql/mariadb_upgrade_info
+ '[' -r /var/lib/mysql/mariadb_upgrade_info ']'
+ flock --exclusive --nonblock -n 9
/usr/local/bin/healthcheck.sh: line 238: flock: command not found

The socket location is defined in /etc/my.cnf.d/docker.cnf. Are you doing a manual configuration other than /etc/mysql/conf.d, the only location documented in https://hub.docker.com/_/mariadb/ - "Using a custom MariaDB configuration file"

@sebastianhelbig
Copy link
Author

No custom configuration.

  db:
    command: --sql_mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
    container_name: test-db
    environment:
      - MARIADB_AUTO_UPGRADE=true
      - MARIADB_DATABASE=test
      - MARIADB_ROOT_PASSWORD=test
      - MARIADB_PASSWORD=test
      - MARIADB_USER=test
      - TZ=Europe/Berlin
    expose:
      - "3306"
    healthcheck:
      interval: 10s
      retries: 10
      start_period: 10s
      test: [ "CMD", "healthcheck.sh", "--connect", "--innodb_initialized", "--mariadbupgrade" ]
      timeout: 5s
    image: mariadb:11.6-ubi
    restart: unless-stopped
    volumes:
      - ./mysql:/var/lib/mysql

@sebastianhelbig
Copy link
Author

It is working on "default" 11.6 (non-ubi). There on mariadb startup the socket is created at /run/mysqld/mysqld.sock.

@grooverdan
Copy link
Member

grooverdan commented Feb 5, 2025

I think I may see the reason:

from a ubi instance:

$ podman exec test-db cat /var/lib/mysql/.my-healthcheck.cnf
[mariadb-client]
port=3306
socket=/run/mariadb/mariadb.sock

from a non-ubi instance:

$ podman exec m116 cat /var/lib/mysql/.my-healthcheck.cnf
[mariadb-client]
port=3306
socket=/run/mysqld/mysqld.sock

if you swapped between the two the datadir configuration the socket configuration here isn't portable.

Remove file and allow MARIADB_AUTO_UPGRADE to regenerate this is an easy option.

Seems this isn't needed and its safe to relay on the real configuration file

$ podman exec m116ubi sed -i -e '/socket=/d' /var/lib/mysql/.my-healthcheck.cnf

$ podman exec m116ubi healthcheck.sh --connect --innodb_initialized --mariadbupgrade && echo success
/usr/local/bin/healthcheck.sh: line 238: flock: command not found
healthcheck mariadbupgrade failed

$ podman exec m116ubi healthcheck.sh --connect --innodb_initialized  && echo success
success

$ podman exec m116ubi cat /var/lib/mysql/.my-healthcheck.cnf
[mariadb-client]
port=3306
user=healthcheck

@grooverdan grooverdan self-assigned this Feb 5, 2025
grooverdan added a commit to grooverdan/mariadb-docker that referenced this issue Feb 5, 2025
The socket/port that where used in the initialization of the datadir
in the /var/lib/mysql may not be the same used at runtime.

This was highlighted in MariaDB#630 where the ubi container puts a socket
in a different location from the non-ubi container.

On the assumption that any change of default port/socket is going
to be in a server configuration file, preferably with a [client-server]
section, lets omit copying this unnecessary.

This does however mean that command line specified changes to
socket (and port less so) will not be persistent. This means that
podman run mariadb:lts --socket=/tmp/s.sock will not be discoverable
for the healtcheck.sh script.
grooverdan added a commit to grooverdan/mariadb-docker that referenced this issue Feb 5, 2025
The socket/port that where used in the initialization of the datadir
in the /var/lib/mysql may not be the same used at runtime.

This was highlighted in MariaDB#630 where the ubi container puts a socket
in a different location from the non-ubi container.

On the assumption that any change of default port/socket is going
to be in a server configuration file, preferably with a [client-server]
section, lets omit copying this unnecessary.

This does however mean that command line specified changes to
socket (and port less so) will not be persistent. This means that
podman run mariadb:lts --socket=/tmp/s.sock will not be discoverable
for the healtcheck.sh script.

Closes: MariaDB#630
grooverdan added a commit to grooverdan/mariadb-docker that referenced this issue Feb 5, 2025
As highlighted in MariaDB#630 a healthcheck.sh --mariadbuprade test
will use flock that is provided by util-linux-core on ubi systems.
grooverdan added a commit that referenced this issue Feb 5, 2025
As highlighted in #630 a healthcheck.sh --mariadbuprade test
will use flock that is provided by util-linux-core on ubi systems.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants