Commit 256b97ce authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

Signal handling, force quit after two interrupts

parent 5c39a2f7
...@@ -96,6 +96,8 @@ func main() { ...@@ -96,6 +96,8 @@ func main() {
os.Exit(1) os.Exit(1)
} }
setupSignalHandlers(env)
exitCode, err := env.Cli(os.Args[1:]) exitCode, err := env.Cli(os.Args[1:])
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error()) fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error())
......
package main
import (
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer/plugin"
"log"
"os"
"os/signal"
)
// Prepares the signal handlers so that we handle interrupts properly.
// The signal handler exists in a goroutine.
func setupSignalHandlers(env packer.Environment) {
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt)
go func() {
<-ch
log.Println("First interrupt. Ignoring, will let plugins handle...")
<-ch
log.Println("Second interrupt. Exiting now.")
env.Ui().Error("Interrupt signal received twice. Forcefully exiting now.")
// Force kill all the plugins
plugin.CleanupClients()
os.Exit(1)
}()
}
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