Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 770511 - app-emulation/lxd: all containers in cluster are stopped on shutdown
Summary: app-emulation/lxd: all containers in cluster are stopped on shutdown
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Joonas Niilola
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-14 14:23 UTC by Ogelpre
Modified: 2021-02-18 17:35 UTC (History)
3 users (show)

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


Attachments
rework on openrc init script (0001-app-emulation-lxd-use-signals-in-openrc-script.patch,1.67 KB, patch)
2021-02-17 10:02 UTC, Ogelpre
Details | Diff
Updated patch for openrc init scripts (0001-app-emulation-lxd-use-signals-in-openrc-script.patch,1.67 KB, patch)
2021-02-17 10:04 UTC, Ogelpre
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ogelpre 2021-02-14 14:23:34 UTC
I am running a LXD cluster with four nodes on gentoo. I am using OpenRC as init system. I noticed that all containers in a cluster are stopped if I restart one node.



Reproducible: Always

Steps to Reproduce:
1. Build a LXD cluster
2. distribute containers on LXD nodes
3. shutdown/reboot a node
Actual Results:  
All containers in the cluster are stopped.

Expected Results:  
Cluster on other nodes shouldn't stopped on shutdown of a single node.

I was able to trace it back to the following lines in the openrc init script:

	lxc stop --all --timeout $TIMEOUT >/dev/null 2>&1
	if [[ ${?} -ne 0 ]]; then
		lxc stop --all --force || eerror "Could not stop all containers."
	fi

lxc stop --all does affect all containers an all nodes. Those four lines should be removed, because the following "lxd shutdown" already stops only local containers.
Comment 1 Larry the Git Cow gentoo-dev 2021-02-16 08:29:49 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=9f88706ccb6f6582b42ff558d679ebe39bc6fb93

commit 9f88706ccb6f6582b42ff558d679ebe39bc6fb93
Author:     Joonas Niilola <juippis@gentoo.org>
AuthorDate: 2021-02-16 08:27:59 +0000
Commit:     Joonas Niilola <juippis@gentoo.org>
CommitDate: 2021-02-16 08:29:42 +0000

    app-emulation/lxd: don't shutdown all cluster instances with service
    
    Closes: https://bugs.gentoo.org/770511
    Signed-off-by: Joonas Niilola <juippis@gentoo.org>

 app-emulation/lxd/files/lxd-4.0.0.initd            | 25 +++-------------------
 .../{lxd-4.0.4-r5.ebuild => lxd-4.0.4-r6.ebuild}   |  0
 2 files changed, 3 insertions(+), 22 deletions(-)
