From 59bb47de185352070c191274fd7a34341db6d886 Mon Sep 17 00:00:00 2001 From: Bram Date: Sat, 26 May 2018 10:43:37 +0200 Subject: [PATCH 1/5] backup filename limit set to 50 --- data/actionsmap/yunohost.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index 6fac16511..4cf0f8955 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -788,7 +788,7 @@ backup: help: Name of the backup archive extra: pattern: &pattern_backup_archive_name - - !!str ^[\w\-\._]{1,30}(? Date: Tue, 29 May 2018 08:31:44 +0200 Subject: [PATCH 2/5] [fix] handle grabbing services status from alternate names, fix yunohost/issues#1134 --- src/yunohost/service.py | 66 +++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/src/yunohost/service.py b/src/yunohost/service.py index b252f0873..65a6f6f2d 100644 --- a/src/yunohost/service.py +++ b/src/yunohost/service.py @@ -227,26 +227,47 @@ def service_status(names=[]): status = _get_service_information_from_systemd(name) - translation_key = "service_description_%s" % name - description = m18n.n(translation_key) + # try to get status using alternative version if they exists + # this is for mariadb/mysql but is generic in case of + alternates = services[name].get("alternates", []) + while status is None and alternates: + status = _get_service_information_from_systemd(alternates.pop()) - # that mean that we don't have a translation for this string - # that's the only way to test for that for now - # if we don't have it, uses the one provided by systemd - if description == translation_key: - description = str(status.get("Description", "")) + if status is None: + logger.error("Failed to get status information via dbus for service %s, systemctl didn't recognize this service ('NoSuchUnit')." % name) + result[name] = { + 'status': "unknown", + 'loaded': "unknown", + 'active': "unknown", + 'active_at': { + "timestamp": "unknown", + "human": "unknown", + }, + 'description': "Error: failed to get information for this service, it doesn't exists for systemd", + 'service_file_path': "unknown", + } - result[name] = { - 'status': str(status.get("SubState", "unknown")), - 'loaded': "enabled" if str(status.get("LoadState", "unknown")) == "loaded" else str(status.get("LoadState", "unknown")), - 'active': str(status.get("ActiveState", "unknown")), - 'active_at': { - "timestamp": str(status.get("ActiveEnterTimestamp", "unknown")), - "human": datetime.fromtimestamp(status.get("ActiveEnterTimestamp") / 1000000).strftime("%F %X"), - }, - 'description': description, - 'service_file_path': str(status.get("FragmentPath", "unknown")), - } + else: + translation_key = "service_description_%s" % name + description = m18n.n(translation_key) + + # that mean that we don't have a translation for this string + # that's the only way to test for that for now + # if we don't have it, uses the one provided by systemd + if description == translation_key: + description = str(status.get("Description", "")) + + result[name] = { + 'status': str(status.get("SubState", "unknown")), + 'loaded': "enabled" if str(status.get("LoadState", "unknown")) == "loaded" else str(status.get("LoadState", "unknown")), + 'active': str(status.get("ActiveState", "unknown")), + 'active_at': { + "timestamp": str(status.get("ActiveEnterTimestamp", "unknown")), + "human": datetime.fromtimestamp(status.get("ActiveEnterTimestamp") / 1000000).strftime("%F %X"), + }, + 'description': description, + 'service_file_path': str(status.get("FragmentPath", "unknown")), + } if len(names) == 1: return result[names[0]] @@ -256,13 +277,20 @@ def service_status(names=[]): def _get_service_information_from_systemd(service): "this is the equivalent of 'systemctl status $service'" import dbus + from dbus.exceptions import DBusException d = dbus.SystemBus() systemd = d.get_object('org.freedesktop.systemd1','/org/freedesktop/systemd1') manager = dbus.Interface(systemd, 'org.freedesktop.systemd1.Manager') - service_path = manager.GetUnit(service + ".service") + try: + service_path = manager.GetUnit(service + ".service") + except DBusException as exception: + if exception.get_dbus_name() == 'org.freedesktop.systemd1.NoSuchUnit': + return None + raise + service_proxy = d.get_object('org.freedesktop.systemd1', service_path) # unit_proxy = dbus.Interface(service_proxy, 'org.freedesktop.systemd1.Unit',) From 6ec5a916f3edb20427f758eabe3fd1ac4784f5fd Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 29 May 2018 08:32:36 +0200 Subject: [PATCH 3/5] [fix] would have failed on status.get returning None --- src/yunohost/service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yunohost/service.py b/src/yunohost/service.py index 65a6f6f2d..ae37bd8c7 100644 --- a/src/yunohost/service.py +++ b/src/yunohost/service.py @@ -263,7 +263,7 @@ def service_status(names=[]): 'active': str(status.get("ActiveState", "unknown")), 'active_at': { "timestamp": str(status.get("ActiveEnterTimestamp", "unknown")), - "human": datetime.fromtimestamp(status.get("ActiveEnterTimestamp") / 1000000).strftime("%F %X"), + "human": datetime.fromtimestamp(status["ActiveEnterTimestamp"] / 1000000).strftime("%F %X") if "ActiveEnterTimestamp" in status else "unknown", }, 'description': description, 'service_file_path': str(status.get("FragmentPath", "unknown")), From 75b6fd87864509295c2e1afa002901e7b625e1b4 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 29 May 2018 08:54:17 +0200 Subject: [PATCH 4/5] [mod] add mariadb as an alternates for mysql service --- data/templates/yunohost/services.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/data/templates/yunohost/services.yml b/data/templates/yunohost/services.yml index ba568760e..47452c476 100644 --- a/data/templates/yunohost/services.yml +++ b/data/templates/yunohost/services.yml @@ -18,6 +18,7 @@ redis-server: log: /var/log/redis/redis-server.log mysql: log: [/var/log/mysql.log,/var/log/mysql.err] + alternates: ['mariadb'] glances: {} ssh: log: /var/log/auth.log From d3f7809fb43fa36e672cccaf14f2a33da6e82dd6 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 29 May 2018 08:55:58 +0200 Subject: [PATCH 5/5] [fix] redo yolo logic in case file doesn't exist --- src/yunohost/service.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/yunohost/service.py b/src/yunohost/service.py index b252f0873..100150c21 100644 --- a/src/yunohost/service.py +++ b/src/yunohost/service.py @@ -698,11 +698,18 @@ def _get_files_diff(orig_file, new_file, as_string=False, skip_header=True): header can also be removed if skip_header is True. """ - with open(orig_file, 'r') as orig_file: - orig_file = orig_file.readlines() - with open(new_file, 'r') as new_file: - new_file.readlines() + if os.path.exists(orig_file): + with open(orig_file, 'r') as orig_file: + orig_file = orig_file.readlines() + else: + orig_file = [] + + if not os.path.exists(new_file): + with open(new_file, 'r') as new_file: + new_file.readlines() + else: + new_file = [] # Compare files and format output diff = unified_diff(orig_file, new_file)