How to check the method and command line options before before starting the container’s init i.e. lxc-execute/lxc-start and the arguments provided. i.e. lxc-execute cntr -d [-s key=val] – command or lxc-start cntr [-s key=val] .
I have had success with the following first approach but not sure if this most is optimal method and will work in future releases. Also can you think of a scenario where this will fail?
In lxc.hook.start-host copy /proc/$LXC_PID/cmdline at a host path that is bind mounted inside container and then read the cmdline file in lxc.hook.start.
This one failed to my surprise:
2. /proc/$PPID/{cmdline,exe} in lxc.hook.start bash script could not provide enough info:
/proc/$PPID/cmdline returns [lxc monitor] /var/extensions/lxc app for a daemon container.
– /proc/$PPID/exe -> /usr/bin/lxc-execute or /proc/$PPID/exe -> /usr/bin/lxc-start atleast identifies the method used to start the container.
None of the approaches that i discussed work in case of lxc-execute --daemon and lxc-start, both points lxc-monitor. i am not able find any method with which we can identify whether the container is started with lxc-execute or lxc-start in any of the hooks. suggestions?
Yes we need to ascertain in hooks. Example above was just a bad example. With pid namespace shared how do we figure if container will be started with lxc.init.static or systemd?