Пример #1
0
 def _start_plugin_process(self, module_port):
     process._start_process("plugin-" +
                            self._manager._config.application.id + "." +
                            self._plugin_module,
                            "plugin_" + self._plugin_module,
                            self._manager._config,
                            nethelper.get_free_port([module_port]),
                            _KerviPluginProcess,
                            plugin_module=self._plugin_module,
                            plugin_config=self._config,
                            log_queue=self._manager._log_queue,
                            load_silent=self._manager._load_silent)
Пример #2
0
    def _start(self):
        self.started = True

        if self._as_service:
            import signal
            signal.signal(signal.SIGINT, handler_stop_signals)
            signal.signal(signal.SIGTERM, handler_stop_signals)

        try:
            import dashboards
        except ImportError:
            pass

        #self.spine.run()
        self.spine.send_command("startThreads", local_only=True)
        time.sleep(.5)

        module_port = self.config.network.ipc_module_port
        pluginManager = PluginManager(self.config)
        self._process_info_lock.acquire()
        #self._process_info = [{"id":"IPC", "ready":False}]
        plugin_modules = pluginManager.prepare_load()
        for plugin_module in plugin_modules:
            self._process_info.append({
                "id": plugin_module,
                "ready": False,
                "pid": None
            })
        self._process_info_lock.release()

        module_port = self.config.network.ipc_module_port
        module_port = pluginManager.load_plugins(module_port + 1)

        for module in self.config.modules:
            module_port += 1
            self._process_info_lock.acquire()
            self._process_info += [{"id": module, "ready": False, "pid": None}]
            self._process_info_lock.release()

            self._module_processes += [
                process._start_process("module-" + self.config.module.ip,
                                       module,
                                       self.config,
                                       nethelper.get_free_port([module_port]),
                                       app_helpers._KerviModuleLoader,
                                       process_id=self.config.module.id + "-" +
                                       module)
            ]

        while not self._is_ready():
            time.sleep(1)

        self._logger.info("module connected to application at: %s",
                          self._root_address)
        self._logger.info("Press ctrl + c to stop your module")
        self.spine.trigger_event("moduleReady", self.config.module.id)
        self.spine.send_command("kervi_action_module_main")
Пример #3
0
    def _start(self):
        self.started = True

        if self._as_service:
            import signal
            signal.signal(signal.SIGINT, handler_stop_signals)
            signal.signal(signal.SIGTERM, handler_stop_signals)

        try:
            import dashboards
        except ImportError:
            pass

        #self.spine.run()
        self.spine.send_command("startThreads", local_only=True)
        time.sleep(.5)

        module_port = self.config.network.ipc_module_port

        for module in self.config.modules:
            module_port += 1
            self._process_info_lock.acquire()
            self._process_info += [{"id":module, "ready":False}]
            self._process_info_lock.release()
                
            self._module_processes += [
                process._start_process(
                    "module-" + self.config.module.ip,
                    module,
                    self.config,
                    nethelper.get_free_port([module_port]),
                    app_helpers._KerviModuleLoader,
                    process_id=self.config.module.id + "-" + module
                )
            ]

        if not self.config.module.app_connection_local and self.config.routing.kervi_io.enabled:
            print("x")
            module_port += 1
            self._process_info_lock.acquire()
            self._process_info = [{"id":"kervi_io", "ready":False}]
            self._process_info_lock.release()

            self._module_processes += [
                process._start_process(
                    "module-routing" + self.config.module.id,
                    "kervi_io",
                    self.config,
                    nethelper.get_free_port([module_port]),
                    app_helpers._KerviIORouterProcess
                )
            ]
            #time.sleep(1)
        while not self._is_ready():
            time.sleep(1)
        
        print("module connected to application at:", self._root_address)
        print("Press ctrl + c to stop your module")
        self.spine.trigger_event(
            "moduleReady",
            self.config.module.id
        )
        self.spine.send_command("kervi_action_module_main")
