Skip to content

Commit

Permalink
Instruct liblxc to use the lxd-stophook wrapper in the bin directory …
Browse files Browse the repository at this point in the history
…of the snap instead of sbin (#14526)

This is the historical path where the lxd binary used to be, but it was
replaced with a small wrapper script which redirects the stop hook
requests to lxd-user (which is statically compiled) so that stop hook
notifications to LXD work when the snap base version is changed.

Related to canonical/lxd-pkg-snap#635

Fixes #13331
  • Loading branch information
tomponline authored Nov 25, 2024
2 parents 752f289 + cce0914 commit 43b7a9a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lxd/instance/drivers/driver_lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,14 +937,24 @@ func (d *lxc) initLXC(config bool) (*liblxc.Container, error) {
return nil, err
}

// Instruct liblxc to use the lxd-stophook wrapper in the bin directory of the snap instead of lxd in sbin.
// This is the historical path where the lxd binary used to be, but it was replaced with a small wrapper
// script which redirects the stop hook requests to lxd-user (which is statically compiled) so that stop
// hook notifications to LXD work when the snap base version is changed.
lxdStopHookPath := d.state.OS.ExecPath
if shared.InSnap() && strings.HasSuffix(lxdStopHookPath, "sbin/lxd") {
// Convert /snap/lxd/current/sbin/lxd into /snap/lxd/current/bin/lxd.
lxdStopHookPath = strings.TrimSuffix(lxdStopHookPath, "sbin/lxd") + "bin/lxd"
}

// Call the onstopns hook on stop but before namespaces are unmounted.
err = lxcSetConfigItem(cc, "lxc.hook.stop", fmt.Sprintf("%s callhook %s %s %s stopns", d.state.OS.ExecPath, shared.VarPath(""), strconv.Quote(d.Project().Name), strconv.Quote(d.Name())))
err = lxcSetConfigItem(cc, "lxc.hook.stop", fmt.Sprintf("%s callhook %s %s %s stopns", lxdStopHookPath, shared.VarPath(""), strconv.Quote(d.Project().Name), strconv.Quote(d.Name())))
if err != nil {
return nil, err
}

// Call the onstop hook on stop.
err = lxcSetConfigItem(cc, "lxc.hook.post-stop", fmt.Sprintf("%s callhook %s %s %s stop", d.state.OS.ExecPath, shared.VarPath(""), strconv.Quote(d.Project().Name), strconv.Quote(d.Name())))
err = lxcSetConfigItem(cc, "lxc.hook.post-stop", fmt.Sprintf("%s callhook %s %s %s stop", lxdStopHookPath, shared.VarPath(""), strconv.Quote(d.Project().Name), strconv.Quote(d.Name())))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 43b7a9a

Please sign in to comment.