Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 530896 - app-containers/lxc - add support for stateful container and flexible settings for start/stop to init script
Summary: app-containers/lxc - add support for stateful container and flexible settings...
Status: IN_PROGRESS
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal with 2 votes (vote)
Assignee: Joonas Niilola
URL:
Whiteboard:
Keywords:
: 525956 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-11-27 17:34 UTC by mike
Modified: 2022-01-01 11:11 UTC (History)
13 users (show)

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


Attachments
/etc/conf.d/lxc (kxc.confd.4,1.39 KB, text/plain)
2014-11-27 17:36 UTC, mike
Details
/etc/init.d/lxc (lxc.initd.4,5.84 KB, text/plain)
2014-11-27 17:37 UTC, mike
Details
/etc/init.d/lxc (lxc.initd.4,5.84 KB, text/plain)
2014-11-27 17:45 UTC, mike
Details
/etc/init.d/lxc (lxc.initd.4,5.88 KB, text/plain)
2014-11-27 17:46 UTC, mike
Details
/etc/init.d/lxc (lxc.initd.4,5.88 KB, text/plain)
2014-11-27 18:18 UTC, mike
Details
/etc/init.d/lxc (lxc.initd.4,6.41 KB, text/plain)
2014-12-24 00:56 UTC, mike
Details
the difference beween original script from portage and the proposed version (file_530896.txt,11.36 KB, patch)
2015-01-05 14:48 UTC, mike
Details | Diff
/etc/init.d/lxc (file_530896.txt,6.99 KB, text/plain)
2015-06-14 22:49 UTC, mike
Details
/etc/conf.d/lxc (file_530896.txt,1.55 KB, text/plain)
2015-06-14 22:51 UTC, mike
Details
the difference beween original script from portage and the proposed version (lxc.initd.diff,10.40 KB, patch)
2015-06-14 22:55 UTC, mike
Details | Diff
the difference beween original script from portage and the proposed version (lxc.initd.diff,10.80 KB, patch)
2015-06-14 22:59 UTC, mike
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description mike 2014-11-27 17:34:53 UTC
The current version doesn't allow to flexible configure the start and stop setting of the container
also it doesn't allow to know when the container was stopped


Reproducible: Always
Comment 1 mike 2014-11-27 17:36:38 UTC
Created attachment 390410 [details]
/etc/conf.d/lxc
Comment 2 mike 2014-11-27 17:37:24 UTC
Created attachment 390412 [details]
/etc/init.d/lxc
Comment 3 mike 2014-11-27 17:38:43 UTC
My solution should solve these problems
Comment 4 mike 2014-11-27 17:45:05 UTC
Created attachment 390414 [details]
/etc/init.d/lxc
Comment 5 mike 2014-11-27 17:46:45 UTC
Created attachment 390416 [details]
/etc/init.d/lxc
Comment 6 mike 2014-11-27 18:18:40 UTC
Created attachment 390418 [details]
/etc/init.d/lxc

corrected typos
Comment 7 Markos Chandras (RETIRED) gentoo-dev 2014-12-20 13:35:03 UTC
Please attach diffs to make review easier. Please also describe what problem are you are trying to solve in details. Give me an example scenario to understand it.
Comment 8 Markos Chandras (RETIRED) gentoo-dev 2014-12-20 13:36:57 UTC
*** Bug 525956 has been marked as a duplicate of this bug. ***
Comment 9 mike 2014-12-24 00:56:38 UTC
Created attachment 392298 [details]
/etc/init.d/lxc

some trivial fixes
Comment 10 mike 2014-12-24 01:04:54 UTC
(In reply to Markos Chandras from comment #7)
> Please attach diffs to make review easier. 

======================
# diff -su /usr/portage/app-emulation/lxc/files/lxc.initd.3 /etc/init.d/lxc  |grep -cE '^ [^#]'
9
# wc -l /usr/portage/app-emulation/lxc/files/lxc.initd.3 /etc/init.d/lxc
 137 /usr/portage/app-emulation/lxc/files/lxc.initd.3
 177 /etc/init.d/lxc
----------------------
differences TOO MUCH. In fact, the script is being rewritten from scratch.
I don't think that diff help to make review


> Please also describe what problem are you are trying to solve in details.
> Give me an example scenario to understand it.

ok. I'll try.
Let's look at lxc.initd.3:

======================
checkconfig() {
...
        utsname=$(lxc_get_var lxc.utsname)
        if [ ${CONTAINER} != ${utsname} ]; then
eerror "You should use the same name for the service and the"
            eerror "container. Right now the container is called ${utsname}"
            return 1
        fi
...
----------------------
for what this is? that terrible will happen if they will be different?
maybe utsname is used here /sys/fs/cgroup/cpuset/lxc/NAME ?
not. there is used value from parameter --name=NAME
you can check it out.
it is an unnecessary restriction.

======================
...
start() {
        checkconfig || return 1
        rm /var/log/lxc/${CONTAINER}.log

        rootpath=$(lxc_get_var lxc.rootfs)

        # Check the format of our init and the chroot's init, to see
        # if we have to use linux32 or linux64; always use setarch
        # when required, as that makes it easier to deal with
        # x32-based containers.
        case $(scanelf -BF '%a#f' ${rootpath}/sbin/init) in
                EM_X86_64)      setarch=linux64;;
                EM_386)         setarch=linux32;;
        esac

        ebegin "Starting ${CONTAINER}"
        env -i ${setarch} $(type -p lxc-start) -l WARN -n ${CONTAINER} -f ${CONFIGFILE} -d -o /var/log/lxc/${CONTAINER}.log
        sleep 0.5

        # lxc-start -d will _always_ report a correct startup, even if it
        # failed, so rather than trust that, check that the cgroup exists.
        [ -d /sys/fs/cgroup/cpuset/lxc/${CONTAINER} ]
        eend $?
}
...
======================
this script hopelessly outdated.
* > rootpath=$(lxc_get_var lxc.rootfs)
  what if I don't use lxc.rootfs in config? what if I include this parameter from other config by lxc.include?
  rootpath will get a blank value? and below we will get archtecture of host system?
  What if, for any reson, I want to use own shell instead of /sbin/init?
  This test makes no sense. As far as I know, lxc-start perfectly launches himself x86 code on x86_64 platform
