()
| 455 | } |
| 456 | |
| 457 | func (l *Loader) liveReloadWorker() { |
| 458 | l.setLiveReloadRunning(true) |
| 459 | defer l.setLiveReloadRunning(false) |
| 460 | |
| 461 | log.Debug("Rules watcher started on path %s ...", l.Path) |
| 462 | if err := l.watcher.Add(l.Path); err != nil { |
| 463 | log.Error("Could not watch path: %s", err) |
| 464 | return |
| 465 | } |
| 466 | |
| 467 | for { |
| 468 | select { |
| 469 | case <-l.stopLiveReload: |
| 470 | goto Exit |
| 471 | case event := <-l.watcher.Events: |
| 472 | // a new rule json file has been created or updated |
| 473 | if event.Op&fsnotify.Write == fsnotify.Write { |
| 474 | if strings.HasSuffix(event.Name, ".json") { |
| 475 | log.Important("Ruleset changed due to %s, reloading ...", path.Base(event.Name)) |
| 476 | if err := l.loadRule(event.Name); err != nil { |
| 477 | log.Warning("%s", err) |
| 478 | } |
| 479 | } |
| 480 | } else if event.Op&fsnotify.Remove == fsnotify.Remove { |
| 481 | if strings.HasSuffix(event.Name, ".json") { |
| 482 | log.Important("Rule deleted %s", path.Base(event.Name)) |
| 483 | // we only need to delete from memory rules of type Always, |
| 484 | // because the Remove event is of a file, i.e.: Duration == Always |
| 485 | l.deleteRule(event.Name) |
| 486 | } |
| 487 | } |
| 488 | case err := <-l.watcher.Errors: |
| 489 | log.Error("File system watcher error: %s", err) |
| 490 | } |
| 491 | } |
| 492 | Exit: |
| 493 | log.Debug("[rules] liveReloadWorker() exited") |
| 494 | } |
| 495 | |
| 496 | // FindFirstMatch will try match the connection against the existing rule set. |
| 497 | func (l *Loader) FindFirstMatch(con *conman.Connection) (match *Rule) { |
no test coverage detected