From 9b32d5e86ef7ad4b4e802ec8fb16b21fb47d45b8 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Sun, 28 Dec 2014 14:49:03 +0100 Subject: Fix service name parsing for systemd >= 215 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Newer systemd put a colored bullet point '●' in front of the service name output: # sudo systemctl status 971 ● libvirtd.service - Virtualization daemon ... Skip that. --- whatmaps/command.py | 7 ++++++- whatmaps/systemd.py | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'whatmaps') diff --git a/whatmaps/command.py b/whatmaps/command.py index 0a4eb7b..d0f5c3e 100755 --- a/whatmaps/command.py +++ b/whatmaps/command.py @@ -113,7 +113,12 @@ def find_systemd_units(procmap, distro): for dummy, procs in procmap.items(): for proc in procs: - unit = Systemd.process_to_unit(proc) + try: + unit = Systemd.process_to_unit(proc) + except ValueError as e: + logging.warning("No systemd unit found for '%s': %s" + "- restart manually" % (proc.exe, e)) + continue if not unit: logging.warning("No systemd unit found for '%s'" "- restart manually" % proc.exe) diff --git a/whatmaps/systemd.py b/whatmaps/systemd.py index add6d0e..3407128 100644 --- a/whatmaps/systemd.py +++ b/whatmaps/systemd.py @@ -38,4 +38,10 @@ class Systemd(object): if systemctl_status.returncode: return None else: - return output.split()[0] + parts = output.split() + if parts[0].endswith('.service'): + return parts[0] + elif parts[1].endswith('.service'): + return parts[1] + else: + raise ValueError("Can't parse service name from\n%s" % output) -- cgit v1.2.3