Exemple #1
0
    async def start_service(self, request):
        service_command = request["service"]
        service_name = service_command.split()[0]
        error = None
        success = False

        if not validate_service(service_name):
            error = "unknown service"

        if service_name in self.services:
            service = self.services[service_name]
            r = service is not None and service.poll() is None
            if r is False:
                self.services.pop(service_name)
                error = None
            else:
                error = "already running"

        if error is None:
            try:
                process, pid_path = launch_service(self.root_path, service_command)
                self.services[service_name] = process
                success = True
            except (subprocess.SubprocessError, IOError):
                log.exception(f"problem starting {service_name}")
                error = "start failed"

        response = {"success": success, "service": service_name, "error": error}
        return response
Exemple #2
0
    async def start_service(self, request):
        service_command = request["service"]
        error = None
        success = False
        testing = False
        if "testing" in request:
            testing = request["testing"]

        if not validate_service(service_command):
            error = "unknown service"

        if service_command in self.services:
            service = self.services[service_command]
            r = service is not None and service.poll() is None
            if r is False:
                self.services.pop(service_command)
                error = None
            else:
                error = "already running"

        if error is None:
            try:
                exe_command = service_command
                if testing is True:
                    exe_command = f"{service_command} --testing=true"
                process, pid_path = launch_service(self.root_path, exe_command)
                self.services[service_command] = process
                success = True
            except (subprocess.SubprocessError, IOError):
                log.exception(f"problem starting {service_command}")
                error = "start failed"

        response = {"success": success, "service": service_command, "error": error}
        return response
Exemple #3
0
    async def start_service(self, request: Dict[str, Any]):
        service_command = request["service"]
        if self.genesis_initialized is False:
            response = {
                "success": False,
                "service": service_command,
                "error":
                "Network not launched yet, waiting for genesis challenge",
            }
            return response

        error = None
        success = False
        testing = False
        if "testing" in request:
            testing = request["testing"]

        if not validate_service(service_command):
            error = "unknown service"

        if service_command in self.services:
            service = self.services[service_command]
            r = service is not None and service.poll() is None
            if r is False:
                self.services.pop(service_command)
                error = None
            else:
                error = f"Service {service_command} already running"

        if error is None:
            try:
                exe_command = service_command
                if testing is True:
                    exe_command = f"{service_command} --testing=true"
                process, pid_path = launch_service(self.root_path, exe_command)
                self.services[service_command] = process
                success = True
            except (subprocess.SubprocessError, IOError):
                log.exception(f"problem starting {service_command}")
                error = "start failed"

        response = {
            "success": success,
            "service": service_command,
            "error": error
        }
        return response
Exemple #4
0
    async def start_service(request):
        service_name = request.query.get("service")
        if not validate_service(service_name):
            r = f"{service_name} unknown service"
            return web.Response(text=str(r))

        if is_running(services, service_name):
            r = f"{service_name} already running"
            return web.Response(text=str(r))

        try:
            process, pid_path = launch_service(root_path, service_name)
            services[service_name] = process
            r = f"{service_name} started"
        except (subprocess.SubprocessError, IOError):
            log.exception(f"problem starting {service_name}")
            r = f"{service_name} start failed"

        return web.Response(text=str(r))