Host OS shutdown/restart = Graceful shutdown & restart of LXD containers?

When the Ubuntu host OS is shutdown and or rebooted are the LXD containers shut down or restarted gracefully as well?

I wanted to make sure that there isn’t something additional I need to configure to make sure that containers shutdown and reboot properly when shutting down or rebooting the host OS.

Yes, on shutdown of the host all containers are sent a shutdown signal to which they have 30s to respond by doing a clean shutdown of the container. After that, if the container is still running, it’ll be killed by LXD.

On startup, all containers which were running at the time the system was shut down will be started back up.

2 Likes

How can I change the 30s value @stgraber?
I think I might be getting data corruption on a DB when restarting the server.

boot.host_shutdown_timeout

1 Like

Thank you @stgraber,
Sounded like a host option at first read, not an instance option…

So, whatever I set at the instance (container) level, both LXD and ultimately the OS, will abide by and wait for that amount of time if it is needed by the instance to do it’s graceful shutdown?

Most distributions have an overall 10min timeout on host shutdown, so if your instance shutdown exceeds that, you may still have a bad time and may need to override the systemd unit.

OK, so if I understood correctly,
Its a LXD option, which is defined at the instance level and the OS will not abide by.
Which means in the end (while under the OS limit) the lxd daemon living on the host will decide if it needs terminating based on the boot.host_shutdown_timeout value on the instance.

When the host shuts down, systemd on the host allows for 10min for LXD to exit before it goes and forcefully kills everything.

As soon as LXD is told the host is shutting down, it tells all the instances to shutdown, then waits boot.host_shutdown_timeout and if the instance isn’t stopped by then, it gets killed by LXD.

If you need boot.host_shutdown_timeout to work with values higher than the host’s systemd timeout, then you need to override the systemd unit of LXD (snap.lxd.daemon.service) to allow for a longer stop timeout.

Understood, thank you very much!