lxd icon indicating copy to clipboard operation
lxd copied to clipboard

systemctl reload snap.lxd.daemon.service starts stopped instances with boot.auto = true

Open vosdev opened this issue 1 year ago • 5 comments

Required information

  • Distribution: Ubuntu
  • Distribution version: 24.04
  • The output of "snap list --all lxd core20 core22 core24 snapd":
Name    Version      Rev    Tracking       Publisher   Notes
core22  20240904     1621   latest/stable  canonical✓  base,disabled
core22  20241001     1663   latest/stable  canonical✓  base
lxd     6.1-78a3d8f  30130  latest/stable  canonical✓  -
snapd   2.63         21759  latest/stable  canonical✓  snapd

Issue description

Updating LXD's certificates I noticed that instances that were in a Stopped state, changed to Running after issueing systemctl reload snap.lxd.daemon.service.

Steps to reproduce

  1. Stop an instance that has boot.autostart: "true" configured.
  2. systemctl reload snap.lxd.daemon.service
  3. The instance is now running

I did not expect it to change to Running after a reload, I only expect this after a restart.

vosdev avatar Nov 14 '24 13:11 vosdev

This also results in instances auto starting when the daemon is auto-refreshed by snapd. While the docs are fairly clear that boot.autostart is tied to the LXD server's lifetime, I agree that this behavior is sub-optimal in a snap-deployed context.

I suspect that the LXD server currently has no way to tell why it was started; looks like the snap holds on to the start state but I'm reasonably confident we can't expect ${LXD_COMMON}/state to exist in all deployment contexts.

MggMuggins avatar Nov 15 '24 17:11 MggMuggins

LXD should already be able to distinguish between snap restart and snap reload, as it chooses not to stop instances during a reload.

tomponline avatar Nov 15 '24 19:11 tomponline

Yeah, it's based on the signal (SIGTERM for reload and SIGPWR for shutdown). The problem is distinguishing during start how the daemon was shut down; that is, to effectively disable boot.autostart when the daemon was shut down with SIGTERM.

MggMuggins avatar Nov 15 '24 20:11 MggMuggins

Wonder if we can set an env var on stop so its detectabke on start up.

tomponline avatar Nov 15 '24 20:11 tomponline

This also results in instances auto starting when the daemon is auto-refreshed by snapd. While the docs are fairly clear that boot.autostart is tied to the LXD server's lifetime, I agree that this behavior is sub-optimal in a snap-deployed context.

Yeah my LXD snap apparently updated yesterday evening and this morning I found some instances running that weren't running before the update.

vosdev avatar Apr 16 '25 08:04 vosdev