1
0
Fork 0
forked from External/mediamtx

fix hot reloading of configuration on macOS and with text editors that deletes and recreates the configuration file

This commit is contained in:
aler9 2020-11-26 21:44:16 +01:00
parent e0845a0af8
commit 0f11dd5c71
2 changed files with 36 additions and 22 deletions

30
main.go
View file

@ -68,13 +68,20 @@ func newProgram(args []string) (*program, error) {
return nil, err
}
err = p.createResources(true)
err = p.createDynamicResources(true)
if err != nil {
p.closeResources()
p.closeAllResources()
return nil, err
}
p.confWatcher, err = confwatcher.New(p.confPath)
if err != nil {
p.closeAllResources()
return nil, err
}
go p.run()
return p, nil
}
@ -110,10 +117,10 @@ outer:
}
}
p.closeResources()
p.closeAllResources()
}
func (p *program) createResources(initial bool) error {
func (p *program) createDynamicResources(initial bool) error {
var err error
if p.stats == nil {
@ -187,17 +194,10 @@ func (p *program) createResources(initial bool) error {
p.pathMan, p.serverTcp, p)
}
if p.confWatcher == nil {
p.confWatcher, err = confwatcher.New(p.confPath)
if err != nil {
return err
}
}
return nil
}
func (p *program) closeResources() {
func (p *program) closeAllResources() {
if p.confWatcher != nil {
p.confWatcher.Close()
}
@ -243,10 +243,6 @@ func (p *program) reloadConf() error {
return err
}
// always recreate confWatcher to avoid reloading twice
p.confWatcher.Close()
p.confWatcher = nil
closeLogHandler := false
if !reflect.DeepEqual(conf.LogDestinationsParsed, p.conf.LogDestinationsParsed) ||
conf.LogFile != p.conf.LogFile {
@ -345,7 +341,7 @@ func (p *program) reloadConf() error {
}
p.conf = conf
return p.createResources(false)
return p.createDynamicResources(false)
}
func main() {