(configPath string)
| 410 | } |
| 411 | |
| 412 | func 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 | |
| 461 | func moduleReload(oldContainer *container.C, configPath string, asyncStopWg *sync.WaitGroup) *container.C { |
| 462 | oldContainer.DefaultLogger.Msg("reloading server...") |
no test coverage detected