def _process_configure() -> None: if os.getuid() == 0: os.setgid(shutil._get_gid('postgres')) # type: ignore os.setuid(shutil._get_uid('postgres')) # type: ignore # Setting "pdeathsig" will make the process be killed if our process dies for any reason. prctl.set_pdeathsig(signal.SIGTERM)
def fs_chown(root_path:str, user:Any, group:Any) -> None: "change tree ownership recursively" if isinstance(user, str): uid = shutil._get_uid(user) assert uid is not None, f"no user: {user}" else: uid = user if isinstance(group, str): gid = shutil._get_gid(group) assert gid is not None, f"no group: {group}" else: gid = group def chown(path:str) -> None: os.chown(path, uid, gid) fs_visit(root_path, chown, chown)
TIMEOUT_TO_GROW_UP = 5 # seconds # DIRS MAIN_DIR = '/opt/zion/' RUNTIME_DIR = MAIN_DIR + 'runtime/java/' WORKERS_DIR = MAIN_DIR + 'workers/' FUNCTIONS_DIR = MAIN_DIR + 'functions/' POOL_DIR = MAIN_DIR + 'docker_pool/' DOCKER_IMAGE = 'adoptopenjdk/openjdk11:x86_64-ubuntu-jdk11u-nightly' # Headers TIMEOUT_HEADER = "X-Object-Meta-Function-Timeout" MEMORY_HEADER = "X-Object-Meta-Function-Memory" MAIN_HEADER = "X-Object-Meta-Function-Main" swift_uid = shutil._get_uid('swift') swift_gid = shutil._get_gid('swift') def init_logger(): # create logger with 'be_service' logger = logging.getLogger('zion_service') logger.setLevel(logging.DEBUG) # create file handler which logs even debug messages fh = logging.FileHandler('/opt/zion/service/zion_service.log') fh.setLevel(logging.DEBUG) # create console handler with a higher log level ch = logging.StreamHandler(sys.stdout) ch.setLevel(logging.DEBUG) # create formatter and add it to the handlers formatter = logging.Formatter(
def __create_link_descriptor(self, target: Path, directory: RelPath = "", **kwargs: Options) -> None: """Creates a link entry for current options and a given target. Also lets you set the dir like cd or options temporarily only for a link""" read_opt = self.__make_read_opt(kwargs) # Now generate the correct name for the symlink replace = read_opt("replace") if replace: # When using regex pattern, name property is ignored if read_opt("name") != "": log_warning("'name'-property is useless if 'replace' is used") replace_pattern = read_opt("replace_pattern") if replace_pattern: base = os.path.basename(target) if "%" in base: base = base.split("%", 1)[1] name = re.sub(replace_pattern, replace, base) else: msg = "You are trying to use 'replace', but no " msg += "'replace_pattern' was set." self.__raise_generation_error(msg) else: name = expandvars(read_opt("name")) # And prevent exceptions in os.symlink() if name and name[-1:] == "/": self.__raise_generation_error("name mustn't represent a directory") # Put together the path of the dir we create the link in if not directory: directory = self.directory # Use the current dir else: directory = expandvars(directory) if directory[0] != '/': # Path is realtive, join with current directory = os.path.join(self.directory, directory) directory = expandvars(directory) # Concat directory and name. The users $HOME needs to be set for this # when executing as root, otherwise ~ will be expanded to the home # directory of the root user (/root) name = expanduser(os.path.join(directory, name)) # Add prefix an suffix to name base, ext = os.path.splitext(os.path.basename(name)) if not base: # If base is empty it means that "name" was never set by the user, # so we fallback to use the target name (but without the tag) base, ext = os.path.splitext( os.path.basename(target.split("%", 1)[-1])) name = os.path.join( os.path.dirname(name), read_opt("prefix") + base + read_opt("suffix") + ext) name = os.path.normpath(name) # Get user and group id of owner owner = read_opt("owner") if owner: # Check for the correct format of owner try: user, group = owner.split(":") except ValueError: msg = "The owner needs to be specified in the format" self.__raise_generation_error(msg + 'user:group') try: uid = shutil._get_uid(user) except LookupError: msg = "You want to set the owner of '" + name + "' to '" + user msg += "', but there is no such user on this system." self.__raise_generation_error(msg) try: gid = shutil._get_gid(group) except LookupError: msg = "You want to set the owner of '" + name + "' to '" msg += group + "', but there is no such group on this system." self.__raise_generation_error(msg) else: # if no owner was specified, we need to set it # to the owner of the dir uid, gid = get_dir_owner(name) # Finally create the result entry linkdescriptor = {} linkdescriptor["target"] = target linkdescriptor["name"] = name linkdescriptor["uid"] = uid linkdescriptor["gid"] = gid linkdescriptor["permission"] = read_opt("permission") self.result["links"].append(linkdescriptor)
def __create_link_descriptor(self, target, directory="", **kwargs): """Creates an entry in ``self.result["links"]`` with current options and a given target. Furthermore lets you set the directory like :func:`cd()`. Args: target (str): Full path to target file directory (str): A path to change the cwd kwargs (dict): A set of options that will be overwritten just for this call Raises: :class:`~errors.GenerationError`: One or more options were misused """ read_opt = self._make_read_opt(kwargs) # First generate the correct name for the symlink replace = read_opt("replace") name = read_opt("name") if replace: # When using regex pattern, name property is ignored replace_pattern = read_opt("replace_pattern") if not replace_pattern: msg = "You are trying to use 'replace', but no " msg += "'replace_pattern' was set." self._gen_err(msg) if name: # Usually it makes no sense to set a name when "replace" is # used, but commands might set this if they got an # dynamicfile, because otherwise you would have to match # against the hash too base = name else: base = os.path.basename(target) if constants.TAG_SEPARATOR in base: base = base.split(constants.TAG_SEPARATOR, 1)[1] name = re.sub(replace_pattern, replace, base) elif name: name = expandpath(name) # And prevent exceptions in os.symlink() if name[-1:] == "/": self._gen_err("name mustn't represent a directory") else: # "name" wasn't set by the user, # so fallback to use the target name (but without the tag) name = os.path.basename( target.split(constants.TAG_SEPARATOR, 1)[-1]) # Add prefix an suffix to name base, ext = os.path.splitext(os.path.basename(name)) if read_opt("extension"): ext = "." + read_opt("extension") name = os.path.join( os.path.dirname(name), read_opt("prefix") + base + read_opt("suffix") + ext) # Put together the path of the dir we create the link in if not directory: directory = self.directory # Use the current dir else: directory = os.path.join(self.directory, expandpath(directory)) # Concat directory and name. The users $HOME needs to be set for this # when executing as root, otherwise ~ will be expanded to the home # directory of the root user (/root) name = normpath(os.path.join(directory, name)) # Get user and group id of owner owner = read_opt("owner") if owner: # Check for the correct format of owner try: user, group = owner.split(":") except ValueError: msg = "The owner needs to be specified in the format " self._gen_err(msg + "user:group") try: uid = shutil._get_uid(user) except LookupError: msg = "You want to set the owner of '" + name + "' to '" + user msg += "', but there is no such user on this system." self._gen_err(msg) try: gid = shutil._get_gid(group) except LookupError: msg = "You want to set the owner of '" + name + "' to '" msg += group + "', but there is no such group on this system." self._gen_err(msg) else: # if no owner was specified, we need to set it # to the owner of the dir uid, gid = get_dir_owner(name) # Finally create the result entry linkdescriptor = {} linkdescriptor["target"] = target linkdescriptor["name"] = name linkdescriptor["uid"] = uid linkdescriptor["gid"] = gid linkdescriptor["permission"] = read_opt("permission") linkdescriptor["secure"] = read_opt("secure") self.result["links"].append(linkdescriptor)
def update_event(self, inp=-1): self.set_output_val(0, shutil._get_uid(self.input(0)))