3

I try to get run the following code snippet. As soon as I daemonize the app, it doesn't watch for new incoming pcap files anymore.

#!/usr/bin/env pypy

 import daemon
 import watchdog
 import logging
 import logging.handlers
 from logging import info, debug, warn, error
 from watchdog.observers import Observer
 from watchdog.events import PatternMatchingEventHandler
 from time import sleep

 def main():
      def on_created_pcap(event):
           error(event.src_path)

     handler = logging.handlers.SysLogHandler("/var/run/syslog")
     formatter = "%(filename)s: [%(levelname)s] %(message)s"
     handler.setFormatter(logging.Formatter(formatter))
     logging.getLogger().addHandler(handler)

     pattern = ['*.pcap']
     event_handler = watchdog.events.PatternMatchingEventHandler(pattern)
     event_handler.on_created = on_created_pcap

     observer = Observer()
     observer.schedule(event_handler, "./")
     observer.start()
     while True:
         sleep(1)

with daemon.DaemonContext():
     main()

W/o the daemon context it works. Any ideas?

NB: I run the snippet on OS X. I you try it on Linux box you need to replace /var/run/syslog in the SysLogHandler w/ ('localhost', 514).

Kirsel
  • 31
  • 1

0 Answers0