Open igalic opened 6 years ago
libiocage cannot do much about checking existence of interfaces or their order, because:
vnet0
.interface
JailConfig property. That is also the case when the interfaces are being set via global the JailConfig defaults.When it comes to invalid configuration, libiocage already does validate the inputs:
# ioc set interfaces="INVALID" myjail
Invalid value for property 'interfaces' of jail myjail: Invalid NIC pair (should be <nic>:<bridge>)
Invalid value for property 'interfaces':
Surprisingly the error message appears twice, which needs to be fixed.
this makes sense!
you can create a jail with an interfaces that doesn't exist! after all, vnet0 is just a name, and it's created on the fly
however, you cannot start the jail without the bridge existing, so we should check if the bridge that was passed to interfaces
exists before startup, or else, fail with a better error
root@container-host1 /u/l/s/libiocage# ioc create better-error vnet=yes interfaces=bridge0:vnet0 ip4_addr='vnet0|dhcp'
better-error successfully created from 11.2-RELEASE!
root@container-host1 /u/l/s/libiocage# ioc start better-error
[+] JailResolverConfig: OK [0.005s]
[-] JailLaunch@better-error: FAILED [1.123s]
Launching jail better-error failed
Destroying jail better-error failed
root@container-host1 /u/l/s/libiocage#
the same thing ran with -d spam
[1;32m/etc/rc.conf was read from /etc/rc.conf[0m
[1;34mUpdated /etc/rc.conf data from /etc/rc.conf[0m
[1;34mQuerying all running jails status[0m
[1;34mConfiguring nameserver for Jail 'better-error'[0m
[-] JailResolverConfig: ...
[1;34mresolv.conf copied from host[0m
[2F
[+] JailResolverConfig: OK [0.005s][K
[1;32mStarting VNET/VIMAGE[0m
[1;32mno static routes configured[0m
[-] JailLaunch@better-error: ...
[1;32m/etc/rc.conf was read from /jails/jails/better-error/root/etc/rc.conf[0m
[1;34mUpdated /etc/rc.conf data from /jails/jails/better-error/root/etc/rc.conf[0m
[1;32m/etc/rc.conf was not modified - skipping write[0m
[1;32mSetting fstab auto-creation placeholder[0m
[1;32mfstab loaded from /jails/jails/better-error/fstab[0m
[1;32mSetting fstab auto-creation placeholder[0m
[1;32mfstab loaded from /jails/jails/better-error/fstab[0m
[1;34m/jails/jails/better-error/fstab written[0m
[1;34mClearing resource limits[0m
[1;32mReading devfs.rules from /etc/devfs.rules[0m
[1;32mExecuting (interactive): /usr/sbin/jail -c vnet name=default-better-error host.hostname=better-error host.domainname=local path=/jails/jails/better-error/root securelevel=2 host.hostuuid=better-error devfs_ruleset=6 enforce_statfs=2 children.max=0 allow.set_hostname=1 allow.sysvipc=0 exec.prestart="/jails/jails/better-error/launch-scripts/prestart.sh" exec.prestop="/jails/jails/better-error/launch-scripts/prestop.sh" exec.poststop="/jails/jails/better-error/launch-scripts/poststop.sh" exec.jail_user=root sysvmsg=new sysvsem=new sysvshm=new allow.raw_sockets=0 allow.chflags=0 allow.mount=0 allow.mount.devfs=0 allow.mount.nullfs=0 allow.mount.procfs=0 allow.mount.fdescfs=0 allow.mount.zfs=0 allow.quotas=0 allow.socket_af=0 exec.timeout=600 stop.timeout=30 mount.fstab=/jails/jails/better-error/fstab mount.devfs=1 mount.fdescfs=0 allow.mount.tmpfs=0 allow.dying persist exec.poststart="/jails/jails/better-error/launch-scripts/poststart.sh"[0m
[1;32m running exec.created hook on the host[0m
[1;32m ifconfig: interface vnet0 does not exist[0m
[1;32m jail: /bin/sh -c "/jails/jails/better-error/launch-scripts/poststart.sh": failed[0m
[1;34mJail 'better-error' was not started[0m
[1;31mLaunching jail better-error failed[0m
[1;34mClearing resource limits[0m
[1;32mWriting jail.conf file to /jails/jails/better-error/launch-scripts/jail.conf[0m
[1;32mExecuting (interactive): /usr/sbin/jail -v -r -f /jails/jails/better-error/launch-scripts/jail.conf default-better-error[0m
[1;32m jail: "default-better-error" not found[0m
[1;31mDestroying jail better-error failed[0m
[1;32mManually executing prestop and poststop hooks[0m
[23F
[-] JailLaunch@better-error: FAILED [1.154s][K
and here's the error we're looking for:
ifconfig: interface vnet0 does not exist
So we can improve the error message here. For instance we could implement explicit handling of stderr output in an additional thread, so that the error can be reasonably parsed and further explained to the user. If this output is seen, we could say things like:
The bridge 'vnet0' does not exist on this host. It was configured in the 'myjail' jail's interface config property value 'bridge0:vnet0'.
or even
The bridge 'vnet0' does not exist on this host. It was configured in the 'myjail' jail's interface config property value 'bridge0:vnet0'. The device 'bridge0' exists on this hosts, so maybe the order '
: ' was swapped.
I would not like to introduce an early check for this occasion, because a failure can be fixed once, while the code would become more complex (and slower) when mitigating the issue early on.
yeah
we need to do better, wrt error messages. both of these would be an excellent step forward!
so, yeah, i guess we finally should start catching both, stdout
and stderr
could this now (partially) be fixed with #589?
when creating a vnet jail, it expects
interfaces
to be set to a specific format:interfaces="vnet0:bridge0"
failing to do so, will ensure that the jail doesn't start, but it also doesn't tell us why! it's very easy to accidentally, or intuitively! reverse this notation
there's no clue as to what is wrong, barely a hint, even starting the jail with
-d spam