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
defa81e4
Commit
defa81e4
authored
Feb 17, 2017
by
bergquist
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'http_graceful'
parents
a32b7dfb
cf871b12
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
24 deletions
+29
-24
pkg/api/http_server.go
+19
-2
pkg/cmd/grafana-server/server.go
+10
-18
pkg/models/server.go
+0
-4
No files found.
pkg/api/http_server.go
View file @
defa81e4
...
...
@@ -25,6 +25,8 @@ type HttpServer struct {
macaron
*
macaron
.
Macaron
context
context
.
Context
streamManager
*
live
.
StreamManager
httpSrv
*
http
.
Server
}
func
NewHttpServer
()
*
HttpServer
{
...
...
@@ -46,11 +48,20 @@ func (hs *HttpServer) Start(ctx context.Context) error {
listenAddr
:=
fmt
.
Sprintf
(
"%s:%s"
,
setting
.
HttpAddr
,
setting
.
HttpPort
)
hs
.
log
.
Info
(
"Initializing HTTP Server"
,
"address"
,
listenAddr
,
"protocol"
,
setting
.
Protocol
,
"subUrl"
,
setting
.
AppSubUrl
)
hs
.
httpSrv
=
&
http
.
Server
{
Addr
:
listenAddr
,
Handler
:
hs
.
macaron
}
switch
setting
.
Protocol
{
case
setting
.
HTTP
:
err
=
http
.
ListenAndServe
(
listenAddr
,
hs
.
macaron
)
err
=
hs
.
httpSrv
.
ListenAndServe
()
if
err
==
http
.
ErrServerClosed
{
hs
.
log
.
Debug
(
"server was shutdown gracefully"
)
return
nil
}
case
setting
.
HTTPS
:
err
=
hs
.
listenAndServeTLS
(
listenAddr
,
setting
.
CertFile
,
setting
.
KeyFile
)
err
=
hs
.
httpSrv
.
ListenAndServeTLS
(
setting
.
CertFile
,
setting
.
KeyFile
)
if
err
==
http
.
ErrServerClosed
{
hs
.
log
.
Debug
(
"server was shutdown gracefully"
)
return
nil
}
default
:
hs
.
log
.
Error
(
"Invalid protocol"
,
"protocol"
,
setting
.
Protocol
)
err
=
errors
.
New
(
"Invalid Protocol"
)
...
...
@@ -59,6 +70,12 @@ func (hs *HttpServer) Start(ctx context.Context) error {
return
err
}
func
(
hs
*
HttpServer
)
Shutdown
(
ctx
context
.
Context
)
error
{
err
:=
hs
.
httpSrv
.
Shutdown
(
ctx
)
hs
.
log
.
Info
(
"stopped http server"
)
return
err
}
func
(
hs
*
HttpServer
)
listenAndServeTLS
(
listenAddr
,
certfile
,
keyfile
string
)
error
{
if
certfile
==
""
{
return
fmt
.
Errorf
(
"cert_file cannot be empty when using HTTPS"
)
...
...
pkg/cmd/grafana-server/server.go
View file @
defa81e4
...
...
@@ -3,7 +3,6 @@ package main
import
(
"context"
"os"
"time"
"golang.org/x/sync/errgroup"
...
...
@@ -39,6 +38,8 @@ type GrafanaServerImpl struct {
shutdownFn
context
.
CancelFunc
childRoutines
*
errgroup
.
Group
log
log
.
Logger
httpServer
*
api
.
HttpServer
}
func
(
g
*
GrafanaServerImpl
)
Start
()
{
...
...
@@ -74,9 +75,9 @@ func (g *GrafanaServerImpl) Start() {
}
func
(
g
*
GrafanaServerImpl
)
startHttpServer
()
{
httpServer
:
=
api
.
NewHttpServer
()
g
.
httpServer
=
api
.
NewHttpServer
()
err
:=
httpServer
.
Start
(
g
.
context
)
err
:=
g
.
httpServer
.
Start
(
g
.
context
)
if
err
!=
nil
{
g
.
log
.
Error
(
"Fail to start server"
,
"error"
,
err
)
...
...
@@ -88,24 +89,15 @@ func (g *GrafanaServerImpl) startHttpServer() {
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
)
}
g
.
shutdownFn
()
err
:
=
g
.
childRoutines
.
Wait
()
err
=
g
.
childRoutines
.
Wait
()
g
.
log
.
Info
(
"Shutdown completed"
,
"reason"
,
err
)
log
.
Close
()
os
.
Exit
(
code
)
}
// implement context.Context
func
(
g
*
GrafanaServerImpl
)
Deadline
()
(
deadline
time
.
Time
,
ok
bool
)
{
return
g
.
context
.
Deadline
()
}
func
(
g
*
GrafanaServerImpl
)
Done
()
<-
chan
struct
{}
{
return
g
.
context
.
Done
()
}
func
(
g
*
GrafanaServerImpl
)
Err
()
error
{
return
g
.
context
.
Err
()
}
func
(
g
*
GrafanaServerImpl
)
Value
(
key
interface
{})
interface
{}
{
return
g
.
context
.
Value
(
key
)
}
pkg/models/server.go
View file @
defa81e4
package
models
import
"context"
type
GrafanaServer
interface
{
context
.
Context
Start
()
Shutdown
(
code
int
,
reason
string
)
}
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