Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 729930 - app-emulation/lxd-4.0.x - lxd.service fails to shut down properly
Summary: app-emulation/lxd-4.0.x - lxd.service fails to shut down properly
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Erik Mackdanz
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2020-06-27 18:33 UTC by Mattias Winther
Modified: 2020-07-13 07:16 UTC (History)
1 user (show)

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


Attachments
Patch for files/lxd.service (lxd.service.patch,402 bytes, patch)
2020-06-27 18:33 UTC, Mattias Winther
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mattias Winther 2020-06-27 18:33:48 UTC
Created attachment 646868 [details, diff]
Patch for files/lxd.service

While debugging an unrelated issue, I noticed that my machine had to SIGKILL a lot of processes during reboots. Looking into it, it seems that the systemd service doesn't try to shut down lxd properly.

According to https://github.com/lxc/lxd/issues/4277#issuecomment-368037914, an lxd shutdown command should be run as part of the shutdown, and after adding it to my lxd.service the containers now shut down as they should.

Attached patch as I'm unclear on how to provide a PR. Please let me know if there are any further questions.
Comment 1 Joonas Niilola gentoo-dev 2020-07-01 12:45:22 UTC
In that issue they recommended to use this service file, 
https://raw.githubusercontent.com/lxc/lxd-pkg-ubuntu/dpm-bionic/debian/lxd.service

as I don't have lxd running on systemd, could you report how well that works for you? It'd be best if we didn't have to carry around our own files, but could rely on existing, working ones.
Comment 2 Joonas Niilola gentoo-dev 2020-07-01 12:48:28 UTC
$ diff -Naur /lib/systemd/system/lxd.service ./lxd.service 
--- /lib/systemd/system/lxd.service	2020-06-26 12:52:07.052027037 +0300
+++ ./lxd.service	2020-07-01 15:43:34.593642991 +0300
@@ -1,10 +1,21 @@
 [Unit]
-Description=Container hypervisor based on LXC
+Description=LXD - main daemon
+After=network-online.target openvswitch-switch.service lxcfs.service lxd.socket
+Requires=network-online.target lxcfs.service lxd.socket
+Documentation=man:lxd(1)
 
 [Service]
-ExecStart=/usr/sbin/lxd --group lxd
+EnvironmentFile=-/etc/environment
+ExecStartPre=@LIBEXECDIR@/lxc/lxc-apparmor-load
+ExecStart=/usr/bin/lxd --group lxd --logfile=/var/log/lxd/lxd.log
+ExecStartPost=/usr/bin/lxd waitready --timeout=600
 KillMode=process
+TimeoutStartSec=600s
+TimeoutStopSec=30s
 Restart=on-failure
+LimitNOFILE=1048576
+LimitNPROC=infinity
+TasksMax=infinity
 
 [Install]
-WantedBy=multi-user.target
+Also=lxd-containers.service lxd.socket

----------

I can see "+ExecStartPre=@LIBEXECDIR@/lxc/lxc-apparmor-load" not working for everyone, it needs app-emulation/lxc[apparmor] installed.
Comment 3 Mattias Winther 2020-07-02 20:28:31 UTC
So would you prefer the linked file plus a script that changes it into your suggested wording, or how should I proceed?
Comment 4 Mattias Winther 2020-07-02 20:32:09 UTC
Seems the shutdown command is in one of the other files. Let me experiment and see if I can get those to work.
Comment 5 Mattias Winther 2020-07-12 10:03:46 UTC
Fiddled around, and ended up replacing my own service file with the ubuntu one altogether, and it seems to work for me as written. I still get a real early filesystem unmount and a bunch of waiting time, but no more console errors about having to kill a bunch of processes, so I would assume it does work.

> I can see "+ExecStartPre=@LIBEXECDIR@/lxc/lxc-apparmor-load" not working for everyone, it needs app-emulation/lxc[apparmor] installed.

Since apparmor was assumed in all the lxd docs I've read, I have it installed, so that line didn't provide a problem for me.
Comment 6 Joonas Niilola gentoo-dev 2020-07-12 10:24:21 UTC
Thanks for reporting in.

I was going to start using the ubuntu provided systemd files for the next version bump regardless, but now I'm thinking of doing a revbump for 4.0.2 with this update.

There should be a way to detect whether lxc[apparmor] is installed, or then I'll add 'apparmor' IUSE to lxd which adds the line to these service files.
Comment 7 Mattias Winther 2020-07-12 17:15:49 UTC
Sounds excellent to me!
Comment 8 Larry the Git Cow gentoo-dev 2020-07-13 07:16:10 UTC
The bug has been closed via the following commit(s):

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

commit ebe0bdd0661553ba0b8657de0d51db56c1241f67
Author:     Joonas Niilola <juippis@gentoo.org>
AuthorDate: 2020-07-13 06:56:21 +0000
Commit:     Joonas Niilola <juippis@gentoo.org>
CommitDate: 2020-07-13 07:16:00 +0000

    app-emulation/lxd: systemd related fixes #729930
    
     - systemd service files provided by upstream,
     - update kernel check CONFIG_NF_NAT_MASQUERADE_IPV4 to NF_NAT_MASQUERADE.
    
    Closes: https://bugs.gentoo.org/729930
    Signed-off-by: Joonas Niilola <juippis@gentoo.org>

 app-emulation/lxd/files/lxd-4.0.0.service          |  20 ++
 app-emulation/lxd/files/lxd-4.0.0.socket           |  12 ++
 app-emulation/lxd/files/lxd-4.0.0_apparmor.service |  21 ++
 .../lxd/files/lxd-containers-4.0.0.service         |  16 ++
 app-emulation/lxd/lxd-4.0.2-r1.ebuild              | 211 +++++++++++++++++++++
 5 files changed, 280 insertions(+)