mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge branch 'unstable' into stretch-unstable
This commit is contained in:
commit
a4d75a2e40
3 changed files with 60 additions and 24 deletions
|
@ -788,7 +788,7 @@ backup:
|
|||
help: Name of the backup archive
|
||||
extra:
|
||||
pattern: &pattern_backup_archive_name
|
||||
- !!str ^[\w\-\._]{1,30}(?<!\.)$
|
||||
- !!str ^[\w\-\._]{1,50}(?<!\.)$
|
||||
- "pattern_backup_archive_name"
|
||||
-d:
|
||||
full: --description
|
||||
|
|
|
@ -16,6 +16,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
|
||||
|
|
|
@ -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["ActiveEnterTimestamp"] / 1000000).strftime("%F %X") if "ActiveEnterTimestamp" in status else "unknown",
|
||||
},
|
||||
'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',)
|
||||
|
@ -698,11 +726,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)
|
||||
|
|
Loading…
Add table
Reference in a new issue