Update local runner lifecycle within client

This commit is contained in:
Chris Roberts 2021-07-26 14:14:41 -07:00 committed by Paul Hinze
parent 572dcc8622
commit cdfcd0dc5b
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
2 changed files with 17 additions and 6 deletions

View File

@ -13,6 +13,7 @@ import (
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
"github.com/hashicorp/vagrant-plugin-sdk/terminal"
configpkg "github.com/hashicorp/vagrant/internal/config"
"github.com/hashicorp/vagrant/internal/runner"
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
"github.com/hashicorp/vagrant/internal/serverclient"
)
@ -36,6 +37,7 @@ type Basis struct {
local bool
localServer bool // True when a local server is created
localRunner *runner.Runner
}
func New(ctx context.Context, opts ...Option) (basis *Basis, err error) {

View File

@ -59,18 +59,27 @@ func (b *Basis) doJob(ctx context.Context, job *vagrant_server.Job, ui terminal.
// In local mode we have to start a runner.
if b.local {
log.Info("local mode, starting local runner")
r, err := b.startRunner()
if err != nil {
return nil, err
if b.localRunner == nil {
log.Info("local mode, starting local runner")
r, err := b.startRunner()
if err != nil {
return nil, err
}
b.localRunner = r
b.cleanup(func() { r.Close() })
}
log.Info("runner started", "runner_id", r.Id())
r := b.localRunner
log.Info("using local runner", "runner_id", r.Id())
// We defer the close so that we clean up resources. Local mode
// always blocks and streams the full output so when doJob exits
// the job is complete.
defer r.Close()
// defer r.Close()
var jobCh chan struct{}