[Lxc-users] Ubuntu template questions

Serge Hallyn serge.hallyn at canonical.com
Thu Mar 15 13:41:11 UTC 2012


Quoting Fajar A. Nugraha (list at fajar.net):
> On Thu, Mar 15, 2012 at 10:02 AM, Serge Hallyn
> <serge.hallyn at canonical.com> wrote:
> > On 03/14/2012 03:23 AM, Fajar A. Nugraha wrote:
> >> On Wed, Mar 14, 2012 at 3:17 PM, Jäkel, Guido<G.Jaekel at dnb.de>  wrote:
> >>> Dear Fajar,
> >>>
> >>> i just googled  http://www.makelinux.net/man/7/P/power-status-changed  . There's written:
> >>>
> >>>         This event is not handled in the default Upstart configuration.
> >>>
> >>>
> >>> For control-alt-delete, the corresponding sentence states:
> >>>
> >>>         In the default Upstart configuration handling of this event is provided by the /etc/init/control-alt-delete.conf task which runs the shutdown(8) tool.
> >>>
> >>>
> >>> This sounds to me like in the current version of upstart the suggested patches to add a SIGPWR handler are included and there's "just" a script missing. I don't have a Ubuntu available; maybe a simple  power-status-changed.conf  will already do all the magic???
> >>
> >> Good catch :D
> >>
> >> $ cat power-status-changed.conf
> >> start on power-status-changed
> >>
> >> task
> >> exec shutdown -h now "Power Down"
> >>
> >>
> >> That, plus an lxc-ps and kill -PWR from the host, was able to shutdown
> >> the guest cleanly with minimal change to the guest.
> >>
> >
> > Thanks guys, this is great.  I don't know if we can swing this this
> > cxycle (it's possible) but an upstart package with your job added is at
> > https://code.launchpad.net/~serge-hallyn/ubuntu/precise/upstart/upstart-handle-sigpwr
> 
> 
> Did you also have a chance to modify /etc/init/lxc.conf?

No, I was going to wait a few days and see if there's any chance of getting
the upstart script accepted.

> A good shutdown script would probably goes something like this:
> - list all containers to autoshutdown.
> The existing one looks at /etc/lxc/auto/*, but IMHO it might be better
> to just list ALL runing containers using "lxc-ls", since they're going
> to be dead anyway when the host is stopped.
> - get PID of init process in containers to shutdown. A combination of
> "lxc-ls", "grep", and/or "awk" would probably work. If the pid can't
> be determined, shutdown the container immediately using lxc-stop
> - send SIGPWR to all init PIDs in previous step
> - create a wait loop for a maximum of ... 30 seconds (?) which
> basically check whether all the process with PIDs above still exist or
> not. If it STILL exist at the end of the wait time, we assume the
> container can't be shutdown cleanly.
> - force-shutdown containers whose init PID hasn't disappear yet using lxc-stop.

Right, which is pretty much how the pre-stop in libvirt goes.

> The maximum wait time is debatable, but IMHO 30 seconds should be a
> good start. Or perhaps we need to put it in /etc/default/lxc?

Either way.

thanks,
-serge




More information about the lxc-users mailing list