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
|
help: Name of the backup archive
|
||||||
extra:
|
extra:
|
||||||
pattern: &pattern_backup_archive_name
|
pattern: &pattern_backup_archive_name
|
||||||
- !!str ^[\w\-\._]{1,30}(?<!\.)$
|
- !!str ^[\w\-\._]{1,50}(?<!\.)$
|
||||||
- "pattern_backup_archive_name"
|
- "pattern_backup_archive_name"
|
||||||
-d:
|
-d:
|
||||||
full: --description
|
full: --description
|
||||||
|
|
|
@ -16,6 +16,7 @@ redis-server:
|
||||||
log: /var/log/redis/redis-server.log
|
log: /var/log/redis/redis-server.log
|
||||||
mysql:
|
mysql:
|
||||||
log: [/var/log/mysql.log,/var/log/mysql.err]
|
log: [/var/log/mysql.log,/var/log/mysql.err]
|
||||||
|
alternates: ['mariadb']
|
||||||
glances: {}
|
glances: {}
|
||||||
ssh:
|
ssh:
|
||||||
log: /var/log/auth.log
|
log: /var/log/auth.log
|
||||||
|
|
|
@ -227,26 +227,47 @@ def service_status(names=[]):
|
||||||
|
|
||||||
status = _get_service_information_from_systemd(name)
|
status = _get_service_information_from_systemd(name)
|
||||||
|
|
||||||
translation_key = "service_description_%s" % name
|
# try to get status using alternative version if they exists
|
||||||
description = m18n.n(translation_key)
|
# 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
|
if status is None:
|
||||||
# that's the only way to test for that for now
|
logger.error("Failed to get status information via dbus for service %s, systemctl didn't recognize this service ('NoSuchUnit')." % name)
|
||||||
# if we don't have it, uses the one provided by systemd
|
result[name] = {
|
||||||
if description == translation_key:
|
'status': "unknown",
|
||||||
description = str(status.get("Description", ""))
|
'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] = {
|
else:
|
||||||
'status': str(status.get("SubState", "unknown")),
|
translation_key = "service_description_%s" % name
|
||||||
'loaded': "enabled" if str(status.get("LoadState", "unknown")) == "loaded" else str(status.get("LoadState", "unknown")),
|
description = m18n.n(translation_key)
|
||||||
'active': str(status.get("ActiveState", "unknown")),
|
|
||||||
'active_at': {
|
# that mean that we don't have a translation for this string
|
||||||
"timestamp": str(status.get("ActiveEnterTimestamp", "unknown")),
|
# that's the only way to test for that for now
|
||||||
"human": datetime.fromtimestamp(status.get("ActiveEnterTimestamp") / 1000000).strftime("%F %X"),
|
# if we don't have it, uses the one provided by systemd
|
||||||
},
|
if description == translation_key:
|
||||||
'description': description,
|
description = str(status.get("Description", ""))
|
||||||
'service_file_path': str(status.get("FragmentPath", "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["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:
|
if len(names) == 1:
|
||||||
return result[names[0]]
|
return result[names[0]]
|
||||||
|
@ -256,13 +277,20 @@ def service_status(names=[]):
|
||||||
def _get_service_information_from_systemd(service):
|
def _get_service_information_from_systemd(service):
|
||||||
"this is the equivalent of 'systemctl status $service'"
|
"this is the equivalent of 'systemctl status $service'"
|
||||||
import dbus
|
import dbus
|
||||||
|
from dbus.exceptions import DBusException
|
||||||
|
|
||||||
d = dbus.SystemBus()
|
d = dbus.SystemBus()
|
||||||
|
|
||||||
systemd = d.get_object('org.freedesktop.systemd1','/org/freedesktop/systemd1')
|
systemd = d.get_object('org.freedesktop.systemd1','/org/freedesktop/systemd1')
|
||||||
manager = dbus.Interface(systemd, 'org.freedesktop.systemd1.Manager')
|
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)
|
service_proxy = d.get_object('org.freedesktop.systemd1', service_path)
|
||||||
|
|
||||||
# unit_proxy = dbus.Interface(service_proxy, 'org.freedesktop.systemd1.Unit',)
|
# 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.
|
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:
|
if os.path.exists(orig_file):
|
||||||
new_file.readlines()
|
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
|
# Compare files and format output
|
||||||
diff = unified_diff(orig_file, new_file)
|
diff = unified_diff(orig_file, new_file)
|
||||||
|
|
Loading…
Add table
Reference in a new issue