#!/usr/bin/env python """Runs the airtime_analyzer application. """ import daemon import argparse import os import airtime_analyzer.airtime_analyzer as aa VERSION = "1.0" DEFAULT_CONFIG_PATH = '/etc/airtime/airtime.conf' DEFAULT_HTTP_RETRY_PATH = '/tmp/airtime_analyzer_http_retries' def run(): '''Entry-point for this application''' print "Airtime Analyzer " + VERSION parser = argparse.ArgumentParser() parser.add_argument("-d", "--daemon", help="run as a daemon", action="store_true") parser.add_argument("--debug", help="log full debugging output", action="store_true") parser.add_argument("--config-file", help="specify a configuration file with RabbitMQ settings (default is %s)" % DEFAULT_CONFIG_PATH) parser.add_argument("--http-retry-queue-file", help="specify where incompleted HTTP requests will be serialized (default is %s)" % DEFAULT_HTTP_RETRY_PATH) args = parser.parse_args() check_if_media_monitor_is_running() #Default config file path config_path = DEFAULT_CONFIG_PATH http_retry_queue_path = DEFAULT_HTTP_RETRY_PATH if args.config_file: config_path = args.config_file if args.http_retry_queue_file: http_retry_queue_path = args.http_retry_queue_file if args.daemon: with daemon.DaemonContext(): aa.AirtimeAnalyzerServer(config_path=config_path, http_retry_queue_path=http_retry_queue_path, debug=args.debug) else: # Run without daemonizing aa.AirtimeAnalyzerServer(config_path=config_path, http_retry_queue_path=http_retry_queue_path, debug=args.debug) def check_if_media_monitor_is_running(): """Ensure media_monitor isn't running before we start. We do this because media_monitor will move newly uploaded files into the library on us and screw up the operation of airtime_analyzer. media_monitor is deprecated. """ pids = [pid for pid in os.listdir('/proc') if pid.isdigit()] for pid in pids: try: process_name = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read() if 'media_monitor.py' in process_name: print "Error: This process conflicts with media_monitor, and media_monitor is running." print " Please terminate the running media_monitor.py process and try again." exit(1) except IOError: # proc has already terminated continue run()