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
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
def start_from_binary(self): microservice_target_path = self.context.get_microservice_target_path( self.service_name) force_chdir(microservice_target_path) if not self.context.offline: nexus = SmNexus(self.context, self.service_name) nexus.download_jar_if_necessary(self.run_from, self.version) filename = self._get_jar_filename() service_data = self.service_data binary_data = service_data["binary"] if "configurationFile" in binary_data: configuration_file = binary_data["configurationFile"] else: print "ERROR: required config 'configurationFile' does not exist" return None binary_to_run = os.path.join(microservice_target_path, filename) if os.path.exists(binary_to_run): force_chdir(self.run_from) os.system("jar xvf " + microservice_target_path + filename + " " + configuration_file + " > /dev/null") force_chdir(microservice_target_path) cmd = self.get_start_command("BINARY") process = Popen(cmd, env=os.environ.copy(), stdout=SmDropwizardServiceStarter.DEV_NULL, stderr=SmDropwizardServiceStarter.DEV_NULL, close_fds=True) if process.returncode == 1: print 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 process.pid else: print "ERROR: the requested file: '" + binary_to_run + "' does not exist" return None
def start_from_sources(self): sbt_extra_params = self._build_extra_params() base_dir = self.context.application.workspace + self.service_data[ "location"] cmd = self.sources["cmd"] process = None try: new_env = os.environ.copy() # SBT is so specific should this be in configuration? new_env["SBT_EXTRA_PARAMS"] = " ".join(sbt_extra_params) os.chdir(base_dir) process = Popen(self.get_start_command("SOURCE"), env=new_env, stdout=SmDropwizardServiceStarter.DEV_NULL, stderr=SmDropwizardServiceStarter.DEV_NULL, close_fds=True) except Exception, e: self.log("Could not start service in '%s' due to exception: %s" % (base_dir, str(e)))
def start_from_binary(self): microservice_target_path = self.context.get_microservice_target_path( self.service_name) force_chdir(microservice_target_path) if not self.context.offline: nexus = SmNexus(self.context, self.service_name) if not self.version: self.version = nexus.find_latest_version( self.run_from, self.service_data["binary"]["artifact"]) nexus.download_jar_if_necessary(self.run_from, self.version) unzip_dir = self._unzip_play_application() parent, _ = os.path.split(unzip_dir) force_pushdir(parent) 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