def _untarPackages(self, packages, service, untarRootPath, nicelevel=None, pgksNeedSuffix=None, pathSuffix=''): """ untar all the packages @params packages - list of dictionary of parsed packages uri @throws AgentException """ self._updateProgress(80) count = 0 for pkgDict in packages.itervalues(): count += 1 # check if package path exists already # if the package is already untarred, move on # else create the package path pkgName = pkgDict['packageName'] untarPath = os.path.join(untarRootPath, pkgName, '%s%s' % (pkgDict['packageVersion'], pathSuffix if ((pgksNeedSuffix is not None) and pkgName in pgksNeedSuffix) else '')) if os.path.exists(untarPath): # perhaps another thread has finished extraction, continue with next package continue os.makedirs(untarPath) try: self.untar(pkgDict['packagePath'], untarPath, nicelevel) except AgentException: rmrf(untarPath) # Note: i. atleast self should have 'rx' so that we can proceed setting 'rx' for group and others # ii. since cronus/cronusapp belong to diff group, lets give access to self, group and others. # if both belong to same group in future, then just self, group should be enough if (not os.name == 'nt'): # ensure all parent dir of scripts dir have 'rx' so that we can really navigate to scripts dir and execute uname = getuserofpath(untarPath) chmod(untarPath, '+rx', sudoUser = uname) cronusPath = os.path.join(untarPath, 'cronus') if os.path.exists(cronusPath): uname = getuserofpath(cronusPath) chmod(cronusPath, '+rx', sudoUser = uname) # now give all scripts 'rx' permission scriptsPath = os.path.join(cronusPath, 'scripts') if os.path.exists(scriptsPath): uname = getuserofpath(scriptsPath) rchmod(scriptsPath, '+rx', sudoUser = uname) #Running as cronus user when higher privilege service (i.e. not chown all the package into the application user) if (not isHigherPrivilegeService(service)): import pwd uname = pylons.config['app_user_account'] uid = pwd.getpwnam(uname).pw_uid gid = pwd.getpwnam(uname).pw_gid rchown(untarPath, uid, gid) self._updateProgress(calcProgress(80, 99, float(count) / len(packages)))
def _getBuiltThread(self, service, manifest, package, exeName): """ here """ # figure out the path to the cronus scripts uname = pylons.config['app_user_account'] execPath = os.path.join(ManifestController.manifestPath(service, manifest), package, 'cronus', 'scripts', exeName) if (isHigherPrivilegeService(service)): cmd = execPath else: cmd = utils.sudoCmd([execPath], uname) dummy = not os.path.exists(execPath) execThread = ExecThread(self._threadMgr, cmd) copycontexts(self, execThread, contextutils.CTX_NAMES) return execThread, dummy
def _getBuiltThread(self, scriptName): """ build lcm script exec thread """ # figure out the path to the cronus scripts uname = pylons.config['app_user_account'] execPath = os.path.join(manifestutil.modulePath(self.__service, self.__module), self.__package, 'cronus', 'scripts', scriptName) if (isHigherPrivilegeService(self.__service)): cmd = execPath else: cmd = utils.sudoCmd([execPath], uname) dummy = not os.path.exists(execPath) execThread = ExecThread(self._threadMgr, cmd) copycontexts(self, execThread, ['service', 'guid']) return execThread, dummy
def _getBuiltThread(self, service, manifest, package, exeName): """ here """ # figure out the path to the cronus scripts uname = pylons.config['app_user_account'] execPath = os.path.join( ManifestController.manifestPath(service, manifest), package, 'cronus', 'scripts', exeName) if (isHigherPrivilegeService(service)): cmd = execPath else: cmd = utils.sudoCmd([execPath], uname) dummy = not os.path.exists(execPath) execThread = ExecThread(self._threadMgr, cmd) copycontexts(self, execThread, contextutils.CTX_NAMES) return execThread, dummy
def _getBuiltThread(self, scriptName): """ build lcm script exec thread """ # figure out the path to the cronus scripts uname = pylons.config['app_user_account'] execPath = os.path.join( manifestutil.modulePath(self.__service, self.__module), self.__package, 'cronus', 'scripts', scriptName) if (isHigherPrivilegeService(self.__service)): cmd = execPath else: cmd = utils.sudoCmd([execPath], uname) dummy = not os.path.exists(execPath) execThread = ExecThread(self._threadMgr, cmd) copycontexts(self, execThread, ['service', 'guid']) return execThread, dummy
def _getBuiltThread(self, service, manifest, package, exeName): """ here """ # figure out the path to the cronus scripts uname = configutil.getAppUser() execPath = os.path.join(manifestutil.manifestPath(service, manifest), package, 'cronus', 'scripts', exeName) if (isHigherPrivilegeService(service)) or not uname: cmd = execPath else: cmd = utils.sudoCmd([execPath], uname) dummy = not os.path.exists(execPath) if not dummy: execThread = ExecThread(self._threadMgr, cmd, parentId = self.getUuid()) contextutils.copyJobContexts(self, execThread) # issue 17, not inject ctx for startup and shutdown script if exeName == 'startup' or exeName == 'shutdown': execThread.setInjectctx(False) return execThread else: return None
def _untarPackages(self, packages, service, untarRootPath, nicelevel=None, pgksNeedSuffix=None, pathSuffix=''): """ untar all the packages @params packages - list of dictionary of parsed packages uri @throws AgentException """ self._updateProgress(80) count = 0 for pkgDict in packages.itervalues(): count += 1 # check if package path exists already # if the package is already untarred, move on # else create the package path pkgName = pkgDict['packageName'] untarPath = os.path.join(untarRootPath, pkgName, '%s%s' % (pkgDict['packageVersion'], pathSuffix if ((pgksNeedSuffix is not None) and pkgName in pgksNeedSuffix) else '')) if os.path.exists(untarPath): # perhaps another thread has finished extraction, continue with next package continue os.makedirs(untarPath) try: self.untar(pkgDict['packagePath'], untarPath, nicelevel) except AgentException: rmrf(untarPath) # Note: i. atleast self should have 'rx' so that we can proceed setting 'rx' for group and others # if both belong to same group in future, then just self, group should be enough # ensure all parent dir of scripts dir have 'rx' so that we can really navigate to scripts dir and execute uname = getuserofpath(untarPath) chmod(untarPath, '+rx', sudoUser = uname) cronusPath = os.path.join(untarPath, 'cronus') if os.path.exists(cronusPath): uname = getuserofpath(cronusPath) chmod(cronusPath, '+rx', sudoUser = uname) # now give all scripts 'rx' permission scriptsPath = os.path.join(cronusPath, 'scripts') if os.path.exists(scriptsPath): uname = getuserofpath(scriptsPath) rchmod(scriptsPath, '+rx', sudoUser = uname) # issue #16, now add symlink to .appdata for easy access appdata_path = manifestutil.appDataPath(service) link_path = os.path.join(untarPath, '.appdata') LOG.info('Create .appdata symlink from %s to %s' % (link_path, appdata_path)) utils.symlink(appdata_path, link_path) #Running as cronus user when higher privilege service (i.e. not chown all the package into the application user) if (not isHigherPrivilegeService(service)): uname = configutil.getAppUser() uid, gid = utils.getUidGid(uname) rchown(untarPath, uid, gid) self._updateProgress(calcProgress(80, 99, float(count) / len(packages)))