From 8665ae0afbd85bde0991fb1507326a183199075b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Wed, 3 Jan 2024 18:51:17 -0500 Subject: [PATCH] lxd: Make VM shutdown/reboot exit cleanly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes https://github.com/lxc/incus/issues/256 Signed-off-by: Stéphane Graber Signed-off-by: hamistao License: Apache-2.0 --- lxd/instance_exec.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lxd/instance_exec.go b/lxd/instance_exec.go index ccf4badbfff4..419238be53fb 100644 --- a/lxd/instance_exec.go +++ b/lxd/instance_exec.go @@ -23,6 +23,7 @@ import ( "github.com/canonical/lxd/lxd/cluster" "github.com/canonical/lxd/lxd/db/operationtype" "github.com/canonical/lxd/lxd/instance" + "github.com/canonical/lxd/lxd/instance/drivers" "github.com/canonical/lxd/lxd/instance/instancetype" "github.com/canonical/lxd/lxd/operations" "github.com/canonical/lxd/lxd/request" @@ -289,7 +290,14 @@ func (s *execWs) Do(op *operations.Operation) error { _ = pty.Close() } + // Make VM disconnections (shutdown/reboot) match containers. + if cmdErr == drivers.ErrExecDisconnected { + cmdResult = 129 + cmdErr = nil + } + metadata := shared.Jmap{"return": cmdResult} + err = op.ExtendMetadata(metadata) if err != nil { return err