Skip to content

Commit

Permalink
Merge pull request #86 from Conight/master
Browse files Browse the repository at this point in the history
fix graceful shutdown not working when monitor service enable
  • Loading branch information
LyricTian authored Jul 28, 2020
2 parents 6d61d57 + 1cccee0 commit 3a066f3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func Init(ctx context.Context, opts ...Option) (func(), error) {
}

// 初始化服务运行监控
InitMonitor(ctx)
monitorCleanFunc := InitMonitor(ctx)

// 初始化图形验证码
InitCaptcha()
Expand All @@ -126,6 +126,7 @@ func Init(ctx context.Context, opts ...Option) (func(), error) {
return func() {
httpServerCleanFunc()
injectorCleanFunc()
monitorCleanFunc()
loggerCleanFunc()
}, nil
}
Expand All @@ -144,13 +145,19 @@ func InitCaptcha() {
}

// InitMonitor 初始化服务监控
func InitMonitor(ctx context.Context) {
func InitMonitor(ctx context.Context) func() {
if c := config.C.Monitor; c.Enable {
err := agent.Listen(agent.Options{Addr: c.Addr, ConfigDir: c.ConfigDir, ShutdownCleanup: true})
// ShutdownCleanup set false to prevent automatically closes on os.Interrupt
// and close agent manually before service shutting down
err := agent.Listen(agent.Options{Addr: c.Addr, ConfigDir: c.ConfigDir, ShutdownCleanup: false})
if err != nil {
logger.Errorf(ctx, "Agent monitor error: %s", err.Error())
}
return func() {
agent.Close()
}
}
return func() {}
}

// InitHTTPServer 初始化http服务
Expand Down

0 comments on commit 3a066f3

Please sign in to comment.