From 50d3ea8e00964b5b4cd4ad6315f35b80e649674a Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 20 Aug 2015 18:31:54 -0700 Subject: [PATCH] trap SIGINT and cleanup containers --- cmd/drone-build/main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/drone-build/main.go b/cmd/drone-build/main.go index cc23f34cf..d25ebc864 100644 --- a/cmd/drone-build/main.go +++ b/cmd/drone-build/main.go @@ -6,7 +6,9 @@ import ( "flag" "fmt" "os" + "os/signal" "strings" + "syscall" log "github.com/drone/drone/Godeps/_workspace/src/github.com/Sirupsen/logrus" "github.com/drone/drone/Godeps/_workspace/src/github.com/samalba/dockerclient" @@ -56,6 +58,16 @@ func main() { ctx.client = client defer client.Destroy() + // watch for sigkill (timeout or cancel build) + killc := make(chan os.Signal, 1) + signal.Notify(killc, syscall.SIGINT, syscall.SIGTERM) + go func() { + <-killc + log.Println("Received reques to kill this build") + client.Destroy() // possibe race here. implement lock on the other end + os.Exit(1) + }() + // performs some initial parsing and pre-processing steps // prior to executing our build tasks. createClone(ctx)