How to check command line options before starting the container's init?


(Mrinal Dhillon) #1

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?

  1. 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.

Thank You
Mrinal Dhillon