()
| 71 | } |
| 72 | |
| 73 | func start() error { |
| 74 | // Initialize zones. |
| 75 | if err := InitializeZones(); err != nil { |
| 76 | return err |
| 77 | } |
| 78 | |
| 79 | if conf.Integrated() { |
| 80 | // Add config listener to enable/disable SPN. |
| 81 | module.instance.Config().EventConfigChange.AddCallback("spn enable check", func(wc *mgr.WorkerCtx, s struct{}) (bool, error) { |
| 82 | // Do not do anything when we are shutting down. |
| 83 | if module.instance.IsShuttingDown() { |
| 84 | return true, nil |
| 85 | } |
| 86 | |
| 87 | enabled := config.GetAsBool("spn/enable", false) |
| 88 | if enabled() { |
| 89 | log.Info("spn: starting SPN") |
| 90 | module.mgr.Go("ensure SPN is started", module.instance.SPNGroup().EnsureStartedWorker) |
| 91 | } else { |
| 92 | log.Info("spn: stopping SPN") |
| 93 | module.mgr.Go("ensure SPN is stopped", module.instance.SPNGroup().EnsureStoppedWorker) |
| 94 | } |
| 95 | return false, nil |
| 96 | }) |
| 97 | |
| 98 | // Load tokens from database. |
| 99 | loadTokens() |
| 100 | |
| 101 | // Check if we need to enable SPN now. |
| 102 | enabled := config.GetAsBool("spn/enable", false) |
| 103 | if enabled() { |
| 104 | module.mgr.Go("ensure SPN is started", module.instance.SPNGroup().EnsureStartedWorker) |
| 105 | } |
| 106 | |
| 107 | // Register new task. |
| 108 | module.updateAccountWorkerMgr.Delay(1 * time.Minute) |
| 109 | } |
| 110 | |
| 111 | return nil |
| 112 | } |
| 113 | |
| 114 | func stop() error { |
| 115 | if conf.Integrated() { |
no test coverage detected