Bug 247747

Summary: databases/mariadb104-server: Language bindings broken after update
Product: Ports & Packages Reporter: Dirk Meyer <dinoex>
Component: Individual Port(s)Assignee: Bernard Spil <brnrd>
Status: Closed FIXED    
Severity: Affects Some People CC: vvd
Priority: --- Flags: bugzilla: maintainer-feedback? (brnrd)
dinoex: merge-quarterly+
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
Fixed socket and log files names and locations
none
Fixed socket and log files names and locations
none
Fixed socket and log files names and locations, create user and group mysql during install vvd: maintainer-approval?

Description Dirk Meyer freebsd_committer freebsd_triage 2020-07-03 19:58:43 UTC
mariadb104-server upgraded: 10.4.13_2 -> 10.4.13_3

Server fails to restart with prior working config.

[ERROR] Can't start server : Bind on unix socket: Address already in use
[ERROR] Do you already have another mysqld server running on socket: /var/run/
mysql ?

Setitng a fixed path in /usr/local/etc/my.cnf helps only for basic tools.

All Perl, PHP, and Ruby bindings fail now with:
 "/var/run/mysql" ERR#38 'Socket operation on non-socket'

Ugly wokraround is to force the socke path in all applications.

The binaries and libs expect the socket at "/var/run/mysql",
but this is now a directory.

Please fix the port to have working default settings.

Suggestion a):
change the compiled in path.

Suggestion b):
use an different path in config that does not collied with the binary defaults.
Comment 1 Vladimir Druzenko freebsd_committer freebsd_triage 2020-07-03 23:53:52 UTC
Socket file is /var/run/mysql/mysql.sock and it was in 10.4.13_2 too.

You have to configure your application to user correct path.
Check
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=246694
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=247413
Comment 2 Dirk Meyer freebsd_committer freebsd_triage 2020-07-04 09:16:32 UTC
Please read the error messages again.

it is not about /usr/local/etc/my.cnf vs /usr/local/etc/mysql/my.cnf


Do you really suggest to change ever application with a DSN
that has not an explicit socket path to have a now an explicit socket path need to be defined?

The compiled in path now points to a directory the ports creates.

This needs to be fixed.
Comment 3 Dirk Meyer freebsd_committer freebsd_triage 2020-07-04 09:29:01 UTC
working
Perl exmpaple

working before:
$dsn = 'DBI:mysql:database';

now:
DBI connect('*****','***',...) failed: Can't connect to local MySQL server through  socket '/var/run/mysql' (38) 

Workaround:
$dsn = 'DBI:mysql:database:mysql_socket=/car/run/mysql/mysql.sock';
Comment 4 Dirk Meyer freebsd_committer freebsd_triage 2020-07-04 09:29:58 UTC
Perl example

working before:
$dsn = 'DBI:mysql:database';

now:
DBI connect('*****','***',...) failed: Can't connect to local MySQL server through  socket '/var/run/mysql' (38) 

Workaround:
$dsn = 'DBI:mysql:database:mysql_socket=/var/run/mysql/mysql.sock';
Comment 5 Dirk Meyer freebsd_committer freebsd_triage 2020-07-04 09:51:51 UTC
before  with mariadb104-server-10.4.13_2:

$ strings /usr/local/lib/mysql/libmariadbd.so | grep /tmp/m
/tmp/mysql.sock


now with mariadb104-server-10.4.13_3:
$ strings /usr/local/lib/mysql/libmariadb.so | grep /var/
/var/run/mysql

