コード例 #1
0
    def _start_from_sources(self):

        service_data = self.context.service_data(self.service_name)
        assets_path = self.context.application.workspace + service_data["location"]

        cmd_with_params = self.service_data["sources"]["cmd"]
        force_pushdir(assets_path)
        run_from_file = open("RUNNING_FROM", 'w')
        run_from_file.write(self.run_from)
        run_from_file.close()

        makedirs_if_not_exists("logs")
        seconds_remaining = SmPythonServiceStarter.PROCESS_STARTUP_TIMEOUT_SECONDS

        with open("logs/stdout.txt", "wb") as out, open("logs/stderr.txt", "wb") as err:
            subprocess.Popen(cmd_with_params, shell=False, env=os.environ.copy(), stdout=out, stderr=err, close_fds=True)

        while seconds_remaining > 0 and not len(SmProcess.processes_matching("grunt")) > 0:
            time.sleep(1)
            seconds_remaining -= 1
            if seconds_remaining < 10 or seconds_remaining % 5 == 0:
                self.log("Waiting for Assets service to start: %s second%s before timeout" % (
                    seconds_remaining, "s" if seconds_remaining > 1 else ""))
        if len(SmProcess.processes_matching("grunt")) == 1:
            process = SmProcess.processes_matching("grunt")
            for i, v in enumerate(process):
                    return v.pid
コード例 #2
0
    def start_from_sources(self):
        sbt_extra_params = self.sbt_extra_params()

        service_data = self.context.service_data(self.service_name)
        microservice_path = self.context.application.workspace + service_data[
            "location"]
        force_chdir(microservice_path)

        env_copy = os.environ.copy()
        env_copy["SBT_EXTRA_PARAMS"] = " ".join(
            sbt_extra_params)  # TODO: not needed i think anymore...

        makedirs_if_not_exists("logs")

        with open("logs/stdout.txt",
                  "wb") as out, open("logs/stderr.txt", "wb") as err:
            process = Popen(self.get_start_command("SOURCE"),
                            env=env_copy,
                            stdout=out,
                            stderr=err,
                            stdin=subprocess.PIPE)
            process.stdin.close()
            if process.returncode == 1:
                print b.fail + "ERROR: could not start '" + self.service_name + "' " + b.endc
            return process.pid  # Note: This is the parent pid
コード例 #3
0
    def _start_from_binary(self):
        assets_target_path = self.context.get_microservice_target_path(self.service_name)
        assets_path = self.context.application.workspace + self.service_data["location"]

        force_chdir(assets_path)
        remove_if_exists("RUNNING_FROM")

        force_chdir(assets_target_path)

        if not self.context.offline:
            nexus = SmNexus(self.context, self.service_name)

            if self.version:
                versions = [ self.version ]
            elif self.context.assets_versions:
                versions = self.context.assets_versions
                self.log("Starting assets versions: %s" % (", ".join(versions)))
            else:
                versions = nexus.get_all_versions(self.run_from)

            for version in versions:
                nexus.download_jar_if_necessary(self.run_from, version)
            self._unzip_assets(versions)

        cmd_with_params = self.service_data["binary"]["cmd"]
        makedirs_if_not_exists("logs")
        with open("logs/stdout.txt", "wb") as out, open("logs/stderr.txt", "wb") as err:
            return subprocess.Popen(cmd_with_params[0].split(), shell=False, env=os.environ.copy(), stdout=out, stderr=err, close_fds=True).pid
