diff --git a/cmd/drone-agent/agent.go b/cmd/drone-agent/agent.go index 9a8b5b126..21341c95e 100644 --- a/cmd/drone-agent/agent.go +++ b/cmd/drone-agent/agent.go @@ -17,10 +17,10 @@ import ( "github.com/cncd/pipeline/pipeline" "github.com/cncd/pipeline/pipeline/backend" "github.com/cncd/pipeline/pipeline/backend/docker" - "github.com/cncd/pipeline/pipeline/interrupt" "github.com/cncd/pipeline/pipeline/multipart" "github.com/cncd/pipeline/pipeline/rpc" + "github.com/drone/signal" "github.com/rs/zerolog" "github.com/rs/zerolog/log" "github.com/tevino/abool" @@ -89,7 +89,7 @@ func loop(c *cli.Context) error { context.Background(), metadata.Pairs("hostname", hostname), ) - ctx = interrupt.WithContextFunc(ctx, func() { + ctx = signal.WithContextFunc(ctx, func() { println("ctrl+c received, terminating process") sigterm.Set() }) diff --git a/vendor/github.com/drone/signal/LICENSE b/vendor/github.com/drone/signal/LICENSE new file mode 100644 index 000000000..1de55b7f4 --- /dev/null +++ b/vendor/github.com/drone/signal/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 drone.io + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/drone/signal/signal.go b/vendor/github.com/drone/signal/signal.go new file mode 100644 index 000000000..dc6e9d2c1 --- /dev/null +++ b/vendor/github.com/drone/signal/signal.go @@ -0,0 +1,38 @@ +// Package signal implements Context os/signal +package signal + +import ( + "context" + "os" + "os/signal" + "syscall" +) + +// WithContext returns a copy of parent context whose Done channel is closed +// when an os interrupt signal is received. +func WithContext(ctx context.Context) context.Context { + return WithContextFunc(ctx, func() { + println("ctrl+c received, terminating process") + }) +} + +// WithContextFunc returns a copy of parent context that is cancelled when +// an os interrupt signal is received. The callback function f is invoked +// before cancellation. +func WithContextFunc(ctx context.Context, f func()) context.Context { + ctx, cancel := context.WithCancel(ctx) + go func() { + c := make(chan os.Signal) + signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) + defer signal.Stop(c) + + select { + case <-ctx.Done(): + case <-c: + f() + cancel() + } + }() + + return ctx +} diff --git a/vendor/vendor.json b/vendor/vendor.json index 5f4e8b261..b9dd90550 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -343,6 +343,12 @@ "revision": "72f4df4a266b7e1e15b75d4ab8e43e273fcbe1d7", "revisionTime": "2017-09-09T01:06:28Z" }, + { + "checksumSHA1": "ZOASUqqEP4pfH5MNjImiyemkjOA=", + "path": "github.com/drone/signal", + "revision": "ac5d07ef13150b4db403b96152e1ea54335df400", + "revisionTime": "2017-09-15T01:38:02Z" + }, { "checksumSHA1": "40Ns85VYa4smQPcewZ7SOdfLnKU=", "path": "github.com/fatih/structs",