* What if previeusly container stopped with some errors on start and directory /sys/fs/cgroup/cpuset/lxc/${CONTAINER} is not retired?
  in this case, will be created directories /sys/fs/cgroup/{cpuset,<and other>}/lxc/${CONTAINER}-1
  and so forth sequentially
  in which case you should never check these directories, or check them just before the lxc-start yet
* what if I need to configure LOGLEVEL, or set --console-log
  lxc-start has a lot of parameters, but the script does not allow them to easily change individually for each container.
  I can't even use somthink like this
  alias lxc-start='lxc-start <my own parameters>'
  becouse of $(type -p lxc-start)
* what if container wlii stop?
  how OpenRC will know about it?
  lxc-start HAS PARAMETER --pidfile, but it is not used!! 


What about this bugs:
 https://bugs.gentoo.org/show_bug.cgi?id=525956
 https://bugs.gentoo.org/show_bug.cgi?id=416643


My script solves all these problems.
Maybe, my English too bad to correctly write documentation. I know, comments on my lxc.confd ,ust be more complete
Maybe some functions, such as freeze/unfreeze/attach/info unnecessary in init script(I thought that they may be useful in some situations)
Maybe some code design can be made better, but this script is definitely better than what is used now
just read it
Comment 11 mike 2015-01-05 14:48:25 UTC
Created attachment 393250 [details, diff]
the difference beween original script from portage and the proposed version

> Please attach diffs to make review easier. 

I added diff. I hope this helps to make review easier.
Comment 12 Adrien D 2015-03-18 23:06:27 UTC
The bug status is UNCONFIRMED, but i confirm the bug on my Gentoo.

lxc.lxcpath not read.
Comment 13 Markos Chandras (RETIRED) gentoo-dev 2015-03-19 08:46:54 UTC
Well i can review the patches but I can't test them since I am using systemd everywhere so I am more than happy to commit them as-is if that works for you
Comment 14 mike 2015-03-19 13:29:54 UTC
> I am more than happy to commit them as-is if that works for you
yes, this work for me since I published it here
now I'm don't use all variables like a rc_lxc__lxcpath or rc_lxc_..timeout, but before writing here, I tried test all of them.

what I'm not sure - is the quality of comments in English in files lxc.confd and lxc.initd
Unfortunately, my English is poor
I hope that there are interested people who will verify literacy of comments
Comment 15 Markos Chandras (RETIRED) gentoo-dev 2015-03-21 10:34:16 UTC
I tried to apply the patches by they no longer apply on top of lxc.initd.3. Can you please have a look and create new patches based on the latest files in the tree? Thanks
Comment 16 mike 2015-06-14 22:49:23 UTC
Created attachment 405162 [details]
/etc/init.d/lxc

* fixed bug with lxcpath
* added possibility to use lxc-execute instead lxc-start to run any command instead /sbin/init
* I hope that reading this script is now a little easier
Comment 17 mike 2015-06-14 22:51:47 UTC
Created attachment 405164 [details]
/etc/conf.d/lxc

added example of variable rc_lxc_foo_bar__linuxrc
this variable may be used to run with lxc-execute
Comment 18 mike 2015-06-14 22:55:57 UTC
Created attachment 405166 [details, diff]
the difference beween original script from portage and the proposed version
Comment 19 mike 2015-06-14 22:59:49 UTC
Created attachment 405168 [details, diff]
the difference beween original script from portage and the proposed version

previous diff was bad
Comment 20 Markos Chandras (RETIRED) gentoo-dev 2015-06-18 16:59:32 UTC
Thanks for the diff. However, it's more complex than I thought so it will take a bit of time for me to process it.
Comment 21 Markos Chandras (RETIRED) gentoo-dev 2015-06-20 11:25:25 UTC
Can you please write a simple post_pkginst() message to explain to users how to migrate their containers the new init.d file (assuming there are migration steps).
Comment 22 Markos Chandras (RETIRED) gentoo-dev 2015-06-20 11:30:23 UTC
Furthermore, does it make sense for you to try and upstream these files? The LXC project already has various init files (not for Gentoo unfortunately) but it would be nice to have these files in the upstream repository.

https://github.com/lxc/lxc/tree/master/config/init

Anyway, that's not critical, just a NiceToHave thing.