Comparing the log files from ‘lxc stop [cont]’ vs 'lxc exec [cont] – poweroff` they both start and end differently, but share a lot in the middle.
The former starts with
systemd[1]: Received SIGRTMIN+3.
systemd[1]: Reached target Unmount All Filesystems.
...
whereas the latter doesn’t “Umount All Filesystems” until much later after other tasks. It could be that systemd is treating Received SIGRTMIN+3
as an emergency power loss and therefore unmounts the filesystems as soon as possible to minimize filesystem damage. Even if that causes some problem in the shutdown.
They finish up differently. The “poweroff” method ending is clean:
systemd[1]: Stopped Network Service.
systemd[1]: Stopped Update UTMP about System Boot/Shutdown.
systemd[1]: Stopped Create Volatile Files and Directories.
dhclient[127]: Killed old client process
ifdown[112]: Killed old client process
resulting in a clean shutdown.
In contrast with the “stop” method some processes are restarting themselves while systemd seems to be both starting and stopping:
systemd[1]: Stopped Network Service.
systemd[1]: Stopped Update UTMP about System Boot/Shutdown.
stretch-cc systemd[1]: Stopped Create Volatile Files and Directories.
stretch-cc dhclient[180]: Killed old client process
ifdown[165]: Killed old client process
so far so good, but then it continues into a final zombie state:
dhclient[180]: Internet Systems Consortium DHCP Client 4.3.5
ifdown[165]: Internet Systems Consortium DHCP Client 4.3.5
ifdown[165]: Copyright 2004-2016 Internet Systems Consortium.
ifdown[165]: All rights reserved.
ifdown[165]: For info, please visit https://www.isc.org/software/dhcp/
dhclient[180]: Copyright 2004-2016 Internet Systems Consortium.
dhclient[180]: All rights reserved.
dhclient[180]: For info, please visit https://www.isc.org/software/dhcp/
dhclient[180]:
dhclient[180]: Listening on LPF/eth0/00:16:3e:e9:b8:9f
ifdown[165]: Listening on LPF/eth0/00:16:3e:e9:b8:9f
ifdown[165]: Sending on LPF/eth0/00:16:3e:e9:b8:9f
ifdown[165]: Sending on Socket/fallback
dhclient[180]: Sending on LPF/eth0/00:16:3e:e9:b8:9f
dhclient[180]: Sending on Socket/fallback
dhclient[180]: DHCPRELEASE on eth0 to 10.185.64.1 port 67
ifdown[165]: DHCPRELEASE on eth0 to 10.185.64.1 port 67
systemd[1]: Reached target Final Step.
systemd[1]: Stopped Raise network interfaces.
systemd[1]: Stopped Apply Kernel Variables.
systemd[1]: systemd-networkd.service: Failed to reset devices.list: Operation not permitted
systemd[1]: systemd-networkd.service: Failed to set invocation ID on control group /system.slice/systemd-networkd.service, ignoring: Operation not permitted
systemd[1]: Starting Network Service...
systemd[1]: Stopped target Local File Systems.
systemd[1]: Stopped target Local File Systems (Pre).
systemd[1]: Stopped Create Static Device Nodes in /dev.
systemd[1]: Stopped Remount Root and Kernel File Systems.
systemd[1]: Stopped Load Kernel Modules.
systemd-networkd[192]: Enumeration completed
systemd-networkd[192]: eth0: Removing non-existent address: 10.185.64.200/24 (valid forever)
systemd[1]: Started Network Service.
systemd-networkd[192]: eth0: Removing non-existent address: fd42:f2c5:781c:6810:216:3eff:fee9:b89f/64 (valid for 59min 59s)
systemd-networkd[192]: eth0: Removing non-existent address: fe80::216:3eff:fee9:b89f/64 (valid forever)
systemd[1]: Reached target Network.
If we suppose this behavior is not an accident, then it can be accounted for supposing that systemd’s goal is only to unmount media to prevent data corruption and NOT to shut down. That supposition seems plausible when reading between the lines of this discussion.
So in the Debian/stretch I got from linuxcontainers, sigpwr.target
is an empty stub. Linking it to ‘poweroff.target’ doesn’t have any effect. I think the current response to SIGRTMIN+3 is baked into systemd compiled code - maybe it can’t be overridden?.
Debian 8/9 are going to be around for awhile. Maybe an lxd/lxc configuration option to translate ‘lxc stop [cont]’ into a poweroff command would be practical.
Otherwise, if there were a method to change the systemd configuration that didn’t depend upon systemd not breaking that method in future releases, that would be a workaround.