Merge branch 'unstable' into stretch-unstable

This commit is contained in:
Alexandre Aubin 2018-06-01 21:49:26 +00:00
commit a4d75a2e40
3 changed files with 60 additions and 24 deletions

View file

@ -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

View file

@ -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

View file

@ -227,6 +227,27 @@ def service_status(names=[]):
status = _get_service_information_from_systemd(name) status = _get_service_information_from_systemd(name)
# 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())
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",
}
else:
translation_key = "service_description_%s" % name translation_key = "service_description_%s" % name
description = m18n.n(translation_key) description = m18n.n(translation_key)
@ -242,7 +263,7 @@ def service_status(names=[]):
'active': str(status.get("ActiveState", "unknown")), 'active': str(status.get("ActiveState", "unknown")),
'active_at': { 'active_at': {
"timestamp": str(status.get("ActiveEnterTimestamp", "unknown")), "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, 'description': description,
'service_file_path': str(status.get("FragmentPath", "unknown")), 'service_file_path': str(status.get("FragmentPath", "unknown")),
@ -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')
try:
service_path = manager.GetUnit(service + ".service") 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.
""" """
if os.path.exists(orig_file):
with open(orig_file, 'r') as orig_file: with open(orig_file, 'r') as orig_file:
orig_file = orig_file.readlines() orig_file = orig_file.readlines()
else:
orig_file = []
if not os.path.exists(new_file):
with open(new_file, 'r') as new_file: with open(new_file, 'r') as new_file:
new_file.readlines() 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)