The socket file "/var/run/mysql/mysql.sock" is only in /usr/loccal/etc/mysql/*
This is only read my the mysql binary tools.
Comment 6 Vladimir Druzenko freebsd_committer freebsd_triage 2020-07-04 20:29:35 UTC
Created attachment 216203 [details]
Fixed socket and log files names and locations

Tested clean install (with removed /var/log/mysql - MARIADB_LOGDIR, /var/run/mysql - MARIADB_RUNDIR and /usr/local/etc/mysql - ETCDIR) on 12.1 amd64.

Bernard, I can explain every changed line if you want.
Comment 7 Vladimir Druzenko freebsd_committer freebsd_triage 2020-07-04 20:56:49 UTC
Created attachment 216204 [details]
Fixed socket and log files names and locations

Typo.
Comment 8 Vladimir Druzenko freebsd_committer freebsd_triage 2020-07-07 04:50:05 UTC
Created attachment 216276 [details]
Fixed socket and log files names and locations, create user and group mysql during install

Added creation user and group mysql during install.
More information is here: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=247413#c16

P.S. Without this patch port is broken for clean install.
Comment 9 Bernard Spil freebsd_committer freebsd_triage 2020-07-11 21:51:12 UTC
Thank you dinoex for a very comprehensive patch! Processing this, a lot to take in.

Any specific reason to make the socket filename a variable?
Comment 10 Vladimir Druzenko freebsd_committer freebsd_triage 2020-07-12 02:45:24 UTC
(In reply to Bernard Spil from comment #9)
> Any specific reason to make the socket filename a variable?
In Makefile or in service start script?

In Makefile for same name in all other files and possible to change in future in one place only.

In start script to allow user to change path and name of sock-file.

P.S. 10.5 need the same patch: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=247535
Comment 11 commit-hook freebsd_committer freebsd_triage 2020-07-12 14:33:14 UTC
A commit references this bug:

Author: brnrd
Date: Sun Jul 12 14:32:20 UTC 2020
New revision: 542085
URL: https://svnweb.freebsd.org/changeset/ports/542085

Log:
  databases/mariadb104-server: Fix breakage

   * Unbreak clean installs (USERS/GROUPS)
   * INSTALL_UNIX_ADDRDIR is a FILE, add the socket filename
   * Built-in socket path now confirmed to be consistent between client, lib and daemon

  PR:		247747
  Submitted by:	VVD <vvd unislabs com>
  Reported by:	dinoex
  MFH:		2020Q3

Changes:
  head/databases/mariadb104-server/Makefile
  head/databases/mariadb104-server/files/my.cnf.sample.in
  head/databases/mariadb104-server/files/mysql-server.in
  head/databases/mariadb104-server/files/server.cnf.sample.in
Comment 12 Bernard Spil freebsd_committer freebsd_triage 2020-07-12 14:55:36 UTC
Thanks for reporting and additional info Dirk!
Thanks for providing the patch VVD!

So MariaDB requires MARIADB_RUNDIR to be a path + filename :/

I've kept the creation of the directory /var/db/mysql in the client so that the directory at least exists, even if there's no socket there.

Validated with `strings` that client binary `mysql`, libraries `libmysql.so` and `libmariadb.so`, and daemon `mysqld` contain the correct `/var/run/mysql/mysql.sock`.

With hindsight, this overhaul of the port is more involved than I had wanted. Hope that the 10.5 port fares better.

Keep reporting!
Comment 13 commit-hook freebsd_committer freebsd_triage 2020-07-12 15:14:26 UTC
A commit references this bug:

Author: brnrd
Date: Sun Jul 12 15:13:48 UTC 2020
New revision: 542086
URL: https://svnweb.freebsd.org/changeset/ports/542086

Log:
  MFH: r542085

  databases/mariadb104-server: Fix breakage

   * Unbreak clean installs (USERS/GROUPS)
   * INSTALL_UNIX_ADDRDIR is a FILE, add the socket filename
   * Built-in socket path now confirmed to be consistent between client, lib and daemon

  PR:		247747
  Submitted by:	VVD <vvd unislabs com>
  Reported by:	dinoex

  Approved by:	ports-secteam (joneum)

Changes:
_U  branches/2020Q3/
  branches/2020Q3/databases/mariadb104-server/Makefile
  branches/2020Q3/databases/mariadb104-server/files/my.cnf.sample.in
  branches/2020Q3/databases/mariadb104-server/files/mysql-server.in
  branches/2020Q3/databases/mariadb104-server/files/server.cnf.sample.in
Comment 14 Vladimir Druzenko freebsd_committer freebsd_triage 2020-07-12 16:18:08 UTC
(In reply to Bernard Spil from comment #12)
> I've kept the creation of the directory /var/db/mysql in the client so that the directory at least exists, even if there's no socket there.
But if /var/run is tmpfs?
Comment 15 Vladimir Druzenko freebsd_committer freebsd_triage 2020-07-12 16:45:54 UTC
(In reply to VVD from comment #14)
Ah, you commit it in server start script too.
Comment 16 Vladimir Druzenko freebsd_committer freebsd_triage 2020-07-12 17:01:31 UTC
(In reply to commit-hook from comment #13)
USERS/GROUPS declared in the Makefile for the server only, but you try to create RUNDIR (/var/run/mysql) WITH owner mysql:mysql during install of the client BEFORE the server installed and user:group created.
Comment 17 Bernard Spil freebsd_committer freebsd_triage 2020-07-12 18:48:42 UTC
(In reply to VVD from comment #14)
And what if /tmp is? From the tmpfs manpage, the one example:

> mount -t tmpfs tmpfs /tmp

(In reply to VVD from comment #16)
Hot damn! And another bug... Is this blocking?
Comment 18 Vladimir Druzenko freebsd_committer freebsd_triage 2020-07-13 02:44:30 UTC
(In reply to VVD from comment #16)
$ ls -dl /var/run/mysql
drwxr-xr-x  2 root  17402160  512 Jul 12 20:36 /var/run/mysql

And after this the server start script will find dir /var/run/mysql and keep it as-is, then the mariadb server can't start with error in /var/log/mysql/mysqld.err:
2020-07-13  5:16:50 0 [ERROR] Can't start server : Bind on unix socket: Permission denied
2020-07-13  5:16:50 0 [ERROR] Do you already have another mysqld server running on socket: /var/run/mysql/mysql.sock ?
2020-07-13  5:16:50 0 [ERROR] Aborting

# rm -rf /var/run/mysql
# service mysql-server start
install: unknown group %%MARIADB_GROUP%%
Starting mysql.

And can't start again:
# grep MARIADB_GROUP /usr/local/etc/rc.d/mysql-server
                install -d -o ${mysql_user} -g %%MARIADB_GROUP%% "${mysql_rundir}"

You need:
SUB_LIST+=      MARIADB_LOGDIR="${MARIADB_LOGDIR}" \
                MARIADB_GROUP="${MARIADB_GROUP}"
in server part of if/else section of the databases/mariadb104-server/Makefile.
Comment 19 Vladimir Druzenko freebsd_committer freebsd_triage 2020-07-13 02:49:08 UTC
(In reply to Bernard Spil from comment #17)
> And what if /tmp is? From the tmpfs manpage, the one example:
> mount -t tmpfs tmpfs /tmp
This, but in /etc/fstab:
mount -t tmpfs tmpfs /var/run
Must create /var/run/mysql after every reboot.
But this is fixed in the server start script.

> Hot damn! And another bug... Is this blocking?
Yes. And one more after…
You can just get my patch without changes: https://bugs.freebsd.org/bugzilla/attachment.cgi?id=216276&action=diff
:-D