Bug 279672 - databases/mysql*-server: make the rc script service jails aware
Summary: databases/mysql*-server: make the rc script service jails aware
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Jochen Neumeister
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-06-11 08:30 UTC by Alexander Leidinger
Modified: 2026-09-05 20:30 UTC (History)
2 users (show)

See Also:
bugzilla: maintainer-feedback? (joneum)


Attachments
mysql80 (476 bytes, patch)
2024-06-11 08:30 UTC, Alexander Leidinger
no flags Details | Diff
mysql81 (476 bytes, patch)
2024-06-11 08:30 UTC, Alexander Leidinger
no flags Details | Diff
mysql84 (476 bytes, patch)
2024-06-11 08:31 UTC, Alexander Leidinger
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Leidinger freebsd_committer freebsd_triage 2024-06-11 08:30:39 UTC
Created attachment 251384 [details]
mysql80

Hi,

attached is a mechanical patch (untested) which makes the rc.d script service jails ready. This is a new feature in -current.

The setup I've chosen is to allow ipv4/ipv6 access. It does not allow to use sysv IPC in a jail. IF you want to add this possibility, the config would need to be changed to "net_basic sysvipc" instead. The config can be overridden in rc.conf.

See also:
  https://docs.freebsd.org/en/books/handbook/jails/#service-jails
  https://docs.freebsd.org/en/articles/rc-scripting/#rcng-service-jails

Bye,
Alexander.
Comment 1 Alexander Leidinger freebsd_committer freebsd_triage 2024-06-11 08:30:58 UTC
Created attachment 251385 [details]
mysql81
Comment 2 Alexander Leidinger freebsd_committer freebsd_triage 2024-06-11 08:31:14 UTC
Created attachment 251386 [details]
mysql84
Comment 3 Alexander Leidinger freebsd_committer freebsd_triage 2025-02-06 10:10:26 UTC
Note: this does not work with service jails, as the filename of the rc.d script is not the same as the value of the name variable inside. Both should match.

Quoting https://docs.freebsd.org/en/articles/rc-scripting/
> Now it is the right time to choose a unique name for our script once and for  all. We will use it in a number of places while developing the script. The content of the name variable needs to match the script name, some parts of FreeBSD (e.g., service jails and the cpuset feature of the rc framework) depend upon this. As such the filename shall also not contain characters which may be troublesome in scripting (e.g., do not use a hyphen "-" and others).
Comment 4 Alexander Leidinger freebsd_committer freebsd_triage 2025-02-06 10:10:59 UTC
Somehow a part of the quote was lost:

Now it is the right time to choose a unique name for our script once and for all. We will use it in a number of places while developing the script. The content of the name variable needs to match the script name, some parts of FreeBSD (e.g., service jails and the cpuset feature of the rc framework) depend upon this. As such the filename shall also not contain characters which may be troublesome in scripting (e.g., do not use a hyphen "-" and others).
Comment 5 Jochen Neumeister freebsd_committer freebsd_triage 2026-08-13 12:24:33 UTC
Hi Alexander,

sorry for the very late reply, this PR simply got lost on my side.

As you noted yourself in comment 3, the patches don't actually work for the mysql ports, since the script is installed as "mysql-server" but name is "mysql". Renaming the script is not an option for me, "service mysql-server start" is muscle memory for admins since decades.

Wouldn't it make more sense to fix this in rc.subr instead? It already knows the script path (rc_service), so the svcj code could use its basename instead of ${name} for exec.start/exec.stop. That would solve the problem for all ports with mismatching script names at once. Once that works I'm happy to add the svcj_options default to the mysql ports (8.1 is gone btw, today it's 8.0/8.4/9.7).
Comment 6 Alexander Leidinger freebsd_committer freebsd_triage 2026-08-14 08:34:09 UTC
rc_service is a good catch!
Committed in 	d0f0a3b89b932b776b76278fa6885f19e8b30cbb
Will be MFCed in about a week.
Comment 7 Jochen Neumeister freebsd_committer freebsd_triage 2026-08-26 07:44:54 UTC
(In reply to Alexander Leidinger from comment #6)

Hi Alexander,

I gave this a real test on a 15.1 VM (with 0bee17af48dd applied) and found a second problem: "service mysql-server stop" fails with "kill: Operation not permitted" and leaves the jail plus mysqld running. The default stop path kills from the host via run_rc_killcmd, and since the mysql script sets mysql_user, the kill is wrapped in "su -m mysql". An unprivileged user on the host can't signal processes inside a child jail. This hits every svcj service that sets ${name}user, scripts with their own stop_cmd are not affected since those are stopped via service -j inside the jail.

The following works for me (tested: start/status/stop/restart in the svcj all fine, normal operation without svcj unchanged), in _run_rc_killcmd after the su wrapper:

if checkyesno ${name}_svcj && [ "${_rc_svcj}" != jailing ]; then
    _cmd="/usr/sbin/jexec svcj-${name} ${_cmd}"
fi

I have the port patches for mysql80/84/97 ready and tested, but I'll hold them back until this is fixed in base, otherwise we'd ship a broken stop.
Comment 8 Alexander Leidinger freebsd_committer freebsd_triage 2026-08-30 17:47:00 UTC
(In reply to Jochen Neumeister from comment #7)
Fixed in -current (together with fixes for some more issues and unit tests for several operations). MFC to stable/15 in a month.
Comment 9 commit-hook freebsd_committer freebsd_triage 2026-09-05 20:25:16 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=443408a666860c2949ca9318b316f2f88b3176f0

commit 443408a666860c2949ca9318b316f2f88b3176f0
Author:     Alexander Leidinger <netchild@FreeBSD.org>
AuthorDate: 2026-09-05 20:23:57 +0000
Commit:     Jochen Neumeister <joneum@FreeBSD.org>
CommitDate: 2026-09-05 20:24:37 +0000

    databases/mysql*-server: make the rc script service jail aware

    Set a default of net_basic for the service jail options, so mysqld
    can use IPv4/IPv6 when it is started in a service jail. The default
    can be overridden via rc.conf.

    PR:             279672
    Sponsored by:   Netzkommune GmbH

 databases/mysql80-server/Makefile              | 2 +-
 databases/mysql80-server/files/mysql-server.in | 1 +
 databases/mysql84-server/Makefile              | 2 +-
 databases/mysql84-server/files/mysql-server.in | 1 +
 databases/mysql97-server/Makefile              | 2 +-
 databases/mysql97-server/files/mysql-server.in | 1 +
 6 files changed, 6 insertions(+), 3 deletions(-)