opnsense-src/libexec/rc/rc.d/mountcritremote
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.9 KiB
Bash
Executable file

#!/bin/sh
#
#
# PROVIDE: mountcritremote
# REQUIRE: NETWORKING FILESYSTEMS ipsec netwait nfscbd
# KEYWORD: nojail
. /etc/rc.subr
name="mountcritremote"
desc="Mount critical remote filesystems"
stop_cmd=":"
start_cmd="mountcritremote_start"
start_precmd="mountcritremote_precmd"
# Mount NFS filesystems if present in /etc/fstab
#
# XXX When the vfsload() issues with nfsclient support and related sysctls
# have been resolved, this block can be removed, and the condition that
# skips nfs in the following block (for "other network filesystems") can
# be removed.
#
mountcritremote_precmd()
{
case "`mount -d -a -t nfs 2> /dev/null`" in
*mount_nfs*)
# Handle absent nfs client support
load_kld -m nfs nfscl || return 1
;;
esac
return 0
}
mountcritremote_start()
{
local mounted_remote_filesystem=false
# Mount nfs filesystems.
#
case "`/sbin/mount -d -a -t nfs`" in
'')
;;
*)
mounted_remote_filesystem=true
echo -n 'Mounting NFS filesystems:'
mount -a -t nfs
echo '.'
;;
esac
# Mount other network filesystems if present in /etc/fstab.
case ${extra_netfs_types} in
[Nn][Oo])
;;
*)
netfs_types="${netfs_types} ${extra_netfs_types}"
;;
esac
for i in ${netfs_types}; do
fstype=${i%:*}
fsdecr=${i#*:}
[ "${fstype}" = "nfs" ] && continue
case "`mount -d -a -t ${fstype}`" in
*mount_${fstype}*)
mounted_remote_filesystem=true
echo -n "Mounting ${fsdecr} filesystems:"
mount -a -t ${fstype}
echo '.'
;;
esac
done
if $mounted_remote_filesystem; then
# Cleanup /var again just in case it's a network mount.
/etc/rc.d/cleanvar quietreload
rm -f /var/run/clean_var /var/spool/lock/clean_var
# Regenerate the ldconfig hints in case there are additional
# library paths on remote file systems
/etc/rc.d/ldconfig quietstart
fi
}
load_rc_config $name
# mounting shall not be performed in a svcj
mountcritremote_svcj="NO"
run_rc_command "$1"