Exemplo n.º 1
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
Exemplo n.º 2
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")