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

Function moduleMain

maddy.go:412–459  ·  view source on GitHub ↗
(configPath string)

Source from the content-addressed store, hash-verified

410}
411
412func moduleMain(configPath string) error {
413 log.DefaultLogger.Msg("loading configuration...")
414
415 // Make path absolute to make sure we can still read it if current directory changes (in moduleConfigure).
416 configPath, err := filepath.Abs(configPath)
417 if err != nil {
418 return err
419 }
420
421 c, err := moduleConfigure(configPath)
422 if err != nil {
423 return err
424 }
425
426 c.DefaultLogger.Msg("configuration loaded")
427
428 if err := moduleStart(c); err != nil {
429 return err
430 }
431 c.DefaultLogger.Msg("server started", "version", Version)
432
433 systemdStatus(SDReady, "Configuration running.")
434 asyncStopWg := sync.WaitGroup{} // Some containers might still be waiting on moduleStop
435 for handleSignals() {
436 hooks.RunHooks(hooks.EventReload)
437
438 c = moduleReload(c, configPath, &asyncStopWg)
439 }
440
441 c.DefaultLogger.Msg("server stopping...")
442
443 systemdStatus(SDStopping, "Waiting for old configuration to stop...")
444 asyncStopWg.Wait()
445
446 systemdStatus(SDStopping, "Waiting for current configuration to stop...")
447 if err := moduleStop(c, true); err != nil {
448 c.DefaultLogger.Msg("moduleStop failed", err)
449 }
450 c.DefaultLogger.Msg("server stopped")
451
452 if c.DefaultLogger.Out != nil {
453 if err := c.DefaultLogger.Close(); err != nil {
454 log.DefaultLogger.Error("failed to close output logger", err)
455 }
456 }
457
458 return nil
459}
460
461func moduleReload(oldContainer *container.C, configPath string, asyncStopWg *sync.WaitGroup) *container.C {
462 oldContainer.DefaultLogger.Msg("reloading server...")

Callers 1

RunFunction · 0.85

Calls 10

RunHooksFunction · 0.92
moduleConfigureFunction · 0.85
moduleStartFunction · 0.85
moduleReloadFunction · 0.85
moduleStopFunction · 0.85
MsgMethod · 0.80
systemdStatusFunction · 0.70
handleSignalsFunction · 0.70
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected