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
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
40 deletions
+89
-40
admin.go
admin.go
+10
-2
app.go
app.go
+75
-38
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 (
...
@@ -19,9 +19,11 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"net/http"
"net/http"
"os"
"text/template"
"text/template"
"time"
"time"
"github.com/astaxie/beego/grace"
"github.com/astaxie/beego/toolbox"
"github.com/astaxie/beego/toolbox"
"github.com/astaxie/beego/utils"
"github.com/astaxie/beego/utils"
)
)
...
@@ -458,8 +460,14 @@ func (admin *adminApp) Run() {
...
@@ -458,8 +460,14 @@ func (admin *adminApp) Run() {
http
.
Handle
(
p
,
f
)
http
.
Handle
(
p
,
f
)
}
}
BeeLogger
.
Info
(
"Admin server Running on %s"
,
addr
)
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
{
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 (
...
@@ -22,6 +22,7 @@ import (
"os"
"os"
"time"
"time"
"github.com/astaxie/beego/grace"
"github.com/astaxie/beego/utils"
"github.com/astaxie/beego/utils"
)
)
...
@@ -76,57 +77,93 @@ func (app *App) Run() {
...
@@ -76,57 +77,93 @@ func (app *App) Run() {
err
=
fcgi
.
Serve
(
l
,
app
.
Handlers
)
err
=
fcgi
.
Serve
(
l
,
app
.
Handlers
)
}
}
}
else
{
}
else
{
app
.
Server
.
Addr
=
addr
if
Graceful
{
app
.
Server
.
Handler
=
app
.
Handlers
if
EnableHttpTLS
{
app
.
Server
.
ReadTimeout
=
time
.
Duration
(
HttpServerTimeOut
)
*
time
.
Second
go
func
()
{
app
.
Server
.
WriteTimeout
=
time
.
Duration
(
HttpServerTimeOut
)
*
time
.
Second
time
.
Sleep
(
20
*
time
.
Microsecond
)
if
HttpsPort
!=
0
{
if
EnableHttpTLS
{
addr
=
fmt
.
Sprintf
(
"%s:%d"
,
HttpAddr
,
HttpsPort
)
go
func
()
{
}
time
.
Sleep
(
20
*
time
.
Microsecond
)
server
:=
grace
.
NewServer
(
addr
,
app
.
Handlers
)
if
HttpsPort
!=
0
{
server
.
Server
.
ReadTimeout
=
time
.
Duration
(
HttpServerTimeOut
)
*
time
.
Second
app
.
Server
.
Addr
=
fmt
.
Sprintf
(
"%s:%d"
,
HttpAddr
,
HttpsPort
)
server
.
Server
.
WriteTimeout
=
time
.
Duration
(
HttpServerTimeOut
)
*
time
.
Second
}
err
:=
server
.
ListenAndServeTLS
(
HttpCertFile
,
HttpKeyFile
)
BeeLogger
.
Info
(
"https server Running on %s"
,
app
.
Server
.
Addr
)
err
:=
app
.
Server
.
ListenAndServeTLS
(
HttpCertFile
,
HttpKeyFile
)
if
err
!=
nil
{
BeeLogger
.
Critical
(
"ListenAndServeTLS: "
,
err
)
time
.
Sleep
(
100
*
time
.
Microsecond
)
endRunning
<-
true
}
}()
}
if
EnableHttpListen
{
go
func
()
{
app
.
Server
.
Addr
=
addr
BeeLogger
.
Info
(
"http server Running on %s"
,
app
.
Server
.
Addr
)
if
ListenTCP4
&&
HttpAddr
==
""
{
ln
,
err
:=
net
.
Listen
(
"tcp4"
,
app
.
Server
.
Addr
)
if
err
!=
nil
{
if
err
!=
nil
{
BeeLogger
.
Critical
(
"ListenAndServe: "
,
err
)
BeeLogger
.
Critical
(
"ListenAndServe
TLS
: "
,
err
)
time
.
Sleep
(
100
*
time
.
Microsecond
)
time
.
Sleep
(
100
*
time
.
Microsecond
)
endRunning
<-
true
endRunning
<-
true
return
}
}
err
=
app
.
Server
.
Serve
(
ln
)
}()
}
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
{
if
err
!=
nil
{
BeeLogger
.
Critical
(
"ListenAndServe: "
,
err
)
BeeLogger
.
Critical
(
"ListenAndServe: "
,
err
,
fmt
.
Sprint
(
os
.
Getpid
())
)
time
.
Sleep
(
100
*
time
.
Microsecond
)
time
.
Sleep
(
100
*
time
.
Microsecond
)
endRunning
<-
true
endRunning
<-
true
return
}
}
}
else
{
}()
err
:=
app
.
Server
.
ListenAndServe
()
}
}
else
{
app
.
Server
.
Addr
=
addr
app
.
Server
.
Handler
=
app
.
Handlers
app
.
Server
.
ReadTimeout
=
time
.
Duration
(
HttpServerTimeOut
)
*
time
.
Second
app
.
Server
.
WriteTimeout
=
time
.
Duration
(
HttpServerTimeOut
)
*
time
.
Second
if
EnableHttpTLS
{
go
func
()
{
time
.
Sleep
(
20
*
time
.
Microsecond
)
if
HttpsPort
!=
0
{
app
.
Server
.
Addr
=
fmt
.
Sprintf
(
"%s:%d"
,
HttpAddr
,
HttpsPort
)
}
BeeLogger
.
Info
(
"https server Running on %s"
,
app
.
Server
.
Addr
)
err
:=
app
.
Server
.
ListenAndServeTLS
(
HttpCertFile
,
HttpKeyFile
)
if
err
!=
nil
{
if
err
!=
nil
{
BeeLogger
.
Critical
(
"ListenAndServe: "
,
err
)
BeeLogger
.
Critical
(
"ListenAndServe
TLS
: "
,
err
)
time
.
Sleep
(
100
*
time
.
Microsecond
)
time
.
Sleep
(
100
*
time
.
Microsecond
)
endRunning
<-
true
endRunning
<-
true
}
}
}
}()
}()
}
if
EnableHttpListen
{
go
func
()
{
app
.
Server
.
Addr
=
addr
BeeLogger
.
Info
(
"http server Running on %s"
,
app
.
Server
.
Addr
)
if
ListenTCP4
&&
HttpAddr
==
""
{
ln
,
err
:=
net
.
Listen
(
"tcp4"
,
app
.
Server
.
Addr
)
if
err
!=
nil
{
BeeLogger
.
Critical
(
"ListenAndServe: "
,
err
)
time
.
Sleep
(
100
*
time
.
Microsecond
)
endRunning
<-
true
return
}
err
=
app
.
Server
.
Serve
(
ln
)
if
err
!=
nil
{
BeeLogger
.
Critical
(
"ListenAndServe: "
,
err
)
time
.
Sleep
(
100
*
time
.
Microsecond
)
endRunning
<-
true
return
}
}
else
{
err
:=
app
.
Server
.
ListenAndServe
()
if
err
!=
nil
{
BeeLogger
.
Critical
(
"ListenAndServe: "
,
err
)
time
.
Sleep
(
100
*
time
.
Microsecond
)
endRunning
<-
true
}
}
}()
}
}
}
}
}
<-
endRunning
<-
endRunning
}
}
config.go
View file @
4138fe02
...
@@ -82,6 +82,7 @@ var (
...
@@ -82,6 +82,7 @@ var (
EnableDocs
bool
// enable generate docs & server docs API Swagger
EnableDocs
bool
// enable generate docs & server docs API Swagger
RouterCaseSensitive
bool
// router case sensitive default is true
RouterCaseSensitive
bool
// router case sensitive default is true
AccessLogs
bool
// print access logs, default is false
AccessLogs
bool
// print access logs, default is false
Graceful
bool
// use graceful start the server
)
)
type
beegoAppConfig
struct
{
type
beegoAppConfig
struct
{
...
@@ -509,5 +510,8 @@ func ParseConfig() (err error) {
...
@@ -509,5 +510,8 @@ func ParseConfig() (err error) {
if
casesensitive
,
err
:=
AppConfig
.
Bool
(
"RouterCaseSensitive"
);
err
==
nil
{
if
casesensitive
,
err
:=
AppConfig
.
Bool
(
"RouterCaseSensitive"
);
err
==
nil
{
RouterCaseSensitive
=
casesensitive
RouterCaseSensitive
=
casesensitive
}
}
if
graceful
,
err
:=
AppConfig
.
Bool
(
"Graceful"
);
err
==
nil
{
Graceful
=
graceful
}
return
nil
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