freebsd-src/libexec/rc/rc.d/zfsbe
Alexander Leidinger f99f0ee14e rc.d: add a service jails config to all base system services
This gives more permissions to services (e.g. network access to
services which require this) when they are started as an automatic
service jail.

The sshd patch is important for the sshd-related functionality as
described in the man-page in the service jails part.

The location of the added env vars is supposed to allow overriding them
in rc.conf, and to hard-disable the use of svcj for some parts where it
doesn't make sense or will not work.

Only a subset of all of the services are fully tested (I'm running this
since more than a year with various services started as service jails).
The untested parts should be most of the time ok, in some edge-cases
more permissions are needed inside the service jail.
Differential Revision:	https://reviews.freebsd.org/D40371
2024-05-22 15:41:49 +02:00

93 lines
1.7 KiB
Bash
Executable file

#!/bin/sh
#
#
# PROVIDE: zfsbe
# REQUIRE: mountcritlocal
# Handle boot environment subordinate filesystems
# that may have canmount property set to noauto.
# For these filesystems mountpoint relative to /
# must be the same as their dataset name relative
# to BE root dataset.
. /etc/rc.subr
name="zfsbe"
rcvar="zfs_enable"
start_cmd="be_start"
stop_cmd="be_stop"
required_modules="zfs"
mount_subordinate()
{
local _be
_be=$1
zfs list -rH -o mountpoint,name,canmount,mounted -s mountpoint -t filesystem $_be | \
while read _mp _name _canmount _mounted ; do
# skip filesystems that must not be mounted
[ "$_canmount" = "off" ] && continue
# skip filesystems that are already mounted
[ "$_mounted" = "yes" ] && continue
case "$_mp" in
"none" | "legacy" | "/" | "/$_be")
# do nothing for filesystems with unset or legacy mountpoint
# or those that would be mounted over /
;;
"/$_be/"*)
# filesystems with mountpoint relative to BE
mount -t zfs $_name ${_mp#/$_be}
;;
*)
# filesystems with mountpoint elsewhere
zfs mount $_name
;;
esac
done
}
activate_bootonce()
{
local _dev
local _bootonce
local _be
_dev=$1
_be=${_dev##*/}
_bootonce=$(kenv -q zfs-bootonce)
if [ "$_bootonce" = "zfs:${_dev}:" ] ; then
bectl activate $_be
fi
}
be_start()
{
if [ `$SYSCTL_N security.jail.jailed` -eq 1 ]; then
:
else
mount -p | while read _dev _mp _type _rest; do
[ $_mp = "/" ] || continue
if [ $_type = "zfs" ] ; then
mount_subordinate $_dev
if checkyesno zfs_bootonce_activate; then
activate_bootonce $_dev
fi
fi
break
done
fi
}
be_stop()
{
}
load_rc_config $name
# doesn't make sense to run in a svcj: mounting / config setting
zfsbe_svcj="NO"
run_rc_command "$1"