def _tools_migrations_run_before_app_restore(backup_version, app_id): all_migrations = _get_migrations_list() current_version = version.parse( ynh_packages_version()["yunohost"]["version"]) backup_version = version.parse(backup_version) if backup_version == current_version: return for migration in all_migrations: if (hasattr(migration, "introduced_in_version") and version.parse(migration.introduced_in_version) > backup_version and hasattr(migration, "run_before_app_restore")): try: logger.info( m18n.n("migrations_running_forward", id=migration.id)) migration.run_before_app_restore(app_id) except Exception as e: msg = m18n.n("migrations_migration_has_failed", exception=e, id=migration.id) logger.error(msg, exc_info=1) raise
def tools_versions(): return ynh_packages_version()
def run(self): # Detect virt technology (if not bare metal) and arch # Gotta have this "|| true" because it systemd-detect-virt return 'none' # with an error code on bare metal ~.~ virt = check_output("systemd-detect-virt || true", shell=True) if virt.lower() == "none": virt = "bare-metal" # Detect arch arch = check_output("dpkg --print-architecture") hardware = dict( meta={"test": "hardware"}, status="INFO", data={ "virt": virt, "arch": arch }, summary="diagnosis_basesystem_hardware", ) # Also possibly the board / hardware name if os.path.exists("/proc/device-tree/model"): model = read_file("/proc/device-tree/model").strip().replace( "\x00", "") hardware["data"]["model"] = model hardware["details"] = ["diagnosis_basesystem_hardware_model"] elif os.path.exists("/sys/devices/virtual/dmi/id/sys_vendor"): model = read_file("/sys/devices/virtual/dmi/id/sys_vendor").strip() if os.path.exists("/sys/devices/virtual/dmi/id/product_name"): model = "%s %s" % ( model, read_file( "/sys/devices/virtual/dmi/id/product_name").strip(), ) hardware["data"]["model"] = model hardware["details"] = ["diagnosis_basesystem_hardware_model"] yield hardware # Kernel version kernel_version = read_file("/proc/sys/kernel/osrelease").strip() yield dict( meta={"test": "kernel"}, data={"kernel_version": kernel_version}, status="INFO", summary="diagnosis_basesystem_kernel", ) # Debian release debian_version = read_file("/etc/debian_version").strip() yield dict( meta={"test": "host"}, data={"debian_version": debian_version}, status="INFO", summary="diagnosis_basesystem_host", ) # Yunohost packages versions # We check if versions are consistent (e.g. all 3.6 and not 3 packages with 3.6 and the other with 3.5) # This is a classical issue for upgrades that failed in the middle # (or people upgrading half of the package because they did 'apt upgrade' instead of 'dist-upgrade') # Here, ynh_core_version is for example "3.5.4.12", so [:3] is "3.5" and we check it's the same for all packages ynh_packages = ynh_packages_version() ynh_core_version = ynh_packages["yunohost"]["version"] consistent_versions = all(infos["version"][:3] == ynh_core_version[:3] for infos in ynh_packages.values()) ynh_version_details = [( "diagnosis_basesystem_ynh_single_version", { "package": package, "version": infos["version"], "repo": infos["repo"], }, ) for package, infos in ynh_packages.items()] yield dict( meta={"test": "ynh_versions"}, data={ "main_version": ynh_core_version, "repo": ynh_packages["yunohost"]["repo"], }, status="INFO" if consistent_versions else "ERROR", summary="diagnosis_basesystem_ynh_main_version" if consistent_versions else "diagnosis_basesystem_ynh_inconsistent_versions", details=ynh_version_details, ) if self.is_vulnerable_to_meltdown(): yield dict( meta={"test": "meltdown"}, status="ERROR", summary="diagnosis_security_vulnerable_to_meltdown", details=["diagnosis_security_vulnerable_to_meltdown_details"], ) bad_sury_packages = list(self.bad_sury_packages()) if bad_sury_packages: cmd_to_fix = "apt install --allow-downgrades " + " ".join([ "%s=%s" % (package, version) for package, version in bad_sury_packages ]) yield dict( meta={"test": "packages_from_sury"}, data={"cmd_to_fix": cmd_to_fix}, status="WARNING", summary="diagnosis_package_installed_from_sury", details=["diagnosis_package_installed_from_sury_details"], ) if self.backports_in_sources_list(): yield dict( meta={"test": "backports_in_sources_list"}, status="WARNING", summary="diagnosis_backports_in_sources_list", )
def tools_diagnosis(auth, private=False): """ Return global info about current yunohost instance to help debugging """ diagnosis = OrderedDict() # Debian release try: with open('/etc/debian_version', 'r') as f: debian_version = f.read().rstrip() except IOError as e: logger.warning(m18n.n('diagnosis_debian_version_error', error=format(e)), exc_info=1) else: diagnosis['host'] = "Debian %s" % debian_version # Kernel version try: with open('/proc/sys/kernel/osrelease', 'r') as f: kernel_version = f.read().rstrip() except IOError as e: logger.warning(m18n.n('diagnosis_kernel_version_error', error=format(e)), exc_info=1) else: diagnosis['kernel'] = kernel_version # Packages version diagnosis['packages'] = ynh_packages_version() # Server basic monitoring diagnosis['system'] = OrderedDict() try: disks = monitor_disk(units=['filesystem'], human_readable=True) except MoulinetteError as e: logger.warning(m18n.n('diagnosis_monitor_disk_error', error=format(e)), exc_info=1) else: diagnosis['system']['disks'] = {} for disk in disks: diagnosis['system']['disks'][ disk] = 'Mounted on %s, %s (%s free)' % ( disks[disk]['mnt_point'], disks[disk]['size'], disks[disk]['avail']) try: system = monitor_system(units=['cpu', 'memory'], human_readable=True) except MoulinetteError as e: logger.warning(m18n.n('diagnosis_monitor_system_error', error=format(e)), exc_info=1) else: diagnosis['system']['memory'] = { 'ram': '%s (%s free)' % (system['memory']['ram']['total'], system['memory']['ram']['free']), 'swap': '%s (%s free)' % (system['memory']['swap']['total'], system['memory']['swap']['free']), } # Services status services = service_status() diagnosis['services'] = {} for service in services: diagnosis['services'][service] = "%s (%s)" % ( services[service]['status'], services[service]['loaded']) # YNH Applications try: applications = app_list()['apps'] except MoulinetteError as e: diagnosis['applications'] = m18n.n('diagnosis_no_apps') else: diagnosis['applications'] = {} for application in applications: if application['installed']: diagnosis['applications'][application['id']] = application[ 'label'] if application['label'] else application['name'] # Private data if private: diagnosis['private'] = OrderedDict() # Public IP diagnosis['private']['public_ip'] = {} try: diagnosis['private']['public_ip']['IPv4'] = get_public_ip(4) except MoulinetteError as e: pass try: diagnosis['private']['public_ip']['IPv6'] = get_public_ip(6) except MoulinetteError as e: pass # Domains diagnosis['private']['domains'] = domain_list(auth)['domains'] return diagnosis
def tools_diagnosis(auth, private=False): """ Return global info about current yunohost instance to help debugging """ diagnosis = OrderedDict(); # Debian release try: with open('/etc/debian_version', 'r') as f: debian_version = f.read().rstrip() except IOError as e: logger.warning(m18n.n('diagnosis_debian_version_error', error=format(e)), exc_info=1) else: diagnosis['host'] = "Debian %s" % debian_version # Kernel version try: with open('/proc/sys/kernel/osrelease', 'r') as f: kernel_version = f.read().rstrip() except IOError as e: logger.warning(m18n.n('diagnosis_kernel_version_error', error=format(e)), exc_info=1) else: diagnosis['kernel'] = kernel_version # Packages version diagnosis['packages'] = ynh_packages_version() # Server basic monitoring diagnosis['system'] = OrderedDict() try: disks = monitor_disk(units=['filesystem'], human_readable=True) except MoulinetteError as e: logger.warning(m18n.n('diagnosis_monitor_disk_error', error=format(e)), exc_info=1) else: diagnosis['system']['disks'] = {} for disk in disks: diagnosis['system']['disks'][disk] = 'Mounted on %s, %s (%s free)' % ( disks[disk]['mnt_point'], disks[disk]['size'], disks[disk]['avail'] ) try: system = monitor_system(units=['cpu', 'memory'], human_readable=True) except MoulinetteError as e: logger.warning(m18n.n('diagnosis_monitor_system_error', error=format(e)), exc_info=1) else: diagnosis['system']['memory'] = { 'ram' : '%s (%s free)' % (system['memory']['ram']['total'], system['memory']['ram']['free']), 'swap' : '%s (%s free)' % (system['memory']['swap']['total'], system['memory']['swap']['free']), } # Services status services = service_status() diagnosis['services'] = {} for service in services: diagnosis['services'][service] = "%s (%s)" % (services[service]['status'], services[service]['loaded']) # YNH Applications try: applications = app_list()['apps'] except MoulinetteError as e: diagnosis['applications'] = m18n.n('diagnosis_no_apps') else: diagnosis['applications'] = {} for application in applications: if application['installed']: diagnosis['applications'][application['id']] = application['label'] if application['label'] else application['name'] # Private data if private: diagnosis['private'] = OrderedDict() # Public IP diagnosis['private']['public_ip'] = {} try: diagnosis['private']['public_ip']['IPv4'] = get_public_ip(4) except MoulinetteError as e: pass try: diagnosis['private']['public_ip']['IPv6'] = get_public_ip(6) except MoulinetteError as e: pass # Domains diagnosis['private']['domains'] = domain_list(auth)['domains'] return diagnosis