Commit 9f559cb2 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

common: detect ctrl-c in Provision

parent 28bf6122
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log" "log"
"time"
) )
// StepProvision runs the provisioners. // StepProvision runs the provisioners.
...@@ -22,13 +23,30 @@ func (*StepProvision) Run(state map[string]interface{}) multistep.StepAction { ...@@ -22,13 +23,30 @@ func (*StepProvision) Run(state map[string]interface{}) multistep.StepAction {
hook := state["hook"].(packer.Hook) hook := state["hook"].(packer.Hook)
ui := state["ui"].(packer.Ui) ui := state["ui"].(packer.Ui)
// Run the provisioner in a goroutine so we can continually check
// for cancellations...
log.Println("Running the provision hook") log.Println("Running the provision hook")
if err := hook.Run(packer.HookProvision, ui, comm, nil); err != nil { errCh := make(chan error, 1)
state["error"] = err go func() {
return multistep.ActionHalt errCh <- hook.Run(packer.HookProvision, ui, comm, nil)
} }()
for {
select {
case err := <-errCh:
if err != nil {
state["error"] = err
return multistep.ActionHalt
}
return multistep.ActionContinue return multistep.ActionContinue
case <-time.After(1 * time.Second):
if _, ok := state[multistep.StateCancelled]; ok {
hook.Cancel()
return multistep.ActionHalt
}
}
}
} }
func (*StepProvision) Cleanup(map[string]interface{}) {} func (*StepProvision) Cleanup(map[string]interface{}) {}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment