From 9ec678cca127d0bdd76bfdd48c6f2e9358be906d Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Tue, 12 Apr 2016 15:04:25 +0800 Subject: [PATCH] fix #44 Support Zero downtime restarts for go servers Signed-off-by: Bo-Yi Wu --- README.md | 1 + gorush/server.go | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b30c436..540a884 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ A push notification server using [Gin](https://github.com/gin-gonic/gin) framewo * Support [YAML](https://github.com/go-yaml/yaml) configuration. * Support command line to send single Android or iOS notification. * Support Web API to send push notification. +* Support zero downtime restarts for go servers using [endless](https://github.com/fvbock/endless). See the [YAML config example](config/config.yml): diff --git a/gorush/server.go b/gorush/server.go index 80733c0..e5ea23b 100644 --- a/gorush/server.go +++ b/gorush/server.go @@ -3,6 +3,7 @@ package gopush import ( "fmt" api "github.com/appleboy/gin-status-api" + "github.com/fvbock/endless" "github.com/gin-gonic/gin" "net/http" ) @@ -76,9 +77,9 @@ func GetMainEngine() *gin.Engine { func RunHTTPServer() error { var err error if PushConf.Core.SSL && PushConf.Core.CertPath != "" && PushConf.Core.KeyPath != "" { - err = GetMainEngine().RunTLS(":"+PushConf.Core.Port, PushConf.Core.CertPath, PushConf.Core.KeyPath) + err = endless.ListenAndServeTLS(":"+PushConf.Core.Port, PushConf.Core.CertPath, PushConf.Core.KeyPath, GetMainEngine()) } else { - err = GetMainEngine().Run(":" + PushConf.Core.Port) + err = endless.ListenAndServe(":"+PushConf.Core.Port, GetMainEngine()) } return err