Skip to content

Commit

Permalink
lxd: Check if instance is already running before attempting to start
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Bolton <mark.bolton@canonical.com>
License: Apache-2.0
  • Loading branch information
boltmark committed Jul 18, 2024
1 parent 15327ce commit 86ad93a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lxd/instances_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 86ad93a

Please sign in to comment.