Ejemplo n.º 1
0
        def startup_modules(self):

            # Get the path where this file is located.
            app_path = os.path.split(os.path.realpath(__file__))[0]
            # Get our package path and package name
            base_path, package_name = os.path.split(app_path)

            # Get loadable module list
            mods = modules.__load_modules__(base_path=base_path)

            # Have each module do their startup work now.
            for mod in mods:
                mod.set_config(
                    self._config
                )  # Set the configuration information in the module.
                result = mod.service_startup()
                if result is not None and result is False:
                    _logger.critical(
                        'Module ({0}) failed during startup.'.format(
                            mod.get_name))
                    sys.exit(1)

            pmanager = Manager()
            mqueue = pmanager.Queue()

            # Keep the created child processes.
            cprocs = dict()  # Dictionary of module process handlers.
            cqueues = dict()  # Dictionary of module Queue objects.
            mlist = list()  # List of module names.

            # Get list of module names
            for mod in mods:
                mlist.append(mod.get_name())

            # Setup thread for modules wanting a processing thread.
            for mod in mods:
                name = mod.get_name()

                cprocs[
                    name] = None  # Add a place holder for the module process

                if mod.wants_processing_thread:
                    _logger.debug('Initializing thread for {0}.'.format(name))

                    cqueues[name] = multiprocessing.Queue()
                    cprocs[name] = multiprocessing.Process(
                        target=mod.process_handler,
                        args=(cqueues[name], mqueue, mlist))
                    cprocs[name].start()

            return mods, pmanager, mqueue, cprocs, cqueues, mlist
Ejemplo n.º 2
0
        def startup_modules(self):

            # Get the path where this file is located.
            app_path = os.path.split(os.path.realpath(__file__))[0]
            # Get our package path and package name
            base_path, package_name = os.path.split(app_path)

            # Get loadable module list
            mods = modules.__load_modules__(base_path=base_path)

            # Have each module do their startup work now.
            for mod in mods:
                mod.set_config(self._config)  # Set the configuration information in the module.
                result = mod.service_startup()
                if result is not None and result is False:
                    _logger.critical('Module ({0}) failed during startup.'.format(mod.get_name))
                    sys.exit(1)

            pmanager = Manager()
            mqueue = pmanager.Queue()

            # Keep the created child processes.
            cprocs = dict()   # Dictionary of module process handlers.
            cqueues = dict()  # Dictionary of module Queue objects.
            mlist = list()    # List of module names.

            # Get list of module names
            for mod in mods:
                mlist.append(mod.get_name())

            # Setup thread for modules wanting a processing thread.
            for mod in mods:
                name = mod.get_name()

                cprocs[name] = None  # Add a place holder for the module process

                if mod.wants_processing_thread:
                    _logger.debug('Initializing thread for {0}.'.format(name))

                    cqueues[name] = multiprocessing.Queue()
                    cprocs[name] = multiprocessing.Process(
                        target=mod.process_handler, args=(cqueues[name], mqueue, mlist))
                    cprocs[name].start()

            return mods, pmanager, mqueue, cprocs, cqueues, mlist
Ejemplo n.º 3
0
        def startup_modules(self):

            # Get the path where this file is located.
            app_path = os.path.split(os.path.realpath(__file__))[0]
            # Get our package path and package name
            base_path, package_name = os.path.split(app_path)

            # Get loadable module list
            mods = modules.__load_modules__(base_path=base_path)
            active_mods = []  # List of modules marked as active.
            running_mods = []  # List of modules that are really running.

            # Set the configuration in each module.
            for mod in mods:
                mod.set_config(
                    self._config
                )  # Set the configuration information in the module.

                # If the module is enabled, add it to the active_mods list.
                if mod.module_enabled():
                    active_mods.append(mod)
                else:
                    _logger.debug('Service: module {0} is disabled.'.format(
                        mod.get_name()))

            pmanager = Manager()
            mqueue = pmanager.Queue()

            # Keep the created child processes.
            cprocs = dict()  # Dictionary of module process handlers.
            cqueues = dict()  # Dictionary of module Queue objects.
            mlist = list()  # List of module names.

            # Sort modules by the priority attribute so we can start them in the proper order.
            sorted_mods = sorted(active_mods,
                                 key=operator.attrgetter('priority'))

            for mod in sorted_mods:
                _logger.debug('Service: starting module {0}: ({1})'.format(
                    mod.get_name(), mod.priority))

                if mod.service_startup() is False:
                    _logger.critical(
                        'Service: module ({0}) failed during startup.'.format(
                            mod.get_name))
                    # sys.exit(1)
                    continue

                name = mod.get_name()

                running_mods.append(mod)
                mlist.append(name)

                cprocs[
                    name] = None  # Add a place holder for the module process.

                # Setup thread for modules wanting a processing thread.
                if mod.wants_processing_thread:
                    # _logger.debug('Initializing thread for {0}.'.format(name))

                    cqueues[name] = multiprocessing.Queue()
                    cprocs[name] = multiprocessing.Process(
                        target=mod.process_handler,
                        args=(cqueues[name], mqueue, mlist))
                    cprocs[name].start()

                    # Give the firewall manager time to setup the initial rules.
                    if name == 'SilentDuneClientFirewallModule':
                        time.sleep(2)

            return running_mods, pmanager, mqueue, cprocs, cqueues, mlist
