From 7eefbd23faa356a3f7ee83ee5c339510e88ff759 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Fri, 24 Apr 2015 14:01:22 -0700 Subject: [PATCH] Ensure that the pidfile is written after all logic for Barak is complete. --- cmd/barak/main.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/barak/main.go b/cmd/barak/main.go index 554e2242..e270c3b7 100644 --- a/cmd/barak/main.go +++ b/cmd/barak/main.go @@ -88,12 +88,6 @@ func main() { } barak.registries = options.Registries - // Write pid to file. - err = AtomicWriteFile(barak.rootDir+"/pidfile", []byte(Fmt("%v", barak.pid))) - if err != nil { - panic(Fmt("Error writing pidfile: %v", err)) - } - // Debug. fmt.Printf("Options: %v\n", options) fmt.Printf("Barak: %v\n", barak) @@ -119,6 +113,12 @@ func main() { }(registry) } + // Write pid to file. This should be the last thing before TrapSignal. + err = AtomicWriteFile(barak.rootDir+"/pidfile", []byte(Fmt("%v", barak.pid))) + if err != nil { + panic(Fmt("Error writing pidfile: %v", err)) + } + TrapSignal(func() { fmt.Println("Barak shutting down") })