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.
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.
$ 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.
So would you prefer the linked file plus a script that changes it into your suggested wording, or how should I proceed?
Seems the shutdown command is in one of the other files. Let me experiment and see if I can get those to work.
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.
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.
Sounds excellent to me!
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(+)