packer/plugin: Killed bool to avoid panics when killing clients

This commit is contained in:
Mitchell Hashimoto 2013-08-19 23:38:22 -07:00
parent 8b00c82898
commit f68e00085b
7 changed files with 12 additions and 6 deletions

View File

@ -40,7 +40,7 @@ func (b *cmdBuilder) Cancel() {
func (c *cmdBuilder) checkExit(p interface{}, cb func()) { func (c *cmdBuilder) checkExit(p interface{}, cb func()) {
if c.client.Exited() && cb != nil { if c.client.Exited() && cb != nil {
cb() cb()
} else if p != nil { } else if p != nil && !Killed {
log.Panic(p) log.Panic(p)
} }
} }

View File

@ -20,6 +20,10 @@ import (
"unicode" "unicode"
) )
// If this is true, then the "unexpected EOF" panic will not be
// raised throughout the clients.
var Killed = false
// This is a slice of the "managed" clients which are cleaned up when // This is a slice of the "managed" clients which are cleaned up when
// calling Cleanup // calling Cleanup
var managedClients = make([]*Client, 0, 5) var managedClients = make([]*Client, 0, 5)

View File

@ -45,7 +45,7 @@ func (c *cmdCommand) Synopsis() (result string) {
func (c *cmdCommand) checkExit(p interface{}, cb func()) { func (c *cmdCommand) checkExit(p interface{}, cb func()) {
if c.client.Exited() { if c.client.Exited() {
cb() cb()
} else if p != nil { } else if p != nil && !Killed {
log.Panic(p) log.Panic(p)
} }
} }

View File

@ -22,7 +22,7 @@ func (c *cmdHook) Run(name string, ui packer.Ui, comm packer.Communicator, data
func (c *cmdHook) checkExit(p interface{}, cb func()) { func (c *cmdHook) checkExit(p interface{}, cb func()) {
if c.client.Exited() { if c.client.Exited() {
cb() cb()
} else if p != nil { } else if p != nil && !Killed {
log.Panic(p) log.Panic(p)
} }
} }

View File

@ -31,7 +31,7 @@ func (c *cmdPostProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.
func (c *cmdPostProcessor) checkExit(p interface{}, cb func()) { func (c *cmdPostProcessor) checkExit(p interface{}, cb func()) {
if c.client.Exited() { if c.client.Exited() {
cb() cb()
} else if p != nil { } else if p != nil && !Killed {
log.Panic(p) log.Panic(p)
} }
} }

View File

@ -31,7 +31,7 @@ func (c *cmdProvisioner) Provision(ui packer.Ui, comm packer.Communicator) error
func (c *cmdProvisioner) checkExit(p interface{}, cb func()) { func (c *cmdProvisioner) checkExit(p interface{}, cb func()) {
if c.client.Exited() { if c.client.Exited() {
cb() cb()
} else if p != nil { } else if p != nil && !Killed {
log.Panic(p) log.Panic(p)
} }
} }

View File

@ -26,7 +26,9 @@ func setupSignalHandlers(env packer.Environment) {
env.Ui().Error("Interrupt signal received twice. Forcefully exiting now.") env.Ui().Error("Interrupt signal received twice. Forcefully exiting now.")
// Force kill all the plugins // Force kill all the plugins, but mark that we're killing them
// first so that we don't get panics everywhere.
plugin.Killed = true
plugin.CleanupClients() plugin.CleanupClients()
os.Exit(1) os.Exit(1)
}() }()