Solved "zfs list" returns stderr "cannot open 'jail': dataset does not exist"

I have a Jail managed ZFS dataset that works great from the command line.

However, upon booting the jail, i have an rc.d script that runs a service "env". In that script it needs to mount a zfs dataset. but first it needs to locate the name. I would like to use the "zfs list" command to do this but it throws an error. I've tried sleeping for up to 48 seconds and it seems to me it should respond within that time but it does not.

I have used rcorder to determine that my service is run last, so I can't make it run any later.

I am aware of these settings in rc.conf for networking that allow you to wait for various things to happen:
netwait_enable="YES" # Enable rc.d/netwait to wait for static ip to be up
netwait_ip="x.x.x.x" # Wait for ping response from any IP in this list.
netwait_timeout="10" # Total number of seconds to perform pings.
netwait_if="ngeth0" # Wait for active link on each intf in this list.
netwait_if_timeout="10" # Total number of seconds to monitor link state.

Is there something similar for mounts? Actually, that might not help. It is likely the dataset is mounted by this point. It is just that zfs list is not aware of it yet and responds with an error.

If anyone has any advice I would appreciate it. Thank you for any help!
 
ok, i am definitely missing something. I gave up on getting it to work, disabled the service in rc.conf and added a script to cron and that works immediately. so there is something preventing me from starting a service on a zfs mount during the boot rc.d process.

if anyone could point me in the right direction I would appreciate it.
 
Try e.g. /etc/jail.conf:
Code:
cat jail.conf
# Common configs for all jails
path = "/jails/$name";
host.hostname = "$name";
exec.start = "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
exec.clean;
persist;
ip4 = inherit;
ip6 = inherit;
mount.devfs;
mount.fdescfs;
allow.mount;
allow.mount.devfs;
allow.mount.fdescfs;
allow.mount.nullfs;
allow.mount.tmpfs;
allow.mount.procfs;
allow.mount.zfs;
enforce_statfs=1;
children.max=100;
allow.socket_af;
allow.raw_sockets;
allow.chflags;
allow.sysvipc;
a {
devfs_ruleset="20";
}
 
trying
exec.poststart+="service envelope onestart 5433";

root(33)au:~ # service jail restart bvc
Stopping jails: bvc.
Starting jails: cannot start jail "bvc":
ng0_bvc
37
envelope does not exist in /etc/rc.d or the local startup
directories (/usr/local/etc/rc.d), or is not executable
jail: bvc: service envelope onestart 5433: failed
.

that is not what i expected at all but thank you for the suggestion!
 
From jail(8):

exec.start
Command(s) to run in the jail environment when a jail is created.
A typical command to run is "sh /etc/rc"

exec.poststart
Command(s) to run in the system environment after a jail is cre-
ated, and after any exec.start commands have completed.

Your commands are running in the system environment. More likely you want something like:

Code:
exec.start = "/bin/sh /etc/rc";
exec.start += "service envelope onestart 5433";
 
Code:
sysvmsg = new;          # prevent security issues with sysv memory being shared across jails and to host
sysvsem = new;          # leave all three uncommented to make sure shared memory is not used
sysvshm = new;          # this one also prevents problems with postgres starting
exec.clean;             # default jails will inherit environment vars from parent. this stops that.
mount.devfs;            # minimum devices list
path="/jail/${name}";
host.hostname="${name}.something.com";
vnet;
vnet.interface="ng0_${name}";
exec.start="sh /etc/rc";
exec.stop="sh /etc/rc.shutdown";
exec.prestart="jng bridge ${name} ix0";
exec.prestop="ifconfig ng0_${name} -vnet ${name}";
exec.poststop="jng shutdown ${name}";
exec.poststop+="ngctl shutdown ng0_${name}";
exec.consolelog="/var/log/${name}.jail";
devfs_ruleset="1000"; # vnet rule set

# for zfs data dataset
allow.mount;
allow.mount.zfs;
enforce_statfs=1;
exec.poststart="zfs list -o name -Hr jail/${name} | grep jail/${name}/.../ | xargs -n 1 zfs destroy -r";
exec.poststart+="zfs list -o name -Hr "jail/${name}" | grep "jail/${name}/" | grep -v "jail/${name}/.../" | xargs -J % -n 1 zfs jail ${name} %";
exec.poststop="jng shutdown ${name}";
exec.poststop+="ngctl shutdown ng0_${name}";
exec.poststop+="zfs list -o name -Hr "jail/${name}" | grep "jail/${name}/" | grep -v "jail/${name}/.../" | xargs -J % -n 1 zfs unjail ${name} %";
exec.poststop+="zfs list -o name -Hr jail/${name} | grep jail/${name}/.../ | xargs -n 1 zfs destroy -r";

bvc {host.hostname = "bvc.somethingelse.com";}

Thank you patmaddox!

zfs destroy removes all disposable jail-managed datasets. This is specific to my use case so ignore it.

To make a dataset manageable despite a jail reboot you issue a zfs jail <jailname> <datasetname>
using exec.poststart worked best for me.
 
I again tried to get zfs mount to work during jail startup instead of from a cron script and after a careful read of the man page this is what i got:

# mostly zfs and networking
allow.mount;
allow.mount.zfs;
enforce_statfs=1;
exec.created="zfs list -o name -Hr jail/${name} | grep jail/${name}/.../ | xargs -n 1 zfs destroy -r";
exec.created+="zfs list -o name -Hr "jail/${name}" | grep "jail/${name}/" | grep -v "jail/${name}/.../" | xargs -J % -n 1 zfs jail ${name} %";
exec.prestart="jng bridge ${name} ix0";
exec.start="zfs mount -a";
exec.start+="/bin/sh /etc/rc";

exec.prestop="ifconfig ng0_${name} -vnet ${name}";
exec.stop="/bin/sh /etc/rc.shutdown";
exec.poststop="jng shutdown ${name}";
exec.poststop+="ngctl shutdown ng0_${name}";
exec.release="zfs list -o name -Hr "jail/${name}" | grep "jail/${name}/" | grep -v "jail/${name}/.../" | xargs -J % -n 1 zfs unjail ${name} %";
exec.release+="zfs list -o name -Hr jail/${name} | grep jail/${name}/.../ | xargs -n 1 zfs destroy -r";

And as near as I can tell, this all works. something about putting zfs jail into exec.created makes exec.start zfs mount work in time for envelope to start via the second exec.start sh rc. This may not be the 'correct' way to do it but merely my interpretation of 'man 8 jail' up until it worked. Thank you all!
 
Back
Top