Commit 3956b3a5 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

command/build: Cancel builds when interrupted

parent 94cfe39a
...@@ -5,6 +5,8 @@ import ( ...@@ -5,6 +5,8 @@ import (
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"io/ioutil" "io/ioutil"
"log" "log"
"os"
"os/signal"
"strings" "strings"
"sync" "sync"
) )
...@@ -112,6 +114,29 @@ func (c Command) Run(env packer.Environment, args []string) int { ...@@ -112,6 +114,29 @@ func (c Command) Run(env packer.Environment, args []string) int {
}() }()
} }
// Handle signals
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt)
go func() {
<-sigCh
log.Println("Interrupted! Cancelling builds...")
var wg sync.WaitGroup
for _, b := range builds {
wg.Add(1)
go func() {
defer wg.Done()
log.Printf("Stopping build: %s", b.Name())
b.Cancel()
}()
}
wg.Wait()
}()
wg.Wait() wg.Wait()
// Output all the artifacts // Output all the artifacts
......
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