Пример #4
0
    def _start(self):
        self.started = True

        try:
            import dashboards
        except ImportError:
            pass

        import kervi.core.utility.process as process
        import kervi.utility.application_helpers as app_helpers

        #if self._as_service:
        signal.signal(signal.SIGINT, handler_stop_signals)
        signal.signal(signal.SIGTERM, handler_stop_signals)

        self.spine.send_command("startThreads", local_only=True)
        time.sleep(.5)
        module_port = self.config.network.ipc_root_port
        pluginManager = PluginManager(self.config, log_queue=self._log_queue)
        self._process_info_lock.acquire()
        plugin_modules = pluginManager.prepare_load()
        for plugin_module in plugin_modules:
            self._process_info.append({
                "id": plugin_module,
                "ready": False,
                "pid": None
            })
        self._process_info_lock.release()

        module_port = pluginManager.load_plugins(module_port + 1)

        for module in self.config.modules:
            self._process_info_lock.acquire()
            self._process_info += [{"id": module, "ready": False, "pid": None}]
            self._process_info_lock.release()

            module_port += 1
            self._module_processes += [
                process._start_process("app-" + self.config.application.id,
                                       module,
                                       self.config,
                                       nethelper.get_free_port([module_port]),
                                       app_helpers._KerviModuleLoader,
                                       log_queue=self._log_queue)
            ]

        #print("wait for ready")
        try:
            while not self.char_list and not self._is_ready():
                #print(self.char_list)
                time.sleep(1)
        except KeyboardInterrupt:
            pass

        #print("pi", self._process_info)

        if not self._in_stop:
            from kervi.dashboards import Dashboard
            Dashboard._add_default()

            self.spine.send_command("kervi_action_app_main")
            ready_message = "Your Kervi application is running"
            self._logger.info(ready_message)

            self._logger.info("Press ctrl + c to stop your application")
            self.spine.trigger_event("appReady", self.config.application.id)

            if self.config.discovery.enabled:
                self._discovery_thread = KerviAppDiscovery(
                    self.config.network.ip,
                    self.config.network.ipc_root_port,
                    self.config.discovery.port,
                    self.config.application.id,
                    self.config.discovery.challenge,
                    self.config.application.name,
                    "http://" + self.config.network.
                    ip  # + ":" + str(self.config.network.http_port)
                )
                self._discovery_thread.start()
            else:
                self._discovery_thread = None
Пример #5
0
    def _start(self):
        self.started = True

        try:
            import dashboards
        except ImportError:
            pass

        import kervi.core.utility.process as process
        import kervi.utility.application_helpers as app_helpers

        if self._as_service:
            signal.signal(signal.SIGINT, handler_stop_signals)
            signal.signal(signal.SIGTERM, handler_stop_signals)

        self.spine.send_command("startThreads", local_only=True)
        time.sleep(.5)
        module_port = self.config.network.ipc_root_port

        self._process_info_lock.acquire()
        self._process_info = [{"id": "IPC", "ready": False}]
        self._process_info_lock.release()

        module_port += 1
        self._module_processes += [
            process._start_process("app-" + self.config.application.id, "IPC",
                                   self.config,
                                   nethelper.get_free_port([module_port]),
                                   app_helpers._KerviSocketIPC)
        ]

        for module in self.config.modules:
            self._process_info_lock.acquire()
            self._process_info += [{"id": module, "ready": False}]
            self._process_info_lock.release()

            module_port += 1
            self._module_processes += [
                process._start_process("app-" + self.config.application.id,
                                       module, self.config,
                                       nethelper.get_free_port([module_port]),
                                       app_helpers._KerviModuleLoader)
            ]

        # if self.config.routing.kervi_io.enabled:
        #     module_port += 1
        #     self._module_processes += [
        #         process._start_process(
        #             "app-" + self.config.application.id,
        #             "kervi_io",
        #             self.config,
        #             nethelper.get_free_port([module_port]),
        #             app_helpers._KerviIORouterProcess
        #         )
        #     ]

        while not self._is_ready():
            time.sleep(1)

        #self._module_processes += app_helpers.load_plugins(self.config, module_port)

        from kervi.dashboards import Dashboard
        Dashboard._add_default()

        import platform
        if platform.system() != "Windows":
            print("\033[92mYour Kervi application is ready at http://" +
                  self.config.network.ip + ":" +
                  str(self.config.network.http_port) + "\033[0m")
        else:
            print("Your Kervi application is ready at http://" +
                  self.config.network.ip + ":" +
                  str(self.config.network.http_port))
        print("Press ctrl + c to stop your application")
        import kervi.ui.webserver as webserver
        webserver.start(self.config.network.ip, self.config.network.http_port,
                        self.config.network.ws_port)
        self.spine.trigger_event("appReady", self.config.application.id)
        self.spine.send_command("startWebSocket")
        self.spine.send_command("kervi_action_app_main")