Comment 2 Joonas Niilola gentoo-dev 2021-02-16 08:37:20 UTC
This should do it, seems to work for me.
Comment 3 Ogelpre 2021-02-16 11:21:49 UTC
Close. But now containers are not shutdown safely on system shutdown/restart. On system restart/shutdown ([[ ${RC_GOINGDOWN} = YES ]] || [[ ${RC_REBOOT} = YES ]]) "lxd shutdown" should be executed to inform init systems in containers.
Comment 4 Joonas Niilola gentoo-dev 2021-02-16 11:37:29 UTC
(In reply to Ogelpre from comment #3)
> Close. But now containers are not shutdown safely on system
> shutdown/restart. 

What problems does this bring? I haven't noticed anything weird yet.

Would this work ok?

diff --git a/app-emulation/lxd/files/lxd-4.0.0.initd b/app-emulation/lxd/files/lxd-4.0.0.initd
index 1cd4da1840b..baec86805c6 100644
--- a/app-emulation/lxd/files/lxd-4.0.0.initd
+++ b/app-emulation/lxd/files/lxd-4.0.0.initd
@@ -29,8 +29,12 @@ start() {
 }
 
 stop() {
-       ebegin "Stopping lxd service (but not containers)."
-       start-stop-daemon --stop --quiet -R TERM/45 -p ${PIDFILE}
-       rm -f ${PIDFILE}
-       eend ${?}
+       if [[ ${RC_GOINGDOWN} = YES ]] || [[ ${RC_REBOOT} = YES ]]; then
+               "${DAEMON}" shutdown
+               rm -f ${PIDFILE}
+       else
+               ebegin "Stopping lxd service (but not containers)."
+               start-stop-daemon --stop --quiet -R TERM/45 -p ${PIDFILE}
+               eend ${?}
+       fi
 }
Comment 5 Joonas Niilola gentoo-dev 2021-02-16 12:17:55 UTC
https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=43b0f09708ca0ee5fb22bec6f3c5320b26c8b535 pushed the proposal, it works just as good to me as the previous one.
Comment 6 Ogelpre 2021-02-16 12:54:31 UTC
This change works. The difference is the following: If you upgrade LXD you can kill the daemon and start again. (restart daemon without stopping containers) The containers will keep running and the new LXD process will recognize the running containers. The containers will not restarted.

If you do a lxd shutdown all containers will be shut. seamless upgrading of LXD is not possible.

Alternatively we could implement a "reload" option which will restart LXD without shutting down containers.
Comment 7 Joonas Niilola gentoo-dev 2021-02-17 09:07:41 UTC
Thanks for confirming. 

I'm up for any changes to init.d scripts if they are provided, as I'm using openrc on my main desktop with lxd, and would not want to break it for testing.

I think we're pretty much the only distro running lxd with openrc out there so no help from neighbours?
Comment 8 Ogelpre 2021-02-17 10:02:09 UTC
Created attachment 687213 [details, diff]
rework on openrc init script

Alpine Linux uses OpenRC, too. But they have just a minimal configuration:
https://git.alpinelinux.org/aports/tree/testing/lxd/lxd.initd

In LXD manuals I found information about the daemon behavior on different signals:
https://lxd.readthedocs.io/en/latest/daemon-behavior/

Based on that information I did a rework of the init script and attached it.
Comment 9 Ogelpre 2021-02-17 10:04:57 UTC
Created attachment 687216 [details, diff]
Updated patch for openrc init scripts

Sorry, I had messed up ebgin messages. Should be fixed now.
Comment 10 Joonas Niilola gentoo-dev 2021-02-17 12:00:39 UTC
Thank you! I will run this for a day or two and if nothing weird shows up, merge.
Comment 11 Larry the Git Cow gentoo-dev 2021-02-18 17:35:07 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6ea96b2080d0903324e22a39400d23f1c7e1f71c

commit 6ea96b2080d0903324e22a39400d23f1c7e1f71c
Author:     Benedikt Neuffer <gentoo@itfriend.de>
AuthorDate: 2021-02-17 09:54:29 +0000
Commit:     Joonas Niilola <juippis@gentoo.org>
CommitDate: 2021-02-18 17:35:01 +0000

    app-emulation/lxd: use signals in openrc script
    
    Rework on openrc script to use signals to communicate with the LXD daemon.
    
    Bug: https://bugs.gentoo.org/770511
    Package-Manager: Portage-3.0.14, Repoman-3.0.2
    Signed-off-by: Benedikt Neuffer <ogelpre@itfriend.de>
    Closes: https://bugs.gentoo.org/770511
    Signed-off-by: Joonas Niilola <juippis@gentoo.org>

 app-emulation/lxd/files/lxd-4.0.0.initd | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

Additionally, it has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6ea96b2080d0903324e22a39400d23f1c7e1f71c

commit 6ea96b2080d0903324e22a39400d23f1c7e1f71c
Author:     Benedikt Neuffer <gentoo@itfriend.de>
AuthorDate: 2021-02-17 09:54:29 +0000
Commit:     Joonas Niilola <juippis@gentoo.org>
CommitDate: 2021-02-18 17:35:01 +0000

    app-emulation/lxd: use signals in openrc script
    
    Rework on openrc script to use signals to communicate with the LXD daemon.
    
    Bug: https://bugs.gentoo.org/770511
    Package-Manager: Portage-3.0.14, Repoman-3.0.2
    Signed-off-by: Benedikt Neuffer <ogelpre@itfriend.de>
    Closes: https://bugs.gentoo.org/770511
    Signed-off-by: Joonas Niilola <juippis@gentoo.org>

 app-emulation/lxd/files/lxd-4.0.0.initd | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)