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

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

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

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

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

Loading…
Cancel
Save