Reload loads rules from the specified path, deleting existing loaded rules from memory.
(path string)
| 88 | // Reload loads rules from the specified path, deleting existing loaded |
| 89 | // rules from memory. |
| 90 | func (l *Loader) Reload(path string) error { |
| 91 | if path == "" { |
| 92 | path = DefaultPath |
| 93 | } |
| 94 | log.Info("rules.Loader.Reload(): %s", path) |
| 95 | |
| 96 | // check that the new path exists before reloading |
| 97 | if core.Exists(path) == false { |
| 98 | return fmt.Errorf("The new path '%s' does not exist", path) |
| 99 | } |
| 100 | |
| 101 | // stop monitors |
| 102 | if l.isLiveReloadRunning() { |
| 103 | l.stopLiveReload <- struct{}{} |
| 104 | } |
| 105 | if l.watcher != nil { |
| 106 | l.watcher.Remove(l.Path) |
| 107 | } |
| 108 | for _, r := range l.rules { |
| 109 | l.cleanListsRule(r) |
| 110 | } |
| 111 | |
| 112 | // then delete the rules, and reload everything |
| 113 | l.Lock() |
| 114 | l.activeRules = make([]string, 0) |
| 115 | l.rules = make(map[string]*Rule) |
| 116 | l.Unlock() |
| 117 | return l.Load(path) |
| 118 | } |
| 119 | |
| 120 | // Load loads rules files from disk. |
| 121 | func (l *Loader) Load(path string) error { |
no test coverage detected