From 9b747c3a9d45aca42a6063a70870796f39c8c0c7 Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Fri, 3 Oct 2014 08:36:08 -0700 Subject: [PATCH] Add a signal handler to pause. It returns 0 when a signal is received. --- build/pause/pause.go | 13 ++++++++++--- build/pause/prepare.sh | 5 +++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/build/pause/pause.go b/build/pause/pause.go index 56d92186029..4dd8c1d89d3 100644 --- a/build/pause/pause.go +++ b/build/pause/pause.go @@ -18,9 +18,16 @@ limitations under the License. package main -import "syscall" +import ( + "os" + "os/signal" + "syscall" +) func main() { - // Halts execution, waiting on signal. - syscall.Pause() + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGTERM) + + // Block until a signal is received. + <-c } diff --git a/build/pause/prepare.sh b/build/pause/prepare.sh index 64e85fdc2ae..1690e889b3f 100755 --- a/build/pause/prepare.sh +++ b/build/pause/prepare.sh @@ -3,4 +3,9 @@ set -e set -x +# Build the binary. go build --ldflags '-extldflags "-static" -s' pause.go + +# Run goupx to shrink binary size. +go get github.com/pwaller/goupx +goupx pause