def update_sources() -> None: """ Updates the repository sources, as on some OS, having it out of sync may lead to error on installation :raise subprocess.CalledProcessError if process fails """ logging.info("Updating apt repositories") launch_and_log_as_root(["apt-get", "update"])
def change_coredump_pattern() -> None: """ Changes the coredump pattern system wide """ core_dump_location = get_global_conf().get("trigger", "core_dump_location") core_dump = os.path.join(core_dump_location, get_global_conf().get("trigger", "core_dump_pattern")) last = False with open("/etc/sysctl.conf") as _file: for _line in _file: if core_dump in _line and ("#" not in _line or _line.index("#") > _line.index(core_dump)): last = True elif "kernel.core_pattern" in _line and\ ("#" not in _line or _line.index("#") > _line.index("kernel.core_pattern")): last = False if last: return command = ["echo", '"kernel.core_pattern={}"'.format(core_dump), ">>", "/etc/sysctl.conf"] try: launch_and_log_as_root(command) launch_and_log_as_root(["sysctl", "-p"]) except subprocess.CalledProcessError: logging.warning("Please add 'kernel.core_pattern=%(pattern)s' to /etc/sysctl.conf", dict(pattern=core_dump)) raise
def change_coredump_pattern() -> None: """ Changes the coredump pattern system wide """ core_dump_location = get_global_conf().get("trigger", "core_dump_location") core_dump = os.path.join( core_dump_location, get_global_conf().get("trigger", "core_dump_pattern")) last = False with open("/etc/sysctl.conf") as _file: for _line in _file: if core_dump in _line and ("#" not in _line or _line.index("#") > _line.index(core_dump)): last = True elif "kernel.core_pattern" in _line and\ ("#" not in _line or _line.index("#") > _line.index("kernel.core_pattern")): last = False if last: return command = [ "echo", '"kernel.core_pattern={}"'.format(core_dump), ">>", "/etc/sysctl.conf" ] try: launch_and_log_as_root(command) launch_and_log_as_root(["sysctl", "-p"]) except subprocess.CalledProcessError: logging.warning( "Please add 'kernel.core_pattern=%(pattern)s' to /etc/sysctl.conf", dict(pattern=core_dump)) raise
def install(packages: list) -> None: """ Installs the packages with an apt-enable system :param packages: the packages to install """ logging.info("Will now install missing packages : %(packages)s", dict(packages=" ".join(packages))) cmd = ["apt-get", "install", "-y"] + packages launch_and_log_as_root(cmd)