From c8cd9ee648967f72ac76f6d28a8e85dd475a5e93 Mon Sep 17 00:00:00 2001 From: George Shammas Date: Mon, 30 Nov 2015 16:48:15 +0000 Subject: [PATCH] Add systemd socket support --- main.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/main.go b/main.go index a7280b2..5126b22 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( "github.com/gin-gonic/gin" "github.com/brandfolder/gin-gorelic" + "github.com/coreos/go-systemd/activation" ) // Logger is a simple log handler, out puts in the standard of apache access log common. @@ -189,6 +190,18 @@ func main() { errc <- fcgi.Serve(fcgi_listen, r) }(errc) + + // Listen on whatever systemd tells us to. + listeners, err := activation.Listeners(true) + if err != nil { + fmt.Printf("Could not get systemd listerns with err %q", err) + } + for _, listener := range listeners { + go func(errc chan error) { + errc <- http.Serve(listener, r) + }(errc) + } + port := os.Getenv("PORT") host := os.Getenv("HOST") if port == "" {