From 09dda9bfd72b2c87ecd40578114f0ad452599db4 Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Mon, 7 Mar 2016 16:22:38 -0500 Subject: [PATCH 1/2] cmd/clair: fix pprof --- cmd/clair/main.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cmd/clair/main.go b/cmd/clair/main.go index 8b129bb7..d5aa90b0 100644 --- a/cmd/clair/main.go +++ b/cmd/clair/main.go @@ -67,25 +67,30 @@ func main() { // Enable CPU Profiling if specified if *flagCPUProfilePath != "" { - startCPUProfiling(*flagCPUProfilePath) - defer stopCPUProfiling() + defer stopCPUProfiling(startCPUProfiling(*flagCPUProfilePath)) } clair.Boot(config) } -func startCPUProfiling(path string) { +func startCPUProfiling(path string) *os.File { f, err := os.Create(path) if err != nil { log.Fatalf("failed to create profile file: %s", err) } - defer f.Close() - pprof.StartCPUProfile(f) + err = pprof.StartCPUProfile(f) + if err != nil { + log.Fatalf("failed to start CPU profiling: %s", err) + } + log.Info("started CPU profiling") + + return f } -func stopCPUProfiling() { +func stopCPUProfiling(f *os.File) { pprof.StopCPUProfile() + f.Close() log.Info("stopped CPU profiling") } From 19e9d1234ee2f001c01b688fd9dde84498b23df3 Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Mon, 7 Mar 2016 16:38:10 -0500 Subject: [PATCH 2/2] clair: catch both SIGINT and SIGTERM for graceful shutdown --- clair.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clair.go b/clair.go index a445f797..cfb5c850 100644 --- a/clair.go +++ b/clair.go @@ -20,6 +20,7 @@ import ( "math/rand" "os" "os/signal" + "syscall" "time" "github.com/coreos/clair/api" @@ -62,7 +63,7 @@ func Boot(config *config.Config) { go updater.Run(config.Updater, db, st) // Wait for interruption and shutdown gracefully. - waitForSignals(os.Interrupt) + waitForSignals(syscall.SIGINT, syscall.SIGTERM) log.Info("Received interruption, gracefully stopping ...") st.Stop() }