def main(): parser = argparse.ArgumentParser() group1 = parser.add_mutually_exclusive_group() group1.add_argument("--start", action="store_true", default=False, help="start program") group1.add_argument("--stop", action="store_true", default=False, help="stop program") parser.add_argument("--no-daemon", action="store_true", default=None, help="run in no daemon mode") parser.add_argument("-p", "--pid-file", default=None, help="pid file") parser.add_argument("-l", "--log-file", default=None, help="log file") parser.add_argument("-c", "--config-file", default="./config.yml", help="config file") parser.add_argument("-v", "--verbosity", action="count", default=None, help="increase output verbosity") parser.add_argument("--version", action="version", version="Version %s" % __version__) parser.add_argument("--recalculate", action="store_true", default=False, help="recalculate data") parser.add_argument( "--platform", type=str, default=False, help=( "platform to recalculate, " "[cloudstack, ec2, ecs, eucalyptus, gce, idcf, openstack, " "rackspacenguk, rackspacengus]" ), ) parser.add_argument("--date-from", type=str, default=False, help="from date, 'YYYY-MM-DD' UTC") parser.add_argument("--date-to", type=str, default=False, help="to date, 'YYYY-MM-DD' UTC") args = parser.parse_args() try: config = yaml.safe_load(open(args.config_file))["scalr"] configure(config, args) except SystemExit: raise except: if args.verbosity > 3: raise else: sys.stderr.write("%s\n" % helper.exc_info(line_no=False)) sys.exit(1) try: app = AnalyticsProcessing() if args.start: if helper.check_pid(CONFIG["pid_file"]): msg = "Application with pid file '%s' already running. Exit" % CONFIG["pid_file"] LOG.info(msg) sys.exit(0) if not args.no_daemon: helper.daemonize() app.start() elif args.stop: app.stop() else: print "Usage %s -h" % sys.argv[0] except KeyboardInterrupt: LOG.critical("KeyboardInterrupt") return except SystemExit: pass except: LOG.exception("Something happened and I think I died") sys.exit(1)
def main(): parser = argparse.ArgumentParser() group = parser.add_mutually_exclusive_group() group.add_argument('--start', action='store_true', default=False, help='start program') group.add_argument('--stop', action='store_true', default=False, help='stop program') parser.add_argument('--no-daemon', action='store_true', default=None, help="run in no daemon mode") parser.add_argument('-p', '--pid-file', default=None, help="pid file") parser.add_argument('-l', '--log-file', default=None, help="log file") parser.add_argument('-c', '--config-file', default='./config.yml', help='config file') parser.add_argument('-i', '--interval', type=int, default=None, help="execution interval in seconds. Default is once") parser.add_argument('-v', '--verbosity', action='count', default=None, help='increase output verbosity') parser.add_argument('--version', action='version', version='Version %s' % __version__) args = parser.parse_args() try: config = yaml.safe_load(open(args.config_file))['scalr'] configure(config, args) except SystemExit: raise except: if args.verbosity > 3: raise else: sys.stderr.write('%s\n' % helper.exc_info()) sys.exit(1) try: app = AnalyticsPoller() if args.start: if helper.check_pid(CONFIG['pid_file']): msg = "Application with pid file '%s' already running. Exit" % CONFIG['pid_file'] LOG.info(msg) sys.exit(0) if not args.no_daemon: helper.daemonize() app.start() elif args.stop: app.stop() else: print 'Usage %s -h' % sys.argv[0] except KeyboardInterrupt: LOG.critical('KeyboardInterrupt') return except SystemExit: pass except: LOG.exception('Something happened and I think I died') sys.exit(1)
def _start(self): if helper.check_pid(self.config['pid_file']): raise exceptions.AlreadyRunningError(self.config['pid_file']) LOG.debug('Starting') if self.args['--daemon']: helper.daemonize() helper.create_pid_file(self.config['pid_file']) atexit.register(helper.delete_file, self.config['pid_file']) LOG.info('Started') helper.set_proc_name(self.name) self() LOG.info('Stopped')
def _start(self): if helper.check_pid(self.config['pid_file']): raise exceptions.AlreadyRunningError(self.config['pid_file']) LOG.debug(self._starting_msg) if self.args['--daemon']: helper.daemonize() helper.create_pid_file(self.config['pid_file']) atexit.register(helper.delete_file, self.config['pid_file']) helper.set_proc_name(self.name) self.start_dtime = datetime.datetime.utcnow() LOG.info('Started') self() LOG.info('Stopped')
def run(self): if self.args.start: if helper.check_pid(self.config['pid_file']): msg = "Application with pid file '%s' already running. Exit" % config['pid_file'] LOG.info(msg) sys.exit(0) if self.args.daemon: helper.daemonize() self.start() elif self.args.stop: self.stop() else: print 'Usage %s -h' % sys.argv[0]
def _start(self): if helper.check_pid(self.config['pid_file']): raise exceptions.AlreadyRunningError(self.config['pid_file']) LOG.debug(self._starting_msg) LOG.debug('Log file: {}'.format(self.config['log_file'])) LOG.debug('Pid file: {}'.format(self.config['pid_file'])) if self.args['--daemon']: helper.daemonize() helper.create_pid_file(self.config['pid_file']) atexit.register(helper.delete_file, self.config['pid_file']) helper.set_proc_name(self.name) self.start_dtime = datetime.datetime.utcnow() LOG.info('Started') self() LOG.info('Stopped')
def main(): parser = argparse.ArgumentParser() group = parser.add_mutually_exclusive_group() group.add_argument('--start', action='store_true', default=False, help='start program') group.add_argument('--stop', action='store_true', default=False, help='stop program') parser.add_argument('--poller', action='store_true', default=None, help='poller mode') parser.add_argument('--plotter', action='store_true', default=None, help='plotter mode') parser.add_argument('--no-daemon', action='store_true', default=None, help="run in no daemon mode") parser.add_argument('--with-snmp', action='store_true', default=None, help="use snmp") parser.add_argument('-i', '--interval', type=int, default=None, help="execution interval in seconds. Default is 120") parser.add_argument('-p', '--pid-file', default=None, help="pid file") parser.add_argument('-l', '--log-file', default=None, help="log file") parser.add_argument('-m', '--metrics', default=None, choices=['cpu', 'la', 'mem', 'net', 'io', 'snum'], action='append', help="metrics type for processing") parser.add_argument('-c', '--config-file', default='./config.yml', help='config file') parser.add_argument('-v', '--verbosity', default=None, action='count', help='increase output verbosity [0:4]. Default is 1 - Error') parser.add_argument('--version', action='version', version='Version %s' % __version__) args = parser.parse_args() try: global SCALR_CONFIG SCALR_CONFIG = yaml.safe_load(open(args.config_file))['scalr'] configure(args) except: if args.verbosity > 3: raise else: sys.stderr.write('%s\n' % helper.exc_info()) sys.exit(1) try: socket.setdefaulttimeout(CONFIG['instances_connection_timeout']) app = LoadStatistics() if args.start: if helper.check_pid(CONFIG['pid_file']): msg = "Application with pid file '%s' already running. Exit" % CONFIG['pid_file'] LOG.info(msg) sys.exit(0) if not args.no_daemon: helper.daemonize() app.start() elif args.stop: app.stop() else: print 'Usage %s -h' % sys.argv[0] except KeyboardInterrupt: sys.stdout.write('Keyboard interrupt\n') helper.kill_child(multiprocessing.current_process().pid) sys.exit(0) except SystemExit: pass except: LOG.exception('Something happened and I think I died') sys.exit(1)