コード例 #4
0
    def start_from_binary(self):
        microservice_target_path = self.context.get_microservice_target_path(self.service_name)
        force_chdir(microservice_target_path)
        
        binaryConfig = self.service_data["binary"]

        if not self.context.offline:
            artifactRepo = SmArtifactRepoFactory.get_repository(self.context, self.service_name, binaryConfig)
            if not self.version:
                self.version = artifactRepo.find_latest_version(self.run_from, binaryConfig["artifact"], binaryConfig["groupId"])
            artifactRepo.download_jar_if_necessary(self.run_from, self.version)

        unzip_dir = self._unpack_play_application(SmArtifactRepoFactory.get_play_app_extension(binaryConfig))
        parent, _ = os.path.split(unzip_dir)
        force_pushdir(parent)

        if "frontend" in self.service_data and self.service_data["frontend"]:
           assets_versions = self._get_assets_version(unzip_dir)
           self.context.assets_versions_to_start(assets_versions)

        cmd_with_params = self.get_start_command("BINARY")
        if os.path.exists(cmd_with_params[0]):
            os.chmod(cmd_with_params[0], stat.S_IRWXU)
        else:
            print b.fail + "ERROR: unable to chmod on non existent file '" + parent + cmd_with_params[0] + "'" + b.endc

        makedirs_if_not_exists("logs")

        print(cmd_with_params)

        with open("logs/stdout.txt", "wb") as out, open("logs/stderr.txt", "wb") as err:
            popen_output = Popen(cmd_with_params, env=os.environ.copy(), stdout=out, stderr=err, close_fds=True)
            if popen_output.returncode == 1:
                print b.fail + "ERROR: could not start '" + self.service_name + "' " + b.endc
            return popen_output.pid
コード例 #5
0
    def _start_from_sources(self):

        service_data = self.context.service_data(self.service_name)
        assets_path = self.context.application.workspace + service_data["location"]

        cmd_with_params = self.service_data["sources"]["cmd"]
        force_pushdir(assets_path)
        run_from_file = open("RUNNING_FROM", 'w')
        run_from_file.write(self.run_from)
        run_from_file.close()

        makedirs_if_not_exists("logs")
        seconds_remaining = SmPythonServiceStarter.PROCESS_STARTUP_TIMEOUT_SECONDS

        with open("logs/stdout.txt", "wb") as out, open("logs/stderr.txt", "wb") as err:
            subprocess.Popen(cmd_with_params, shell=False, env=os.environ.copy(), stdout=out, stderr=err, close_fds=True)

        while seconds_remaining > 0 and not len(SmProcess.processes_matching("grunt")) > 0:
            time.sleep(1)
            seconds_remaining -= 1
            if seconds_remaining < 10 or seconds_remaining % 5 == 0:
                self.log("Waiting for Assets service to start: %s second%s before timeout" % (
                    seconds_remaining, "s" if seconds_remaining > 1 else ""))
        if len(SmProcess.processes_matching("grunt")) == 1:
            process = SmProcess.processes_matching("grunt")
            for i, v in enumerate(process):
                    return v.pid
コード例 #6
0
    def _start_from_binary(self):
        assets_target_path = self.context.get_microservice_target_path(
            self.service_name)
        assets_path = self.context.application.workspace + self.service_data[
            "location"]

        force_chdir(assets_path)
        remove_if_exists("RUNNING_FROM")

        force_chdir(assets_target_path)

        if not self.context.offline:
            nexus = SmNexus(self.context, self.service_name)
            versions = nexus.get_all_versions(self.version, self.run_from)
            for version in versions:
                nexus.download_jar_if_necessary(self.run_from, version)
            self._unzip_assets(versions)

        cmd_with_params = self.service_data["binary"]["cmd"]
        makedirs_if_not_exists("logs")
        with open("logs/stdout.txt",
                  "wb") as out, open("logs/stderr.txt", "wb") as err:
            return subprocess.Popen(cmd_with_params[0].split(),
                                    shell=False,
                                    env=os.environ.copy(),
                                    stdout=out,
                                    stderr=err,
                                    close_fds=True).pid
