Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
13e015fe
Commit
13e015fe
authored
May 01, 2018
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: improved handling of http server shutdown
parent
0fc4da81
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
8 deletions
+17
-8
pkg/api/http_server.go
+10
-0
pkg/cmd/grafana-server/server.go
+7
-8
No files found.
pkg/api/http_server.go
View file @
13e015fe
...
...
@@ -60,6 +60,16 @@ func (hs *HTTPServer) Start(ctx context.Context) error {
hs
.
log
.
Info
(
"Initializing HTTP Server"
,
"address"
,
listenAddr
,
"protocol"
,
setting
.
Protocol
,
"subUrl"
,
setting
.
AppSubUrl
,
"socket"
,
setting
.
SocketPath
)
hs
.
httpSrv
=
&
http
.
Server
{
Addr
:
listenAddr
,
Handler
:
hs
.
macaron
}
// handle http shutdown on server context done
go
func
()
{
<-
ctx
.
Done
()
if
err
:=
hs
.
httpSrv
.
Shutdown
(
context
.
Background
());
err
!=
nil
{
hs
.
log
.
Error
(
"Failed to shutdown server"
,
"error"
,
err
)
}
hs
.
log
.
Info
(
"Stopped HTTP Server"
)
}()
switch
setting
.
Protocol
{
case
setting
.
HTTP
:
err
=
hs
.
httpSrv
.
ListenAndServe
()
...
...
pkg/cmd/grafana-server/server.go
View file @
13e015fe
...
...
@@ -92,6 +92,8 @@ func (g *GrafanaServerImpl) Start() error {
serviceGraph
.
Provide
(
&
inject
.
Object
{
Value
:
dashboards
.
NewProvisioningService
()})
serviceGraph
.
Provide
(
&
inject
.
Object
{
Value
:
api
.
NewRouteRegister
(
middleware
.
RequestMetrics
,
middleware
.
RequestTracing
)})
serviceGraph
.
Provide
(
&
inject
.
Object
{
Value
:
api
.
HTTPServer
{}})
// self registered services
services
:=
registry
.
GetServices
()
// Add all services to dependency graph
...
...
@@ -172,15 +174,12 @@ func (g *GrafanaServerImpl) startHttpServer() error {
func
(
g
*
GrafanaServerImpl
)
Shutdown
(
code
int
,
reason
string
)
{
g
.
log
.
Info
(
"Shutdown started"
,
"code"
,
code
,
"reason"
,
reason
)
err
:=
g
.
HttpServer
.
Shutdown
(
g
.
context
)
if
err
!=
nil
{
g
.
log
.
Error
(
"Failed to shutdown server"
,
"error"
,
err
)
}
// call cancel func on root context
g
.
shutdownFn
()
err
=
g
.
childRoutines
.
Wait
()
if
err
!=
nil
&&
err
!=
context
.
Canceled
{
g
.
log
.
Error
(
"Server shutdown completed with an error"
,
"error"
,
err
)
// wait for chid routines
if
err
:=
g
.
childRoutines
.
Wait
();
err
!=
nil
&&
err
!=
context
.
Canceled
{
g
.
log
.
Error
(
"Server shutdown completed"
,
"error"
,
err
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment