MCPcopy Index your code
hub / github.com/foxcpp/maddy / moduleReload

Function moduleReload

maddy.go:461–528  ·  view source on GitHub ↗
(oldContainer *container.C, configPath string, asyncStopWg *sync.WaitGroup)

Source from the content-addressed store, hash-verified

459}
460
461func moduleReload(oldContainer *container.C, configPath string, asyncStopWg *sync.WaitGroup) *container.C {
462 oldContainer.DefaultLogger.Msg("reloading server...")
463 systemdStatus(SDReloading, "Reloading server...")
464
465 rollbackReload := func() {
466 // Restore DefaultLogger config that might be set by moduleConfig
467 log.DefaultLogger.Out = oldContainer.DefaultLogger.Out
468 }
469
470 oldContainer.DefaultLogger.Msg("loading new configuration...")
471 newContainer, err := moduleConfigure(configPath)
472 if err != nil {
473 rollbackReload()
474 oldContainer.DefaultLogger.Error("failed to load new configuration", err)
475
476 return oldContainer
477 }
478
479 oldContainer.DefaultLogger.Msg("configuration loaded")
480 rollbackReload = func() {
481 // Restore DefaultLogger config that might be set by moduleConfig
482 log.DefaultLogger.Out = oldContainer.DefaultLogger.Out
483 container.Global = oldContainer
484 }
485
486 if err := oldContainer.Lifetime.EarlyStopAll(); err != nil {
487 rollbackReload()
488 oldContainer.DefaultLogger.Error("failed to early-stop old server", err)
489
490 return oldContainer
491 }
492
493 netresource.ResetListenersUsage()
494 oldContainer.DefaultLogger.Msg("starting new server")
495 if err := moduleStart(newContainer); err != nil {
496 rollbackReload()
497 oldContainer.DefaultLogger.Error("failed to start new server", err)
498
499 return oldContainer
500 }
501
502 newContainer.DefaultLogger.Msg("new server started", "version", Version)
503
504 systemdStatus(SDReloading, "New configuration running. Waiting for old connections and transactions to finish...")
505
506 asyncStopWg.Add(1)
507 go func() {
508 defer asyncStopWg.Done()
509 defer func() {
510 if err := netresource.CloseUnusedListeners(); err != nil {
511 oldContainer.DefaultLogger.Error("CloseUnusedListeners failed", err)
512 }
513 }()
514
515 oldContainer.DefaultLogger.Msg("stopping old server")
516 if err := moduleStop(oldContainer, false); err != nil {
517 oldContainer.DefaultLogger.Error("moduleStop failed", err)
518 }

Callers 1

moduleMainFunction · 0.85

Calls 11

ResetListenersUsageFunction · 0.92
CloseUnusedListenersFunction · 0.92
moduleConfigureFunction · 0.85
moduleStartFunction · 0.85
moduleStopFunction · 0.85
MsgMethod · 0.80
EarlyStopAllMethod · 0.80
AddMethod · 0.80
systemdStatusFunction · 0.70
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected