Virustotal integration for amavisd-new
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.

74 lines
1.8KB

  1. # -*- coding: utf-8 -*-
  2. import threading
  3. import signal
  4. import logging
  5. from argparse import ArgumentParser
  6. from logging.handlers import SysLogHandler
  7. import sys
  8. from amavisvt.client import Configuration
  9. from amavisvt.daemon import AmavisVTDaemon
  10. logger = logging.getLogger(__file__)
  11. if __name__ == "__main__":
  12. parser = ArgumentParser()
  13. parser.add_argument('-v', '--verbose', action='count', help='Increase verbosity', default=2)
  14. parser.add_argument('-d', '--debug', action='store_true', default=False, help='Send verbose log messages to stdout too')
  15. parser.add_argument('-s', '--socket', help='Socket path')
  16. args = parser.parse_args()
  17. logging.basicConfig(
  18. level=logging.FATAL - (10 * args.verbose),
  19. format='%(asctime)s %(levelname)-7s [%(threadName)s] %(message)s',
  20. )
  21. logger = logging.getLogger()
  22. if not args.debug:
  23. for h in logger.handlers:
  24. h.setLevel(logging.ERROR)
  25. handler = SysLogHandler(address='/dev/log')
  26. formatter = logging.Formatter('amavisvt: %(threadName)s - %(message)s')
  27. handler.setFormatter(formatter)
  28. logger.addHandler(handler)
  29. logger.info("Starting up")
  30. daemon = None
  31. shutdown_sig = threading.Event()
  32. def _sig_handler(sig, frame):
  33. logger.debug("Handler received signal %s", sig)
  34. if sig in (signal.SIGTERM, signal.SIGKILL, signal.SIGINT):
  35. shutdown_sig.set()
  36. daemon.stop()
  37. signal.signal(signal.SIGUSR1, _sig_handler)
  38. signal.signal(signal.SIGINT, _sig_handler)
  39. error = False
  40. try:
  41. config = Configuration()
  42. daemon = AmavisVTDaemon(config, socket_path=args.socket)
  43. daemon.run_and_wait()
  44. while True:
  45. shutdown_sig.wait(5)
  46. if shutdown_sig.is_set():
  47. break
  48. except KeyboardInterrupt:
  49. pass
  50. error = True
  51. except:
  52. logger.exception("Server error")
  53. error = True
  54. finally:
  55. if daemon:
  56. daemon.stop()
  57. sys.exit(int(error))