From 86ad93a96239959ef53eceee076d296d8c08bc33 Mon Sep 17 00:00:00 2001 From: Mark Bolton Date: Wed, 17 Jul 2024 18:31:03 -0700 Subject: [PATCH] lxd: Check if instance is already running before attempting to start Signed-off-by: Mark Bolton License: Apache-2.0 --- lxd/instances_post.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lxd/instances_post.go b/lxd/instances_post.go index b6953e8f8fee..1fc0824aebcf 100644 --- a/lxd/instances_post.go +++ b/lxd/instances_post.go @@ -1504,16 +1504,22 @@ func clusterCopyContainerInternal(s *state.State, r *http.Request, source instan return createFromMigration(s, nil, projectName, profiles, req) } +// instanceCreateFinish finalizes the creation process of an instance by starting it based on +// the Start field of the request. func instanceCreateFinish(s *state.State, req *api.InstancesPost, args db.InstanceArgs) error { if req == nil || !req.Start { return nil } - // Start the instance. + // Load instance and start if not already running. inst, err := instance.LoadByProjectAndName(s, args.Project, args.Name) if err != nil { return fmt.Errorf("Failed to load the instance: %w", err) } + if inst.IsRunning() { + return nil + } + return inst.Start(false) }