From 54a89d869fc8591b15f91f40ad15fe59b103e609 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 22 Jan 2023 16:20:02 +0100 Subject: syncoid autosuspend: cosmetic fixes --- .../zfs/syncoid/templates/autosuspend.py.j2 | 32 ++++++++++++++++++---- .../zfs/syncoid/templates/autosuspend.service.j2 | 2 +- .../zfs/syncoid/templates/autosuspend.timer.j2 | 2 +- 3 files changed, 29 insertions(+), 7 deletions(-) (limited to 'roles/storage') diff --git a/roles/storage/zfs/syncoid/templates/autosuspend.py.j2 b/roles/storage/zfs/syncoid/templates/autosuspend.py.j2 index 9dc9bc52..39fe0092 100644 --- a/roles/storage/zfs/syncoid/templates/autosuspend.py.j2 +++ b/roles/storage/zfs/syncoid/templates/autosuspend.py.j2 @@ -109,7 +109,8 @@ class AutoSuspender(object): return result - def suspend(self): + def suspend_system(self): + print("trying to suspend system") manager = self._get_logind_manager_interface() if not manager.CanSuspend(): print("ERR: system can not be suspended") @@ -119,8 +120,31 @@ class AutoSuspender(object): except dbus.exceptions.DBusException as error: print("ERR: %s" % error) + def _reformat_hdparm_output(self, lines): + result = [] + entry = "" + for line in lines: + line = line.decode('utf-8') + if line == '': + if entry != '': + result.append(entry) + entry = "" + continue + if line.strip().startswith("drive state is:"): + line = ' ' + line.split(':', 2)[1].strip() + entry += line + result.append(entry) + return result + def spindown_disks(self, disks): - subprocess.run(["hdparm", "-y"] + disks) + print("current disk power states:") + lines = subprocess.run(["hdparm", "-C"] + disks, check=True, stdout=subprocess.PIPE).stdout.splitlines() + for line in self._reformat_hdparm_output(lines): + print(" %s" % line) + print("issuing standby commands:") + lines = subprocess.run(["hdparm", "-y"] + disks, check=True, stdout=subprocess.PIPE).stdout.splitlines() + for line in self._reformat_hdparm_output(lines): + print(" %s" % line) def print_usage(): @@ -147,10 +171,8 @@ if __name__ == "__main__": print("checking for suspend inhibitors:") if s.check(): if mode == "system": - print("trying to suspend system") - s.suspend() + s.suspend_system() elif mode == "disks": - print("trying to spindown disks") s.spindown_disks(disks) else: print("not suspending because at least one check failed.") diff --git a/roles/storage/zfs/syncoid/templates/autosuspend.service.j2 b/roles/storage/zfs/syncoid/templates/autosuspend.service.j2 index f88823ca..dc376598 100644 --- a/roles/storage/zfs/syncoid/templates/autosuspend.service.j2 +++ b/roles/storage/zfs/syncoid/templates/autosuspend.service.j2 @@ -1,5 +1,5 @@ [Unit] -Description=automatic system suspender for syncoid-based backups +Description=automatic {{ zfs_syncoid_autosuspend }} suspender for syncoid-based backups [Service] Type=oneshot diff --git a/roles/storage/zfs/syncoid/templates/autosuspend.timer.j2 b/roles/storage/zfs/syncoid/templates/autosuspend.timer.j2 index fee94905..f69b96e0 100644 --- a/roles/storage/zfs/syncoid/templates/autosuspend.timer.j2 +++ b/roles/storage/zfs/syncoid/templates/autosuspend.timer.j2 @@ -1,5 +1,5 @@ [Unit] -Description=automatic system suspender for syncoid-based backups +Description=automatic {{ zfs_syncoid_autosuspend }} suspender for syncoid-based backups [Timer] OnCalendar=*-*-* *:04/10:30 -- cgit v1.2.3