systemd journal watcher daemon in ruby
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
595 B

  1. module JournaldWatcher
  2. class Listener
  3. def initialize(journal, filter)
  4. @journal = journal
  5. @filter = filter
  6. end
  7. def listen(&block)
  8. @journal.filter @filter
  9. @journal.seek :tail
  10. @journal.move_previous_skip 1 # workaround due to systemd bug, see https://bugzilla.redhat.com/show_bug.cgi?id=979487
  11. watch { |entry| block.call(entry) }
  12. end
  13. private
  14. # like Systemd::Journal.watch but don't wait forever
  15. def watch
  16. loop { (yield @journal.current_entry while @journal.move_next) if @journal.wait(100_000) }
  17. end
  18. end
  19. end