30.04.2014 16:26, Christian Seiler wrote: [] > However, from personal experience, lxc-start is not quite as user- > friendly. In >95% of cases, I want to start a container in the > background and keep it running. There are some cases where I want > to have it in the foreground and get the output immediately, but > that is the exception (I am not talking about lxc-execute here, > just about lxc-start).
Please count my strong disagreement here. Usually when you're start the container for the first time, when you just configured it, you want to see some error messages right on the terminal you start it from. So you can fix it and repeat, to hit another configuration error and so on. When -d is the default, you not only see the problems immediately. It is much worse: stderr of lxc-start is redirected to /dev/null, so you don't even see error messages from lxc-start itself! Such as, cgroupfs is not mounted, or what not. I think the better alternative, in my opinion, is to be able to specify -d in the config file. When you're done, write it there, and -d becomes the default _for this container_, and you can use -F to force foreground. Speaking of error messages during startup, I always used the following trick, instead of using standard daemon() function: create a pipe, fork, and use this pipe in parent to read just one variable: exit status from the child (close writing side of the pipe in parent). Now parent just sits there reading from this pipe. In the child, do all the necessary init stuff, but du not close error reporting channels yet. When all done, write 0 into the pipe, close it, redirect stderr and run usual background task. In case of failure, either just exit (parent will read 0 bytes which means failure) or write the non-zero exit status to the pipe. This is when you have to do all the init in a single process. When it is posisible to do init and run in _different_ processes (across fork), it is best to do init first, and run daemon() only when everything is done. Thanks, /mjt _______________________________________________ lxc-devel mailing list [email protected] http://lists.linuxcontainers.org/listinfo/lxc-devel
