hack/e2e.go: listen for Interrupt signal and attempt cleanup if using --down

Signed-off-by: Jess Frazelle <me@jessfraz.com>
Signed-off-by: Jess Frazelle <acidburn@google.com>
pull/6/head
Jess Frazelle 2016-09-06 13:41:02 -07:00 committed by Jess Frazelle
parent 41f17bd9ac
commit da786a8dc5
No known key found for this signature in database
GPG Key ID: 18F3685C0022BFF3
1 changed files with 16 additions and 0 deletions

View File

@ -25,6 +25,7 @@ import (
"log"
"os"
"os/exec"
"os/signal"
"os/user"
"path/filepath"
"strconv"
@ -159,6 +160,21 @@ func main() {
log.Fatalf("Error creating deployer: %v", err)
}
if *down {
// listen for signals such as ^C and gracefully attempt to clean up
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for range c {
log.Print("Captured ^C, gracefully attempting to cleanup resources..")
if err := deploy.Down(); err != nil {
log.Printf("Tearing down deployment failed: %v", err)
os.Exit(1)
}
}
}()
}
if err := run(deploy); err != nil {
log.Fatalf("Something went wrong: %s", err)
}