summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2023-01-21 23:03:00 +0100
committerChristian Pointner <equinox@spreadspace.org>2023-01-21 23:03:00 +0100
commitfacdd63fe173b51c6d9de29ccc2167b0d7a45b6f (patch)
tree669c79d308749774da206c85acf8883568f0e8d5
parentadd wikijs instance: wiki.davste.at (diff)
syncoid/autosuspend: implement disk spindown mode
-rw-r--r--inventory/host_vars/ch-epimetheus.yml3
-rw-r--r--roles/storage/zfs/syncoid/defaults/main.yml8
-rw-r--r--roles/storage/zfs/syncoid/tasks/main.yml10
-rw-r--r--roles/storage/zfs/syncoid/templates/autosuspend.py.j234
-rw-r--r--roles/storage/zfs/syncoid/templates/autosuspend.service.j22
-rw-r--r--roles/storage/zfs/syncoid/templates/pull.timer.j22
-rw-r--r--roles/storage/zfs/syncoid/templates/syncoid_finalize.j22
7 files changed, 51 insertions, 10 deletions
diff --git a/inventory/host_vars/ch-epimetheus.yml b/inventory/host_vars/ch-epimetheus.yml
index fa05843e..c6c75fae 100644
--- a/inventory/host_vars/ch-epimetheus.yml
+++ b/inventory/host_vars/ch-epimetheus.yml
@@ -100,7 +100,8 @@ zfs_sanoid_modules:
process_children_only: yes
-# zfs_syncoid_autosuspend: yes
+zfs_syncoid_autosuspend: disks
+zfs_syncoid_autosuspend_disks: "{{ luks_volumes | dict2items | map(attribute='value.device') }}"
zfs_syncoid_target_pool: backup
zfs_syncoid_sources:
'ch-prometheus':
diff --git a/roles/storage/zfs/syncoid/defaults/main.yml b/roles/storage/zfs/syncoid/defaults/main.yml
index 1161423b..b0a9b5c1 100644
--- a/roles/storage/zfs/syncoid/defaults/main.yml
+++ b/roles/storage/zfs/syncoid/defaults/main.yml
@@ -1,5 +1,11 @@
---
-zfs_syncoid_autosuspend: no
+# zfs_syncoid_autosuspend: system
+
+# zfs_syncoid_autosuspend: disks
+# zfs_syncoid_autosuspend_disks:
+# - /dev/sda
+# - /dev/sdb
+
# zfs_syncoid_target_pool: target
diff --git a/roles/storage/zfs/syncoid/tasks/main.yml b/roles/storage/zfs/syncoid/tasks/main.yml
index 6b3e227e..939dc110 100644
--- a/roles/storage/zfs/syncoid/tasks/main.yml
+++ b/roles/storage/zfs/syncoid/tasks/main.yml
@@ -71,14 +71,22 @@
enabled: yes
- name: enable autosuspend
- when: zfs_syncoid_autosuspend
+ when: zfs_syncoid_autosuspend is defined
block:
+ - name: install hdparm package
+ when: zfs_syncoid_autosuspend == 'disks'
+ apt:
+ name: hdparm
+ state: present
+
- name: create systemd override directory for sanoid timer
+ when: zfs_syncoid_autosuspend == 'system'
file:
path: /etc/systemd/system/sanoid.timer.d
state: directory
- name: disable persistence of sanoid timer
+ when: zfs_syncoid_autosuspend == 'system'
copy:
content: |
[Timer]
diff --git a/roles/storage/zfs/syncoid/templates/autosuspend.py.j2 b/roles/storage/zfs/syncoid/templates/autosuspend.py.j2
index a6217ca0..9dc9bc52 100644
--- a/roles/storage/zfs/syncoid/templates/autosuspend.py.j2
+++ b/roles/storage/zfs/syncoid/templates/autosuspend.py.j2
@@ -119,12 +119,38 @@ class AutoSuspender(object):
except dbus.exceptions.DBusException as error:
print("ERR: %s" % error)
+ def spindown_disks(self, disks):
+ subprocess.run(["hdparm", "-y"] + disks)
+
+
+def print_usage():
+ print("usage: %s (system|disks) [ /dev/sda [ /dev/sdb [ ... ]]] " % sys.argv[0])
+
if __name__ == "__main__":
+ if len(sys.argv) < 2:
+ print_usage()
+ sys.exit(1)
+ mode = sys.argv[1]
+ disks = []
+ if mode not in ["system", "disks"]:
+ print_usage()
+ sys.exit(1)
+ if mode == "disks":
+ if len(sys.argv) < 3:
+ print_usage()
+ sys.exit(1)
+ else:
+ disks = sys.argv[2:]
+
s = AutoSuspender()
- print("checking if the system can be suspended:")
+ print("checking for suspend inhibitors:")
if s.check():
- print("trying to suspend system")
- s.suspend()
+ if mode == "system":
+ print("trying to suspend system")
+ s.suspend()
+ elif mode == "disks":
+ print("trying to spindown disks")
+ s.spindown_disks(disks)
else:
- print("not suspending system because at least one check failed.")
+ 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 28cff913..f88823ca 100644
--- a/roles/storage/zfs/syncoid/templates/autosuspend.service.j2
+++ b/roles/storage/zfs/syncoid/templates/autosuspend.service.j2
@@ -3,7 +3,7 @@ Description=automatic system suspender for syncoid-based backups
[Service]
Type=oneshot
-ExecStart=/usr/local/bin/syncoid-autosuspend.py
+ExecStart=/usr/local/bin/syncoid-autosuspend.py {{ zfs_syncoid_autosuspend }}{% if zfs_syncoid_autosuspend == 'disks' %} {{ zfs_syncoid_autosuspend_disks | join(' ') }}{% endif %}{{ '' }}
NoNewPrivileges=yes
PrivateTmp=yes
ProtectSystem=strict
diff --git a/roles/storage/zfs/syncoid/templates/pull.timer.j2 b/roles/storage/zfs/syncoid/templates/pull.timer.j2
index bcbb1a28..c43c5b28 100644
--- a/roles/storage/zfs/syncoid/templates/pull.timer.j2
+++ b/roles/storage/zfs/syncoid/templates/pull.timer.j2
@@ -4,7 +4,7 @@ Description=syncoid-based backup for {{ item.key }}
[Timer]
OnCalendar={{ item.value.periodic.schedule }}
AccuracySec=10s
-WakeSystem={{ zfs_syncoid_autosuspend | ternary('true', 'false') }}
+WakeSystem={{ (zfs_syncoid_autosuspend is defined and zfs_syncoid_autosuspend == 'system') | ternary('true', 'false') }}
[Install]
WantedBy=timers.target
diff --git a/roles/storage/zfs/syncoid/templates/syncoid_finalize.j2 b/roles/storage/zfs/syncoid/templates/syncoid_finalize.j2
index 638781ac..05423880 100644
--- a/roles/storage/zfs/syncoid/templates/syncoid_finalize.j2
+++ b/roles/storage/zfs/syncoid/templates/syncoid_finalize.j2
@@ -1,5 +1,5 @@
#!/bin/bash
-{% if zfs_syncoid_autosuspend %}
+{% if zfs_syncoid_autosuspend is defined %}
echo "running sanoid --prune to cleanup old snapshots"
sleep 5