ffstatus-daemon.py 725 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/python
  2. from __future__ import print_function
  3. import daemon
  4. import logging
  5. import sys
  6. import time
  7. import ffstatus
  8. LOGFILE = '/var/log/ffstatus.log'
  9. logging.basicConfig(
  10. filename=LOGFILE,
  11. format='%(asctime)s [%(levelname)s] %(message)s',
  12. datefmt='%Y-%m-%d %H:%M:%S',
  13. level=logging.INFO,
  14. )
  15. a = ffstatus.AlfredParser()
  16. try:
  17. a.sanitycheck()
  18. except Exception as err:
  19. logging.critical("Failed sanity-check: " + str(err))
  20. print('FAILED SANITY CHECK: ' + str(err))
  21. sys.exit(1)
  22. daemon_context = daemon.DaemonContext(
  23. files_preserve=[handler.stream]
  24. )
  25. with daemon_context:
  26. while True:
  27. try:
  28. logging.debug('Execute')
  29. a.execute()
  30. time.sleep(15)
  31. except Exception as err:
  32. logging.error(str(err))