app lal: 接收 USER1 USER2 信号,优雅退出

pull/200/head
q191201771 5 years ago
parent 07a6e6702e
commit bce56313ae

@ -6,11 +6,11 @@ import (
) )
type Config struct { type Config struct {
RTMP RTMP `json:"rtmp"`
SubIdleTimeout int64 `json:"sub_idle_timeout"` SubIdleTimeout int64 `json:"sub_idle_timeout"`
GOPCacheNum int `json:"gop_cache_number"` GOPCacheNum int `json:"gop_cache_number"`
HTTPFlv HTTPFlv `json:"httpflv"` HTTPFlv HTTPFlv `json:"httpflv"`
RTMP RTMP `json:"rtmp"`
Pull Pull `json:"pull"` Pull Pull `json:"pull"`
} }

@ -8,7 +8,8 @@ import (
"net/http" "net/http"
_ "net/http/pprof" _ "net/http/pprof"
"os" "os"
"time" "os/signal"
"syscall"
) )
var sm *ServerManager var sm *ServerManager
@ -20,11 +21,11 @@ func main() {
config := loadConf(confFile) config := loadConf(confFile)
sm = NewServerManager(config) sm = NewServerManager(config)
go sm.RunLoop()
//shutdownAfter(60 * time.Second) go runWebPProf()
go runSignalHandler()
startWebPProf() sm.RunLoop()
} }
func parseFlag() string { func parseFlag() string {
@ -67,18 +68,18 @@ func loadConf(confFile string) *Config {
return config return config
} }
func startWebPProf() { func runWebPProf() {
log.Info("start web pprof listen. addr=:10001")
if err := http.ListenAndServe("0.0.0.0:10001", nil); err != nil { if err := http.ListenAndServe("0.0.0.0:10001", nil); err != nil {
log.Error(err) log.Error(err)
return return
} }
log.Info("start pprof listen. addr=:10001")
} }
// TODO chef: 添加优雅退出信号处理 func runSignalHandler() {
func shutdownAfter(d time.Duration) { c := make(chan os.Signal)
go func() { signal.Notify(c, syscall.SIGUSR1, syscall.SIGUSR2)
time.Sleep(d) s := <-c
log.Infof("recv signal. s=%+v", s)
sm.Dispose() sm.Dispose()
}()
} }

@ -70,7 +70,9 @@ func (sm *ServerManager) RunLoop() {
func (sm *ServerManager) Dispose() { func (sm *ServerManager) Dispose() {
log.Debug("Dispose manager.") log.Debug("Dispose manager.")
if sm.httpFlvServer != nil {
sm.httpFlvServer.Dispose() sm.httpFlvServer.Dispose()
}
sm.rtmpServer.Dispose() sm.rtmpServer.Dispose()
sm.exitChan <- true sm.exitChan <- true
sm.mutex.Lock() sm.mutex.Lock()

@ -114,7 +114,7 @@ func (s *ServerSession) AsyncWrite(msg []byte) error {
return nil return nil
} }
func (s *ServerSession) ReadableType()string { func (s *ServerSession) ReadableType() string {
switch s.t { switch s.t {
case ServerSessionTypePub: case ServerSessionTypePub:
return "PUB" return "PUB"

Loading…
Cancel
Save