Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
4138fe02
Commit
4138fe02
authored
May 13, 2015
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
beego suppot graceful restart application
parent
245762f7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
2 deletions
+51
-2
admin.go
admin.go
+10
-2
app.go
app.go
+37
-0
config.go
config.go
+4
-0
grace.go
grace/grace.go
+0
-0
No files found.
admin.go
View file @
4138fe02
...
...
@@ -19,9 +19,11 @@ import (
"encoding/json"
"fmt"
"net/http"
"os"
"text/template"
"time"
"github.com/astaxie/beego/grace"
"github.com/astaxie/beego/toolbox"
"github.com/astaxie/beego/utils"
)
...
...
@@ -458,8 +460,14 @@ func (admin *adminApp) Run() {
http
.
Handle
(
p
,
f
)
}
BeeLogger
.
Info
(
"Admin server Running on %s"
,
addr
)
err
:=
http
.
ListenAndServe
(
addr
,
nil
)
var
err
error
if
Graceful
{
err
=
grace
.
ListenAndServe
(
addr
,
nil
)
}
else
{
err
=
http
.
ListenAndServe
(
addr
,
nil
)
}
if
err
!=
nil
{
BeeLogger
.
Critical
(
"Admin ListenAndServe: "
,
err
)
BeeLogger
.
Critical
(
"Admin ListenAndServe: "
,
err
,
fmt
.
Sprint
(
os
.
Getpid
())
)
}
}
app.go
View file @
4138fe02
...
...
@@ -22,6 +22,7 @@ import (
"os"
"time"
"github.com/astaxie/beego/grace"
"github.com/astaxie/beego/utils"
)
...
...
@@ -75,6 +76,41 @@ func (app *App) Run() {
}
err
=
fcgi
.
Serve
(
l
,
app
.
Handlers
)
}
}
else
{
if
Graceful
{
if
EnableHttpTLS
{
go
func
()
{
time
.
Sleep
(
20
*
time
.
Microsecond
)
if
HttpsPort
!=
0
{
addr
=
fmt
.
Sprintf
(
"%s:%d"
,
HttpAddr
,
HttpsPort
)
}
server
:=
grace
.
NewServer
(
addr
,
app
.
Handlers
)
server
.
Server
.
ReadTimeout
=
time
.
Duration
(
HttpServerTimeOut
)
*
time
.
Second
server
.
Server
.
WriteTimeout
=
time
.
Duration
(
HttpServerTimeOut
)
*
time
.
Second
err
:=
server
.
ListenAndServeTLS
(
HttpCertFile
,
HttpKeyFile
)
if
err
!=
nil
{
BeeLogger
.
Critical
(
"ListenAndServeTLS: "
,
err
)
time
.
Sleep
(
100
*
time
.
Microsecond
)
endRunning
<-
true
}
}()
}
if
EnableHttpListen
{
go
func
()
{
server
:=
grace
.
NewServer
(
addr
,
app
.
Handlers
)
server
.
Server
.
ReadTimeout
=
time
.
Duration
(
HttpServerTimeOut
)
*
time
.
Second
server
.
Server
.
WriteTimeout
=
time
.
Duration
(
HttpServerTimeOut
)
*
time
.
Second
if
ListenTCP4
&&
HttpAddr
==
""
{
server
.
Network
=
"tcp4"
}
err
:=
server
.
ListenAndServe
()
if
err
!=
nil
{
BeeLogger
.
Critical
(
"ListenAndServe: "
,
err
,
fmt
.
Sprint
(
os
.
Getpid
()))
time
.
Sleep
(
100
*
time
.
Microsecond
)
endRunning
<-
true
}
}()
}
}
else
{
app
.
Server
.
Addr
=
addr
app
.
Server
.
Handler
=
app
.
Handlers
...
...
@@ -128,5 +164,6 @@ func (app *App) Run() {
}
}
}
<-
endRunning
}
config.go
View file @
4138fe02
...
...
@@ -82,6 +82,7 @@ var (
EnableDocs
bool
// enable generate docs & server docs API Swagger
RouterCaseSensitive
bool
// router case sensitive default is true
AccessLogs
bool
// print access logs, default is false
Graceful
bool
// use graceful start the server
)
type
beegoAppConfig
struct
{
...
...
@@ -509,5 +510,8 @@ func ParseConfig() (err error) {
if
casesensitive
,
err
:=
AppConfig
.
Bool
(
"RouterCaseSensitive"
);
err
==
nil
{
RouterCaseSensitive
=
casesensitive
}
if
graceful
,
err
:=
AppConfig
.
Bool
(
"Graceful"
);
err
==
nil
{
Graceful
=
graceful
}
return
nil
}
grace/grace.go
0 → 100644
View file @
4138fe02
This diff is collapsed.
Click to expand it.
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