Commit 4c5d6170 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/plugin: catch interrupts for every server

parent 06d12773
...@@ -92,28 +92,19 @@ func Server() (*packrpc.Server, error) { ...@@ -92,28 +92,19 @@ func Server() (*packrpc.Server, error) {
return nil, err return nil, err
} }
// Serve a single connection // Eat the interrupts
log.Println("Serving a plugin connection...")
return packrpc.NewServer(conn), nil
}
// Registers a signal handler to swallow and count interrupts so that the
// plugin isn't killed. The main host Packer process is responsible
// for killing the plugins when interrupted.
func countInterrupts() {
ch := make(chan os.Signal, 1) ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt) signal.Notify(ch, os.Interrupt)
go func() { go func() {
var count int32 = 0
for { for {
<-ch <-ch
newCount := atomic.AddInt32(&Interrupts, 1) newCount := atomic.AddInt32(&count, 1)
log.Printf("Received interrupt signal (count: %d). Ignoring.", newCount) log.Printf("Received interrupt signal (count: %d). Ignoring.", newCount)
} }
}() }()
}
// Tests whether or not the plugin was interrupted or not. // Serve a single connection
func Interrupted() bool { log.Println("Serving a plugin connection...")
return atomic.LoadInt32(&Interrupts) > 0 return packrpc.NewServer(conn), nil
} }
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