trap SIGINT and cleanup containers

This commit is contained in:
Brad Rydzewski 2015-08-20 18:31:54 -07:00
parent f5721a9383
commit 50d3ea8e00

View file

@ -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)