diff --git a/config.go b/config.go index 365c8a59b..99df10529 100644 --- a/config.go +++ b/config.go @@ -66,38 +66,45 @@ func (c *config) LoadBuilder(name string) (packer.Builder, error) { return nil, nil } - return plugin.Builder(exec.Command(bin)) + return c.pluginClient(bin).Builder() } // This is a proper packer.CommandFunc that can be used to load packer.Command // implementations from the defined plugins. func (c *config) LoadCommand(name string) (packer.Command, error) { log.Printf("Loading command: %s\n", name) - commandBin, ok := c.Commands[name] + bin, ok := c.Commands[name] if !ok { log.Printf("Command not found: %s\n", name) return nil, nil } - return plugin.Command(exec.Command(commandBin)) + return c.pluginClient(bin).Command() } // This is a proper implementation of packer.HookFunc that can be used // to load packer.Hook implementations from the defined plugins. func (c *config) LoadHook(name string) (packer.Hook, error) { log.Printf("Loading hook: %s\n", name) - return plugin.Hook(exec.Command(name)) + return c.pluginClient(name).Hook() } // This is a proper packer.ProvisionerFunc that can be used to load // packer.Provisioner implementations from defined plugins. func (c *config) LoadProvisioner(name string) (packer.Provisioner, error) { log.Printf("Loading provisioner: %s\n", name) - provBin, ok := c.Provisioners[name] + bin, ok := c.Provisioners[name] if !ok { log.Printf("Provisioner not found: %s\n", name) return nil, nil } - return plugin.Provisioner(exec.Command(provBin)) + return c.pluginClient(bin).Provisioner() +} + +func (c *config) pluginClient(path string) *plugin.Client { + var config plugin.ClientConfig + config.Cmd = exec.Command(path) + config.Managed = true + return plugin.NewClient(&config) } diff --git a/packer/plugin/client.go b/packer/plugin/client.go index 8defc5a49..6890875f7 100644 --- a/packer/plugin/client.go +++ b/packer/plugin/client.go @@ -42,7 +42,7 @@ type ClientConfig struct { // plugin package or not. If true, then by calling CleanupClients, // it will automatically be cleaned up. Otherwise, the client // user is fully responsible for making sure to Kill all plugin - // clients. + // clients. By default the client is _not_ managed. Managed bool // The minimum and maximum port to use for communicating with