04290dfc by astaxie

beego: delete hotupdate

1 parent 3f2a712b
...@@ -107,7 +107,6 @@ func listConf(rw http.ResponseWriter, r *http.Request) { ...@@ -107,7 +107,6 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
107 fmt.Fprintln(rw, "MaxMemory:", MaxMemory) 107 fmt.Fprintln(rw, "MaxMemory:", MaxMemory)
108 fmt.Fprintln(rw, "EnableGzip:", EnableGzip) 108 fmt.Fprintln(rw, "EnableGzip:", EnableGzip)
109 fmt.Fprintln(rw, "DirectoryIndex:", DirectoryIndex) 109 fmt.Fprintln(rw, "DirectoryIndex:", DirectoryIndex)
110 fmt.Fprintln(rw, "EnableHotUpdate:", EnableHotUpdate)
111 fmt.Fprintln(rw, "HttpServerTimeOut:", HttpServerTimeOut) 110 fmt.Fprintln(rw, "HttpServerTimeOut:", HttpServerTimeOut)
112 fmt.Fprintln(rw, "ErrorsShow:", ErrorsShow) 111 fmt.Fprintln(rw, "ErrorsShow:", ErrorsShow)
113 fmt.Fprintln(rw, "XSRFKEY:", XSRFKEY) 112 fmt.Fprintln(rw, "XSRFKEY:", XSRFKEY)
......
...@@ -45,7 +45,7 @@ func (app *App) Run() { ...@@ -45,7 +45,7 @@ func (app *App) Run() {
45 err error 45 err error
46 l net.Listener 46 l net.Listener
47 ) 47 )
48 endRunning := make(chan bool) 48 endRunning := make(chan bool, 1)
49 49
50 if UseFcgi { 50 if UseFcgi {
51 if HttpPort == 0 { 51 if HttpPort == 0 {
...@@ -58,26 +58,6 @@ func (app *App) Run() { ...@@ -58,26 +58,6 @@ func (app *App) Run() {
58 } 58 }
59 err = fcgi.Serve(l, app.Handlers) 59 err = fcgi.Serve(l, app.Handlers)
60 } else { 60 } else {
61 if EnableHotUpdate {
62 server := &http.Server{
63 Handler: app.Handlers,
64 ReadTimeout: time.Duration(HttpServerTimeOut) * time.Second,
65 WriteTimeout: time.Duration(HttpServerTimeOut) * time.Second,
66 }
67 laddr, err := net.ResolveTCPAddr("tcp", addr)
68 if nil != err {
69 BeeLogger.Critical("ResolveTCPAddr:", err)
70 }
71 l, err = GetInitListener(laddr)
72 if err == nil {
73 theStoppable = newStoppable(l)
74 err = server.Serve(theStoppable)
75 if err == nil {
76 theStoppable.wg.Wait()
77 err = CloseSelf()
78 }
79 }
80 } else {
81 s := &http.Server{ 61 s := &http.Server{
82 Addr: addr, 62 Addr: addr,
83 Handler: app.Handlers, 63 Handler: app.Handlers,
...@@ -109,7 +89,6 @@ func (app *App) Run() { ...@@ -109,7 +89,6 @@ func (app *App) Run() {
109 }() 89 }()
110 } 90 }
111 } 91 }
112 }
113 92
114 <-endRunning 93 <-endRunning
115 } 94 }
......
...@@ -56,7 +56,6 @@ var ( ...@@ -56,7 +56,6 @@ var (
56 MaxMemory int64 56 MaxMemory int64
57 EnableGzip bool // flag of enable gzip 57 EnableGzip bool // flag of enable gzip
58 DirectoryIndex bool // flag of display directory index. default is false. 58 DirectoryIndex bool // flag of display directory index. default is false.
59 EnableHotUpdate bool // flag of hot update checking by app self. default is false.
60 HttpServerTimeOut int64 59 HttpServerTimeOut int64
61 ErrorsShow bool // flag of show errors in page. if true, show error and trace info in page rendered with error template. 60 ErrorsShow bool // flag of show errors in page. if true, show error and trace info in page rendered with error template.
62 XSRFKEY string // xsrf hash salt string. 61 XSRFKEY string // xsrf hash salt string.
...@@ -101,6 +100,7 @@ func init() { ...@@ -101,6 +100,7 @@ func init() {
101 100
102 // set this to 0.0.0.0 to make this app available to externally 101 // set this to 0.0.0.0 to make this app available to externally
103 EnableHttpListen = true //default enable http Listen 102 EnableHttpListen = true //default enable http Listen
103
104 HttpAddr = "" 104 HttpAddr = ""
105 HttpPort = 8080 105 HttpPort = 8080
106 106
...@@ -254,10 +254,6 @@ func ParseConfig() (err error) { ...@@ -254,10 +254,6 @@ func ParseConfig() (err error) {
254 DirectoryIndex = directoryindex 254 DirectoryIndex = directoryindex
255 } 255 }
256 256
257 if hotupdate, err := AppConfig.Bool("HotUpdate"); err == nil {
258 EnableHotUpdate = hotupdate
259 }
260
261 if timeout, err := AppConfig.Int64("HttpServerTimeOut"); err == nil { 257 if timeout, err := AppConfig.Int64("HttpServerTimeOut"); err == nil {
262 HttpServerTimeOut = timeout 258 HttpServerTimeOut = timeout
263 } 259 }
......
1 // Beego (http://beego.me/)
2 // @description beego is an open-source, high-performance web framework for the Go programming language.
3 // @link http://github.com/astaxie/beego for the canonical source repository
4 // @license http://github.com/astaxie/beego/blob/master/LICENSE
5 // @authors astaxie
6
7 package beego
8
9 import (
10 "errors"
11 "fmt"
12 "log"
13 "net"
14 "os"
15 "os/exec"
16 "os/signal"
17 "reflect"
18 "strconv"
19 "sync"
20 //"syscall"
21 )
22
23 const (
24 // An environment variable when restarting application http listener.
25 FDKey = "BEEGO_HOT_FD"
26 )
27
28 // Export an error equivalent to net.errClosing for use with Accept during
29 // a graceful exit.
30 var ErrClosing = errors.New("use of closed network connection")
31 var ErrInitStart = errors.New("init from")
32
33 // Allows for us to notice when the connection is closed.
34 type conn struct {
35 net.Conn
36 wg *sync.WaitGroup
37 isclose bool
38 lock *sync.Mutex
39 }
40
41 // Close current processing connection.
42 func (c conn) Close() error {
43 c.lock.Lock()
44 defer c.lock.Unlock()
45 err := c.Conn.Close()
46 if !c.isclose && err == nil {
47 c.wg.Done()
48 c.isclose = true
49 }
50 return err
51 }
52
53 type stoppableListener struct {
54 net.Listener
55 count int64
56 stopped bool
57 wg sync.WaitGroup
58 }
59
60 var theStoppable *stoppableListener
61
62 func newStoppable(l net.Listener) (sl *stoppableListener) {
63 sl = &stoppableListener{Listener: l}
64
65 // this goroutine monitors the channel. Can't do this in
66 // Accept (below) because once it enters sl.Listener.Accept()
67 // it blocks. We unblock it by closing the fd it is trying to
68 // accept(2) on.
69 go func() {
70 WaitSignal(l)
71 sl.stopped = true
72 sl.Listener.Close()
73 }()
74 return
75 }
76
77 // Set stopped Listener to accept requests again.
78 // it returns the accepted and closable connection or error.
79 func (sl *stoppableListener) Accept() (c net.Conn, err error) {
80 c, err = sl.Listener.Accept()
81 if err != nil {
82 return
83 }
84 sl.wg.Add(1)
85 // Wrap the returned connection, so that we can observe when
86 // it is closed.
87 c = conn{Conn: c, wg: &sl.wg}
88
89 return
90 }
91
92 // Listener waits signal to kill or interrupt then restart.
93 func WaitSignal(l net.Listener) error {
94 ch := make(chan os.Signal, 1)
95 signal.Notify(ch, os.Interrupt, os.Kill)
96 for {
97 sig := <-ch
98 log.Println(sig.String())
99 switch sig {
100
101 case os.Kill:
102 return nil
103 case os.Interrupt:
104 err := Restart(l)
105 if nil != err {
106 return err
107 }
108 return nil
109 }
110 }
111 }
112
113 // Kill current running os process.
114 func CloseSelf() error {
115 ppid := os.Getpid()
116 if ppid == 1 { // init provided sockets, for example systemd
117 return nil
118 }
119 p, err := os.FindProcess(ppid)
120 if err != nil {
121 return err
122 }
123 return p.Kill()
124 }
125
126 // Re-exec this image without dropping the listener passed to this function.
127 func Restart(l net.Listener) error {
128 argv0, err := exec.LookPath(os.Args[0])
129 if nil != err {
130 return err
131 }
132 wd, err := os.Getwd()
133 if nil != err {
134 return err
135 }
136 v := reflect.ValueOf(l).Elem().FieldByName("fd").Elem()
137 fd := uintptr(v.FieldByName("sysfd").Int())
138 allFiles := append([]*os.File{os.Stdin, os.Stdout, os.Stderr},
139 os.NewFile(fd, string(v.FieldByName("sysfile").String())))
140
141 p, err := os.StartProcess(argv0, os.Args, &os.ProcAttr{
142 Dir: wd,
143 Env: append(os.Environ(), fmt.Sprintf("%s=%d", FDKey, fd)),
144 Files: allFiles,
145 })
146 if nil != err {
147 return err
148 }
149 log.Printf("spawned child %d\n", p.Pid)
150 return nil
151 }
152
153 // Get current net.Listen in running process.
154 func GetInitListener(tcpaddr *net.TCPAddr) (l net.Listener, err error) {
155 countStr := os.Getenv(FDKey)
156 if countStr == "" {
157 return net.ListenTCP("tcp", tcpaddr)
158 }
159 count, err := strconv.Atoi(countStr)
160 if err != nil {
161 return nil, err
162 }
163 f := os.NewFile(uintptr(count), "listen socket")
164 l, err = net.FileListener(f)
165 if err != nil {
166 return nil, err
167 }
168 return l, nil
169 }
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!