mirror of
https://github.com/bluenviron/mediamtx.git
synced 2025-12-20 02:00:05 -08:00
fix hot reloading of configuration on macOS and with text editors that deletes and recreates the configuration file
This commit is contained in:
parent
e0845a0af8
commit
0f11dd5c71
2 changed files with 36 additions and 22 deletions
30
main.go
30
main.go
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue