[lxc-users] Graceful Shutdown/Reboot
Brett 11
open_side111 at hotmail.com
Wed Feb 8 23:25:39 UTC 2017
I suggest you to look for shutdown messages in the service log file, e.g. /var/log/mysql/error.log . I expect all sane distributions to at least try to stop all containers (as well as other processes) gracefully and give them some time to finish their work. However, I suppose it is possible to install and run LXC in a way that containers won't close correctly, so it makes sense to check first.
With Best Regards,
Marat Khalili
--
Thanks Marat for the suggestion. But I really want a 'for sure' mechanism to manage this, so...
I came to the conclusion of using systemd to do this for me with the help of a user on the LXC sub on reddit.
Here's what I came up with in case it can help others..
Systemd has default '.service' profiles for LXC containers that I tweaked. The big thing was it was stopping the container with SIGPWR which wasn't working for me in Debian Stretch. So a added 'lxc-stop' and a 'sleep' for a delayed start after boot.
cat /etc/systemd/system/multi-user.target.wants/lxc at CONTAINER_NAME.service
[Unit]
Description=LXC Container: %i
# This pulls in apparmor, dev-setup, lxc-net
After=lxc.service
Wants=lxc.service
Documentation=man:lxc-start man:lxc
[Service]
Type=simple
# KillMode=mixed
# KillSignal=SIGPWR
ExecStop=/usr/bin/lxc-stop -n %i
TimeoutStopSec=120s
ExecStartPre=/bin/sleep 15
ExecStart=/usr/bin/lxc-start -F -n %i
# Environment=BOOTUP=serial
# Environment=CONSOLETYPE=serial
Delegate=yes
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target
More information about the lxc-users
mailing list