Add systemd socket support

This commit is contained in:
George Shammas 2015-11-30 16:48:15 +00:00
parent 0a392f3e90
commit c8cd9ee648
1 changed files with 13 additions and 0 deletions

13
main.go
View File

@ -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 == "" {