Ejemplo n.º 1
0
 def run(self):
     from counterblock.lib import config_util
     config_util.generate_config_files()
Ejemplo n.º 2
0
def main():
    # Post installation tasks
    config_util.generate_config_files()

    # Parse command-line arguments.
    parser = argparse.ArgumentParser(prog='counterblock', description='counterblock daemon')

    parser.add_argument(
        '-V', '--version', action='version', version="counterblock %s" % config.VERSION)
    parser.add_argument('--config-file', help='the path to the configuration file')
    config_util.add_config_arguments(parser, CONFIG_ARGS, 'server.conf')

    # actions
    subparsers = parser.add_subparsers(dest='command', help='the action to be taken')
    subparsers.required = True
    parser_server = subparsers.add_parser('server', help='Run counterblock')
    parser_reparse = subparsers.add_parser('reparse', help='Reparse the counterblock database')
    parser_enmod = subparsers.add_parser('enmod', help='Enable a module')
    parser_enmod.add_argument('module_path', type=str, help='Full Path of module to Enable relative to Counterblockd directory')
    parser_dismod = subparsers.add_parser('dismod', help='Disable a module')
    parser_dismod.add_argument('module_path', type=str, help='Path of module to Disable relative to Counterblockd directory')
    parser_listmod = subparsers.add_parser('listmod', help='Display Module Config')
    parser_rollback = subparsers.add_parser('rollback', help='Rollback to a specific block number')
    parser_rollback.add_argument('block_index', type=int, help='Block index to roll back to')

    args = parser.parse_args()

    config.init(args)

    log.set_up(args.verbose)

    # log unhandled errors.
    def handle_exception(exc_type, exc_value, exc_traceback):
        logger.error("Unhandled Exception", exc_info=(exc_type, exc_value, exc_traceback))
    sys.excepthook = handle_exception

    # Create/update pid file
    pid = str(os.getpid())
    pidf = open(config.PID, 'w')
    pidf.write(pid)
    pidf.close()

    # load any 3rd party modules
    module.load_all()

    # Handle arguments
    if args.command == 'enmod':
        module.toggle(args.module_path, True)
        sys.exit(0)
    elif args.command == 'dismod':
        module.toggle(args.module_path, False)
        sys.exit(0)
    elif args.command == 'listmod':
        module.list_all()
        sys.exit(0)
    elif args.command == 'reparse':
        startup.init_mongo()
        database.reparse(quit_after=True)
    elif args.command == 'rollback':
        assert args.block_index >= 1
        startup.init_mongo()
        database.rollback(args.block_index)
        sys.exit(0)

    logger.info("counterblock Version %s starting ..." % config.VERSION)

    # Run Startup Functions
    StartUpProcessor.run_active_functions()
Ejemplo n.º 3
0
def main():
    # Post installation tasks
    config_util.generate_config_files()

    # Parse command-line arguments.
    parser = argparse.ArgumentParser(prog='counterblock',
                                     description='counterblock daemon')

    parser.add_argument('-V',
                        '--version',
                        action='version',
                        version="counterblock %s" % config.VERSION)
    parser.add_argument('--config-file',
                        help='the path to the configuration file')
    config_util.add_config_arguments(parser, CONFIG_ARGS, 'server.conf')

    # actions
    subparsers = parser.add_subparsers(dest='command',
                                       help='the action to be taken')
    subparsers.required = True
    parser_server = subparsers.add_parser('server', help='Run counterblock')
    parser_reparse = subparsers.add_parser(
        'reparse', help='Reparse the counterblock database')
    parser_enmod = subparsers.add_parser('enmod', help='Enable a module')
    parser_enmod.add_argument(
        'module_path',
        type=str,
        help='Full Path of module to Enable relative to Counterblockd directory'
    )
    parser_dismod = subparsers.add_parser('dismod', help='Disable a module')
    parser_dismod.add_argument(
        'module_path',
        type=str,
        help='Path of module to Disable relative to Counterblockd directory')
    parser_listmod = subparsers.add_parser('listmod',
                                           help='Display Module Config')
    parser_rollback = subparsers.add_parser(
        'rollback', help='Rollback to a specific block number')
    parser_rollback.add_argument('block_index',
                                 type=int,
                                 help='Block index to roll back to')

    args = parser.parse_args()

    config.init(args)

    log.set_up(args.verbose)

    # log unhandled errors.
    def handle_exception(exc_type, exc_value, exc_traceback):
        logger.error("Unhandled Exception",
                     exc_info=(exc_type, exc_value, exc_traceback))

    sys.excepthook = handle_exception

    # Create/update pid file
    pid = str(os.getpid())
    pidf = open(config.PID, 'w')
    pidf.write(pid)
    pidf.close()

    # load any 3rd party modules
    module.load_all()

    # Handle arguments
    logger.info("counterblock command specified: {}".format(args.command))
    if args.command == 'enmod':
        module.toggle(args.module_path, True)
        sys.exit(0)
    elif args.command == 'dismod':
        module.toggle(args.module_path, False)
        sys.exit(0)
    elif args.command == 'listmod':
        module.list_all()
        sys.exit(0)
    elif args.command == 'reparse':
        startup.init_mongo()
        database.init_reparse(quit_after=True)
    elif args.command == 'rollback':
        assert args.block_index >= 1
        startup.init_mongo()
        database.rollback(args.block_index)
        sys.exit(0)

    assert args.command in ('server', 'reparse')
    logger.info("counterblock Version %s starting ..." % config.VERSION)

    # Run Startup Functions
    StartUpProcessor.run_active_functions()
Ejemplo n.º 4
0
    def run(self):
        from counterblock.lib import config_util

        config_util.generate_config_files()