Ejemplo n.º 4
0
def run():

    # Set global debug value and setup application logging.
    _logger.addHandler(setup_logging('--debug' in sys.argv))

    # See if we need to dump information about this node.
    if '--debug' in sys.argv:
        node_info_dump(sys.argv)

    # Get the path where this file is located.
    app_path = os.path.split(os.path.realpath(__file__))[0]
    # Get our package path and package name
    base_path, package_name = os.path.split(app_path)

    # Check and make sure we can find the init scripts.
    if not os.path.exists(os.path.join(app_path, 'init/sdc-firewall.service.in')) or \
            not os.path.exists(os.path.join(app_path, 'init/sdc-firewall.init.in')):
        print(
            'sdc-install: error: Unable to locate client init scripts, unable to install'
        )
        sys.exit(1)

    # Setup i18n - Good for 2.x and 3.x python.
    kwargs = {}
    if sys.version_info[0] < 3:
        kwargs['unicode'] = True
    gettext.install('sdc_install', **kwargs)

    # Get loadable module list
    module_list = __load_modules__(base_path=base_path)

    # Setup program arguments.
    parser = argparse.ArgumentParser(prog='sdc-install')
    parser.add_argument(_('--debug'),
                        help=_('Enable debug output'),
                        default=False,
                        action='store_true')  # noqa

    # Loop through the module objects and add any argparse arguments.
    for mod in module_list:
        mod.add_installer_arguments(parser)

    args = parser.parse_args()

    # Have each module validate arguments.
    for mod in module_list:
        if mod.validate_arguments(
                args
        ) is False:  # If return value is None, we just want to continue.
            parser.print_help()
            exit(1)

    node_info = NodeInformation()

    # Instantiate the installer object
    i = Installer(args, module_list, node_info)

    # Begin the install process.
    if not i.start_install():

        # Have each module do their uninstall work now.
        for mod in module_list:
            mod.uninstall_module()

        i.clean_up()

        _logger.error('Install aborted.')
        return 1

    return 0
Ejemplo n.º 5
0
        def startup_modules(self):

            # Get the path where this file is located.
            app_path = os.path.split(os.path.realpath(__file__))[0]
            # Get our package path and package name
            base_path, package_name = os.path.split(app_path)

            # Get loadable module list
            mods = modules.__load_modules__(base_path=base_path)
            active_mods = []  # List of modules marked as active.
            running_mods = []  # List of modules that are really running.

            # Set the configuration in each module.
            for mod in mods:
                mod.set_config(self._config)  # Set the configuration information in the module.

                # If the module is enabled, add it to the active_mods list.
                if mod.module_enabled():
                    active_mods.append(mod)
                else:
                    _logger.debug('Service: module {0} is disabled.'.format(mod.get_name()))

            pmanager = Manager()
            mqueue = pmanager.Queue()

            # Keep the created child processes.
            cprocs = dict()   # Dictionary of module process handlers.
            cqueues = dict()  # Dictionary of module Queue objects.
            mlist = list()    # List of module names.

            # Sort modules by the priority attribute so we can start them in the proper order.
            sorted_mods = sorted(active_mods, key=operator.attrgetter('priority'))

            for mod in sorted_mods:
                _logger.debug('Service: starting module {0}: ({1})'.format(mod.get_name(), mod.priority))

                if mod.service_startup() is False:
                    _logger.critical('Service: module ({0}) failed during startup.'.format(mod.get_name))
                    # sys.exit(1)
                    continue

                name = mod.get_name()

                running_mods.append(mod)
                mlist.append(name)

                cprocs[name] = None  # Add a place holder for the module process.

                # Setup thread for modules wanting a processing thread.
                if mod.wants_processing_thread:
                    # _logger.debug('Initializing thread for {0}.'.format(name))

                    cqueues[name] = multiprocessing.Queue()
                    cprocs[name] = multiprocessing.Process(
                        target=mod.process_handler, args=(cqueues[name], mqueue, mlist))
                    cprocs[name].start()

                    # Give the firewall manager time to setup the initial rules.
                    if name == 'SilentDuneClientFirewallModule':
                        time.sleep(2)

            return running_mods, pmanager, mqueue, cprocs, cqueues, mlist
Ejemplo n.º 6
0
def run():

    # Set global debug value and setup application logging.
    _logger.addHandler(setup_logging('--debug' in sys.argv))

    # See if we need to dump information about this node.
    if '--debug' in sys.argv:
        node_info_dump(sys.argv)

    # Get the path where this file is located.
    app_path = os.path.split(os.path.realpath(__file__))[0]
    # Get our package path and package name
    base_path, package_name = os.path.split(app_path)

    # Check and make sure we can find the init scripts.
    if not os.path.exists(os.path.join(app_path, 'init/sdc-firewall.service.in')) or \
            not os.path.exists(os.path.join(app_path, 'init/sdc-firewall.init.in')):
        print('sdc-install: error: Unable to locate client init scripts, unable to install')
        sys.exit(1)

    # Setup i18n - Good for 2.x and 3.x python.
    kwargs = {}
    if sys.version_info[0] < 3:
        kwargs['unicode'] = True
    gettext.install('sdc_install', **kwargs)

    # Get loadable module list
    module_list = __load_modules__(base_path=base_path)

    # Setup program arguments.
    parser = argparse.ArgumentParser(prog='sdc-install')
    parser.add_argument(_('--debug'), help=_('Enable debug output'), default=False, action='store_true')  # noqa

    # Loop through the module objects and add any argparse arguments.
    for mod in module_list:
        mod.add_installer_arguments(parser)

    args = parser.parse_args()

    # Have each module validate arguments.
    for mod in module_list:
        if mod.validate_arguments(args) is False:  # If return value is None, we just want to continue.
            parser.print_help()
            exit(1)

    node_info = NodeInformation()

    # Instantiate the installer object
    i = Installer(args, module_list, node_info)

    # Begin the install process.
    if not i.start_install():

        # Have each module do their uninstall work now.
        for mod in module_list:
            mod.uninstall_module()

        i.clean_up()

        _logger.error('Install aborted.')
        return 1

    return 0