Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 330835 - app-emulation/lxc-0.7.2-r1 init script
Summary: app-emulation/lxc-0.7.2-r1 init script
Status: RESOLVED OBSOLETE
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Diego Elio Pettenò (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-02 13:44 UTC by Vadim Kuznetsov (RETIRED)
Modified: 2014-04-11 11:20 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vadim Kuznetsov (RETIRED) gentoo-dev 2010-08-02 13:44:59 UTC
Hi Diego,
Thanks for the script.!

    init_pid=$(head -n1 ${cgroupmount}/${CONTAINER}/tasks)

    ebegin "Shutting down system in ${CONTAINER}"
    kill -INT ${init_pid}
    eend $?

isn't lxc-kill -n ${CONTAINER} 2 will do the same?

Also "shutting down" action is depend on inittab definition
ca:12345:ctrlaltdel:/sbin/shutdown -r now
In this case INT signal will reboot the container.

    sleep 15

    missingprocs=$(pgrep -P ${init_pid})

This will not catch it as init will get new PID.

    ebegin "Stopping ${CONTAINER}"
    lxc-stop -n ${CONTAINER}
    eend $?

And this will stop newly rebooted container
or in case
ca:12345:ctrlaltdel:/sbin/shutdown -h now
it will stop already STOPPED container.

Thanks.
Comment 1 Diego Elio Pettenò (RETIRED) gentoo-dev 2010-08-02 13:52:46 UTC
Hmm you're right regarding the INT... guess I'll have to see if TERM works as well.
Comment 2 Diego Elio Pettenò (RETIRED) gentoo-dev 2010-08-03 00:37:43 UTC
Actually, I just tested around, and -INT with

ca:12345:ctrlaltdel:/sbin/shutdown -r now

does not cause a restart within the container:

 * Stopping D-BUS system messagebus ...                                                                                                                      [ ok ]
 * Terminating remaining processes ...
 * /etc/init.d/killprocs: send: Bad file descriptor                                                                                                          [ ok ]
 * Killing remaining processes ...                                                                                                                           [ ok ]
 * Saving dependency cache ...                                                                                                                               [ ok ]
INIT: no more processes left in this runlevel

are you sure it does so for you?
Comment 3 Vadim Kuznetsov (RETIRED) gentoo-dev 2010-08-03 01:52:22 UTC
(In reply to comment #2)
> are you sure it does so for you?

Yes, I am sure. Just retested. You gotta start your test from STOPPED state, i.e. edit inittab before you start container. 

If you watch -n 1 lxc-ps ax --lxc, you may actually see
/sbin/rc reboot
instead of 
/sbin/rc shutdown
Comment 4 Diego Elio Pettenò (RETIRED) gentoo-dev 2010-08-03 01:56:25 UTC
Yes, sure, okay.. but it won't arrive to the reboot() syscall, init will stop after all process are gone, unable to do anything else...

AFAICT no init script beside kexec (which is pointless within lxc anyway) changes behaviour depending on shutdown or reboot..
Comment 5 Vadim Kuznetsov (RETIRED) gentoo-dev 2010-08-03 02:17:38 UTC
(In reply to comment #4)
> Yes, sure, okay.. but it won't arrive to the reboot() syscall, init will stop
> after all process are gone, unable to do anything else...

Before kill:
CONTAINER    PID TTY      STAT   TIME COMMAND
gentoo     20350 ?        Ss     0:00 init [3]
gentoo     20759 ?        Ss     0:00 dhcpcd -m 2 eth0
gentoo     20810 ?        Ss     0:00 /usr/sbin/sshd
gentoo     20831 pts/4    Ss+    0:00 /sbin/agetty 38400 console
gentoo     20832 pts/3    Ss+    0:00 /sbin/agetty 38400 tty1 linux

After kill (lxc-kill -n gentoo  2), container like new:
CONTAINER    PID TTY      STAT   TIME COMMAND
gentoo     22721 ?        Ss     0:00 init [3]
gentoo     23123 ?        Ss     0:00 dhcpcd -m 2 eth0
gentoo     23174 ?        Ss     0:00 /usr/sbin/sshd
gentoo     23195 pts/4    Ss+    0:00 /sbin/agetty 38400 console
gentoo     23196 pts/3    Ss+    0:00 /sbin/agetty 38400 tty1 linux

Container went though states:
'gentoo' changed state to [STARTING]
'gentoo' changed state to [RUNNING]
'gentoo' changed state to [STOPPING]
'gentoo' changed state to [STOPPED]
'gentoo' changed state to [STARTING]
'gentoo' changed state to [RUNNING]

> AFAICT no init script beside kexec (which is pointless within lxc anyway)
> changes behaviour depending on shutdown or reboot..
> 
sorry, what?
Comment 6 Diego Elio Pettenò (RETIRED) gentoo-dev 2010-08-03 02:21:15 UTC
Hrmmmm will double-check tomorrow, for now... sleep =_=
Comment 7 Elfenbein, Karsten 2010-12-01 21:01:15 UTC
could you also add a check if the ${container}.log exists before removing the file
Comment 8 Alexander Y. Fomichev 2010-12-27 11:15:58 UTC
i guess everybody knows already so this comment is only to continue discussion: lxc-start restarting container after "shutdown -r" since commit 91480a0f0a62732f3115d556b689d62d574294ae.
http://lxc.git.sourceforge.net/git/gitweb.cgi?p=lxc/lxc;a=commitdiff;h=91480a0f0a62732f3115d556b689d62d574294ae

I think after this patch INT+sleep for n seconds is not so good idea. Probably if we will pull the init till it dies it could make a gap between stop&start short enough, but i'd prefer to have an opportunity to customize shutdown procedure (i.g. for containers without an init). Well, as an alternative we could just send -PWR to container's init which along with appropriate powerfail[now] entry will works too, but not all of distros provide such entry in inittab (really i haven't seen any) so it will not work "out of the box" anyway.

If it will be useful, my own version is here:
https://github.com/gluk/gentoo-init/blob/master/lxc
Comment 9 Markos Chandras (RETIRED) gentoo-dev 2014-04-11 11:20:02 UTC
This version has been removed. Re-open if the bug is still relevant