コード例 #7
0
    def start_from_binary(self):
        microservice_target_path = self.context.get_microservice_target_path(
            self.service_name)
        force_chdir(microservice_target_path)

        binaryConfig = self.service_data["binary"]

        if not self.context.offline:
            artifactRepo = SmArtifactRepoFactory.get_repository(
                self.context, self.service_name, binaryConfig)
            if not self.version:
                self.version = artifactRepo.find_latest_version(
                    self.run_from, binaryConfig["artifact"],
                    binaryConfig["groupId"])
            artifactRepo.download_jar_if_necessary(self.run_from, self.version)

        unzip_dir = self._unpack_play_application(
            SmArtifactRepoFactory.get_play_app_extension(binaryConfig))
        parent, _ = os.path.split(unzip_dir)
        force_chdir(parent)

        if "frontend" in self.service_data and self.service_data["frontend"]:
            assets_versions = self._get_assets_version(unzip_dir)
            self.context.assets_versions_to_start(assets_versions)

        cmd_with_params = self.get_start_command("BINARY")
        if os.path.exists(cmd_with_params[0]):
            os.chmod(cmd_with_params[0], stat.S_IRWXU)
        else:
            self.context.log(b.fail +
                             "ERROR: unable to chmod on non existent file '" +
                             parent + cmd_with_params[0] + "'" + b.endc)

        makedirs_if_not_exists("logs")

        self.context.log(
            "Starting %s with parameters %s" %
            (self.service_name, cmd_with_params), True)

        with open("logs/stdout.txt",
                  "wb") as out, open("logs/stderr.txt", "wb") as err:
            popen_output = Popen(cmd_with_params,
                                 env=os.environ.copy(),
                                 stdout=out,
                                 stderr=err,
                                 close_fds=True)
            if popen_output.returncode == 1:
                self.context.log(b.fail + "ERROR: could not start '" +
                                 self.service_name + "' " + b.endc)
            else:
                self.context.log("'%s' version '%s' started successfully" %
                                 (self.service_name, self.version))
            return popen_output.pid
コード例 #8
0
    def _start_from_binary(self):
        assets_target_path = self.context.get_microservice_target_path(
            self.service_name)
        assets_path = self.context.application.workspace + self.service_data[
            "location"]

        force_chdir(assets_path)
        remove_if_exists("RUNNING_FROM")

        force_chdir(assets_target_path)

        if not self.context.offline:
            artifactory = SmArtifactory(self.context, self.service_name)

            if self.version:
                versions = [self.version]
            elif self.context.assets_versions:
                versions = self.context.assets_versions
                self.log(
                    "Starting assets versions: %s" % (", ".join(versions)),
                    True)
            else:
                versions = artifactory.find_all_versions(self.run_from)
                self.log(
                    "Starting assets versions: %s" % (", ".join(versions)),
                    True)

            for version in versions:
                self.context.log("\nStarting assets version: %s" % version)
                artifactory.download_jar_if_necessary(self.run_from, version)
            self._unzip_assets(versions)

        cmd_with_params = self.service_data["binary"]["cmd"]
        if _is_python_3():
            py3cmd = self.service_data["binary"].get("py3_cmd")
            if py3cmd is not None:
                cmd_with_params = py3cmd

        self.log("starting %s..." % cmd_with_params)

        makedirs_if_not_exists("logs")
        with open("logs/stdout.txt",
                  "wb") as out, open("logs/stderr.txt", "wb") as err:
            return subprocess.Popen(
                cmd_with_params[0].split(),
                shell=False,
                env=os.environ.copy(),
                stdout=out,
                stderr=err,
                close_fds=True,
                universal_newlines=True,
            ).pid
コード例 #9
0
    def start_from_sources(self):
        sbt_extra_params = self.sbt_extra_params()

        service_data = self.context.service_data(self.service_name)
        microservice_path = self.context.application.workspace + service_data["location"]
        curr_dir = force_pushdir(microservice_path)

        env_copy = os.environ.copy()
        env_copy["SBT_EXTRA_PARAMS"] = " ".join(sbt_extra_params) # TODO: not needed i think anymore...

        makedirs_if_not_exists("logs")

        with open("logs/stdout.txt", "wb") as out, open("logs/stderr.txt", "wb") as err:
            process = Popen(self.get_start_command("SOURCE"), env=env_copy, stdout=out, stderr=err, stdin=subprocess.PIPE)
            process.stdin.close()
            if process.returncode == 1:
                print b.fail + "ERROR: could not start '" + self.service_name + "' " + b.endc
            return process.pid # Note: This is the parent pid