diff options
author | Guido Günther <agx@sigxcpu.org> | 2014-12-28 14:49:03 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2014-12-28 14:59:02 +0100 |
commit | 9b32d5e86ef7ad4b4e802ec8fb16b21fb47d45b8 (patch) | |
tree | 31c5335278ccebfaeeb10a41ac632a426d2e07f9 | |
parent | 8c5b2930b37f7cf6fd0a44e4283bf2c79fbc13bd (diff) |
Fix service name parsing for systemd >= 215
Newer systemd put a colored bullet point '●' in front of the service
name output:
# sudo systemctl status 971
● libvirtd.service - Virtualization daemon
...
Skip that.
-rwxr-xr-x | whatmaps/command.py | 7 | ||||
-rw-r--r-- | whatmaps/systemd.py | 8 |
2 files changed, 13 insertions, 2 deletions
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) |