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
04290dfc
Commit
04290dfc
authored
May 20, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
beego: delete hotupdate
parent
3f2a712b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
225 deletions
+30
-225
admin.go
admin.go
+0
-1
app.go
app.go
+29
-50
config.go
config.go
+1
-5
reload.go
reload.go
+0
-169
No files found.
admin.go
View file @
04290dfc
...
@@ -107,7 +107,6 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
...
@@ -107,7 +107,6 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
fmt
.
Fprintln
(
rw
,
"MaxMemory:"
,
MaxMemory
)
fmt
.
Fprintln
(
rw
,
"MaxMemory:"
,
MaxMemory
)
fmt
.
Fprintln
(
rw
,
"EnableGzip:"
,
EnableGzip
)
fmt
.
Fprintln
(
rw
,
"EnableGzip:"
,
EnableGzip
)
fmt
.
Fprintln
(
rw
,
"DirectoryIndex:"
,
DirectoryIndex
)
fmt
.
Fprintln
(
rw
,
"DirectoryIndex:"
,
DirectoryIndex
)
fmt
.
Fprintln
(
rw
,
"EnableHotUpdate:"
,
EnableHotUpdate
)
fmt
.
Fprintln
(
rw
,
"HttpServerTimeOut:"
,
HttpServerTimeOut
)
fmt
.
Fprintln
(
rw
,
"HttpServerTimeOut:"
,
HttpServerTimeOut
)
fmt
.
Fprintln
(
rw
,
"ErrorsShow:"
,
ErrorsShow
)
fmt
.
Fprintln
(
rw
,
"ErrorsShow:"
,
ErrorsShow
)
fmt
.
Fprintln
(
rw
,
"XSRFKEY:"
,
XSRFKEY
)
fmt
.
Fprintln
(
rw
,
"XSRFKEY:"
,
XSRFKEY
)
...
...
app.go
View file @
04290dfc
...
@@ -45,7 +45,7 @@ func (app *App) Run() {
...
@@ -45,7 +45,7 @@ func (app *App) Run() {
err
error
err
error
l
net
.
Listener
l
net
.
Listener
)
)
endRunning
:=
make
(
chan
bool
)
endRunning
:=
make
(
chan
bool
,
1
)
if
UseFcgi
{
if
UseFcgi
{
if
HttpPort
==
0
{
if
HttpPort
==
0
{
...
@@ -58,56 +58,35 @@ func (app *App) Run() {
...
@@ -58,56 +58,35 @@ func (app *App) Run() {
}
}
err
=
fcgi
.
Serve
(
l
,
app
.
Handlers
)
err
=
fcgi
.
Serve
(
l
,
app
.
Handlers
)
}
else
{
}
else
{
if
EnableHotUpdate
{
s
:=
&
http
.
Server
{
server
:=
&
http
.
Server
{
Addr
:
addr
,
Handler
:
app
.
Handlers
,
Handler
:
app
.
Handlers
,
ReadTimeout
:
time
.
Duration
(
HttpServerTimeOut
)
*
time
.
Second
,
ReadTimeout
:
time
.
Duration
(
HttpServerTimeOut
)
*
time
.
Second
,
WriteTimeout
:
time
.
Duration
(
HttpServerTimeOut
)
*
time
.
Second
,
WriteTimeout
:
time
.
Duration
(
HttpServerTimeOut
)
*
time
.
Second
,
}
}
laddr
,
err
:=
net
.
ResolveTCPAddr
(
"tcp"
,
addr
)
if
EnableHttpTLS
{
if
nil
!=
err
{
go
func
()
{
BeeLogger
.
Critical
(
"ResolveTCPAddr:"
,
err
)
if
HttpsPort
!=
0
{
}
s
.
Addr
=
fmt
.
Sprintf
(
"%s:%d"
,
HttpAddr
,
HttpsPort
)
l
,
err
=
GetInitListener
(
laddr
)
if
err
==
nil
{
theStoppable
=
newStoppable
(
l
)
err
=
server
.
Serve
(
theStoppable
)
if
err
==
nil
{
theStoppable
.
wg
.
Wait
()
err
=
CloseSelf
()
}
}
}
err
:=
s
.
ListenAndServeTLS
(
HttpCertFile
,
HttpKeyFile
)
}
else
{
if
err
!=
nil
{
s
:=
&
http
.
Server
{
BeeLogger
.
Critical
(
"ListenAndServeTLS: "
,
err
)
Addr
:
addr
,
time
.
Sleep
(
100
*
time
.
Microsecond
)
Handler
:
app
.
Handlers
,
endRunning
<-
true
ReadTimeout
:
time
.
Duration
(
HttpServerTimeOut
)
*
time
.
Second
,
}
WriteTimeout
:
time
.
Duration
(
HttpServerTimeOut
)
*
time
.
Second
,
}()
}
}
if
EnableHttpTLS
{
go
func
()
{
if
EnableHttpListen
{
if
HttpsPort
!=
0
{
go
func
()
{
s
.
Addr
=
fmt
.
Sprintf
(
"%s:%d"
,
HttpAddr
,
HttpsPort
)
err
:=
s
.
ListenAndServe
()
}
if
err
!=
nil
{
err
:=
s
.
ListenAndServeTLS
(
HttpCertFile
,
HttpKeyFile
)
BeeLogger
.
Critical
(
"ListenAndServe: "
,
err
)
if
err
!=
nil
{
time
.
Sleep
(
100
*
time
.
Microsecond
)
BeeLogger
.
Critical
(
"ListenAndServeTLS: "
,
err
)
endRunning
<-
true
time
.
Sleep
(
100
*
time
.
Microsecond
)
}
endRunning
<-
true
}()
}
}()
}
if
EnableHttpListen
{
go
func
()
{
err
:=
s
.
ListenAndServe
()
if
err
!=
nil
{
BeeLogger
.
Critical
(
"ListenAndServe: "
,
err
)
time
.
Sleep
(
100
*
time
.
Microsecond
)
endRunning
<-
true
}
}()
}
}
}
}
}
...
...
config.go
View file @
04290dfc
...
@@ -56,7 +56,6 @@ var (
...
@@ -56,7 +56,6 @@ var (
MaxMemory
int64
MaxMemory
int64
EnableGzip
bool
// flag of enable gzip
EnableGzip
bool
// flag of enable gzip
DirectoryIndex
bool
// flag of display directory index. default is false.
DirectoryIndex
bool
// flag of display directory index. default is false.
EnableHotUpdate
bool
// flag of hot update checking by app self. default is false.
HttpServerTimeOut
int64
HttpServerTimeOut
int64
ErrorsShow
bool
// flag of show errors in page. if true, show error and trace info in page rendered with error template.
ErrorsShow
bool
// flag of show errors in page. if true, show error and trace info in page rendered with error template.
XSRFKEY
string
// xsrf hash salt string.
XSRFKEY
string
// xsrf hash salt string.
...
@@ -101,6 +100,7 @@ func init() {
...
@@ -101,6 +100,7 @@ func init() {
// set this to 0.0.0.0 to make this app available to externally
// set this to 0.0.0.0 to make this app available to externally
EnableHttpListen
=
true
//default enable http Listen
EnableHttpListen
=
true
//default enable http Listen
HttpAddr
=
""
HttpAddr
=
""
HttpPort
=
8080
HttpPort
=
8080
...
@@ -254,10 +254,6 @@ func ParseConfig() (err error) {
...
@@ -254,10 +254,6 @@ func ParseConfig() (err error) {
DirectoryIndex
=
directoryindex
DirectoryIndex
=
directoryindex
}
}
if
hotupdate
,
err
:=
AppConfig
.
Bool
(
"HotUpdate"
);
err
==
nil
{
EnableHotUpdate
=
hotupdate
}
if
timeout
,
err
:=
AppConfig
.
Int64
(
"HttpServerTimeOut"
);
err
==
nil
{
if
timeout
,
err
:=
AppConfig
.
Int64
(
"HttpServerTimeOut"
);
err
==
nil
{
HttpServerTimeOut
=
timeout
HttpServerTimeOut
=
timeout
}
}
...
...
reload.go
deleted
100644 → 0
View file @
3f2a712b
// Beego (http://beego.me/)
// @description beego is an open-source, high-performance web framework for the Go programming language.
// @link http://github.com/astaxie/beego for the canonical source repository
// @license http://github.com/astaxie/beego/blob/master/LICENSE
// @authors astaxie
package
beego
import
(
"errors"
"fmt"
"log"
"net"
"os"
"os/exec"
"os/signal"
"reflect"
"strconv"
"sync"
//"syscall"
)
const
(
// An environment variable when restarting application http listener.
FDKey
=
"BEEGO_HOT_FD"
)
// Export an error equivalent to net.errClosing for use with Accept during
// a graceful exit.
var
ErrClosing
=
errors
.
New
(
"use of closed network connection"
)
var
ErrInitStart
=
errors
.
New
(
"init from"
)
// Allows for us to notice when the connection is closed.
type
conn
struct
{
net
.
Conn
wg
*
sync
.
WaitGroup
isclose
bool
lock
*
sync
.
Mutex
}
// Close current processing connection.
func
(
c
conn
)
Close
()
error
{
c
.
lock
.
Lock
()
defer
c
.
lock
.
Unlock
()
err
:=
c
.
Conn
.
Close
()
if
!
c
.
isclose
&&
err
==
nil
{
c
.
wg
.
Done
()
c
.
isclose
=
true
}
return
err
}
type
stoppableListener
struct
{
net
.
Listener
count
int64
stopped
bool
wg
sync
.
WaitGroup
}
var
theStoppable
*
stoppableListener
func
newStoppable
(
l
net
.
Listener
)
(
sl
*
stoppableListener
)
{
sl
=
&
stoppableListener
{
Listener
:
l
}
// this goroutine monitors the channel. Can't do this in
// Accept (below) because once it enters sl.Listener.Accept()
// it blocks. We unblock it by closing the fd it is trying to
// accept(2) on.
go
func
()
{
WaitSignal
(
l
)
sl
.
stopped
=
true
sl
.
Listener
.
Close
()
}()
return
}
// Set stopped Listener to accept requests again.
// it returns the accepted and closable connection or error.
func
(
sl
*
stoppableListener
)
Accept
()
(
c
net
.
Conn
,
err
error
)
{
c
,
err
=
sl
.
Listener
.
Accept
()
if
err
!=
nil
{
return
}
sl
.
wg
.
Add
(
1
)
// Wrap the returned connection, so that we can observe when
// it is closed.
c
=
conn
{
Conn
:
c
,
wg
:
&
sl
.
wg
}
return
}
// Listener waits signal to kill or interrupt then restart.
func
WaitSignal
(
l
net
.
Listener
)
error
{
ch
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
ch
,
os
.
Interrupt
,
os
.
Kill
)
for
{
sig
:=
<-
ch
log
.
Println
(
sig
.
String
())
switch
sig
{
case
os
.
Kill
:
return
nil
case
os
.
Interrupt
:
err
:=
Restart
(
l
)
if
nil
!=
err
{
return
err
}
return
nil
}
}
}
// Kill current running os process.
func
CloseSelf
()
error
{
ppid
:=
os
.
Getpid
()
if
ppid
==
1
{
// init provided sockets, for example systemd
return
nil
}
p
,
err
:=
os
.
FindProcess
(
ppid
)
if
err
!=
nil
{
return
err
}
return
p
.
Kill
()
}
// Re-exec this image without dropping the listener passed to this function.
func
Restart
(
l
net
.
Listener
)
error
{
argv0
,
err
:=
exec
.
LookPath
(
os
.
Args
[
0
])
if
nil
!=
err
{
return
err
}
wd
,
err
:=
os
.
Getwd
()
if
nil
!=
err
{
return
err
}
v
:=
reflect
.
ValueOf
(
l
)
.
Elem
()
.
FieldByName
(
"fd"
)
.
Elem
()
fd
:=
uintptr
(
v
.
FieldByName
(
"sysfd"
)
.
Int
())
allFiles
:=
append
([]
*
os
.
File
{
os
.
Stdin
,
os
.
Stdout
,
os
.
Stderr
},
os
.
NewFile
(
fd
,
string
(
v
.
FieldByName
(
"sysfile"
)
.
String
())))
p
,
err
:=
os
.
StartProcess
(
argv0
,
os
.
Args
,
&
os
.
ProcAttr
{
Dir
:
wd
,
Env
:
append
(
os
.
Environ
(),
fmt
.
Sprintf
(
"%s=%d"
,
FDKey
,
fd
)),
Files
:
allFiles
,
})
if
nil
!=
err
{
return
err
}
log
.
Printf
(
"spawned child %d
\n
"
,
p
.
Pid
)
return
nil
}
// Get current net.Listen in running process.
func
GetInitListener
(
tcpaddr
*
net
.
TCPAddr
)
(
l
net
.
Listener
,
err
error
)
{
countStr
:=
os
.
Getenv
(
FDKey
)
if
countStr
==
""
{
return
net
.
ListenTCP
(
"tcp"
,
tcpaddr
)
}
count
,
err
:=
strconv
.
Atoi
(
countStr
)
if
err
!=
nil
{
return
nil
,
err
}
f
:=
os
.
NewFile
(
uintptr
(
count
),
"listen socket"
)
l
,
err
=
net
.
FileListener
(
f
)
if
err
!=
nil
{
return
nil
,
err
}
return
l
,
nil
}
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