Re: service jails and precmd make ntpd (and nfsd) sad

Alexander Leidinger <[email protected]>
Newsgroups gmane.os.freebsd.architechture
Organization No organization, this is a private message.
Message-ID <[email protected]>
Am 2025-03-21 10:18, schrieb Lexi Winter:
> hello,
> 
> while investigating how to support ntpd in a service jail[0], i ran 
> into
> a problem with rc(8) which i think is more architectural in nature.
> 
> the problem: several rc.d scripts, including ntpd and nfsd, assume that
> you can set $command_args in ${svc}_start_precmd and this change will 
> be
> reflected in ${svc}_start when the service is started.  for non-svcj
> services, this assumption is correct.  for svcj services, it is not,
> because ${svc}_start_precmd is run outside the jail, then ${svc}_start 
> is
> run inside the jail in a separate shell process.

Regarding the service jails your observation is correct.

IIRC there where some more cases of this before I introduced service 
jails. In those cases I changed the setting of command args from inside 
the precmd to outside the precmd. In those cases where I did it, this 
was possible as it was not depending on some value which was computed 
inside precmd.

> this cannot be fixed by simply running ${svc}_start_precmd in the svcj,
> because ntpd's rc script needs to load a kernel module in its precmd.
> 
> i think the correct fix here is to split precmd into two things, one of
> which is run outside the jail (to load kernel modules, etc.) and one of
> which is run before ${svc}_start (or other actions) in the same shell
> that the action will run in.
> 
> i would propose 'setup' as the thing which is run outside the jail, and
> 'precmd' as the thing which is run inside the jail.

Modifying the service jails to run the precmd (or whatever) inside 
instead of of outside requires more than an one line change. Be careful 
if you want to go that way.

> am i on the right track here, or have i missed something?

There is another option. Load the kernel module outside of the ntpd 
service rc script. Either as a documented requirement when enabling 
service jails (and an error message from the rc script in the svcj case 
if the module is not loaded), or by adding another rc script which also 
listens on ntpd_enable and the ntpd rc scripts depends on. This module 
loading script can be forced to svcj off as it runs in a different 
execution context than the current ntdp rc script. Personally I prefer 
the separation of duties here instead of adding complexity inside the rc 
scripts (KISS... rc.subr and related are already convoluted).

Bye,
Alexander.

-- 
http://www.Leidinger.net [email protected]: PGP 0x8F31830F9F2772BF
http://www.FreeBSD.org    [email protected]  : PGP 0x8F31830F9F2772BF
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEER9UlYXp1PSd08nWXEg2wmwP42IYFAmfdbhkACgkQEg2wmwP4
2IbhFg//RljXbR2MgVYLKs1z/jQs+OeQ7HbDmQFfo5xX5WDBFVwX2Rfvkrizb/yL
AXMUK88TMSBBdyUYDSadRYA/MFw579I5poThn1sCGmoSIffLy6goEq+BQO35SmyN
iKJihqY8n1gv8n9K+NstqxvUw1UFwIj8r3YVSGkZ5m2OTgi5N483PJuvQRC+4iyI
iOUafuxmMeA+9SZ3ZBJyKG9pLhhUIkUwLKbFFxTE63qcnHSfmYYKII+blEef/W9P
6iylZaJ27he3ETg1TYTGMYzFELWuslSMuK0D4s1J7xthESGbjR3fP7HtfapIHJSU
3e0NUzzf8DyuwtniQOSNaP0u40a8ym+qT9NA12a16kfKLi0+XarWEQfwD2ASJAKr
JHtIqNGsj1rZFgn3bJkZLJwpD6tJPDj8N2F7ota9yBSNmqYAqZEXmg17j13dPDAq
zDbgfOBxLPq2pEGdC/wiCBY91kRwzgvgk0g39zFxUahD/RwgG2pF+z7Tv9wx2pQb
I9X4agKnn++PcCnjJx0uBjv3Nm5cGZXpSmAOqSUX37F2rOc91RnKRWUoofl3K4IU
AE1WZ/6Slafj7NPpjGk4/5tg6s+GGp2DYMgd6sB0xnxd7ZlhfGf5HIvwZ6L4UQ0s
jx4Vg52sAusLzzeQaDEbSlOun9hs1vFIofRv2lrlSOofQqoQ+xQ=
=xx8T
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.