diff --git a/ansible/roles/app/tasks/node/set_raid.yaml b/ansible/roles/app/tasks/node/set_raid.yaml index e10992f..ee0fee9 100644 --- a/ansible/roles/app/tasks/node/set_raid.yaml +++ b/ansible/roles/app/tasks/node/set_raid.yaml @@ -68,3 +68,23 @@ group: "svadmins" mode: "0770" become: true + +- name: Deploy btrfs scrub service and timer + ansible.builtin.template: + src: "{{ hostvars['console']['node']['config_path'] }}/services/systemd/app/btrfs/{{ item }}.j2" + dest: "/etc/systemd/system/{{ item }}" + owner: "root" + group: "root" + mode: "0644" + loop: + - "btrfs-scrub.service" + - "btrfs-scrub.timer" + become: true + +- name: Enable auto btrfs scrub + ansible.builtin.systemd: + name: "btrfs-scrub.timer" + state: "started" + enabled: true + daemon_reload: true + become: true diff --git a/config/services/systemd/app/btrfs/btrfs-scrub.service.j2 b/config/services/systemd/app/btrfs/btrfs-scrub.service.j2 new file mode 100644 index 0000000..e502400 --- /dev/null +++ b/config/services/systemd/app/btrfs/btrfs-scrub.service.j2 @@ -0,0 +1,10 @@ +[Unit] +Description=BTRFS auto scrub +ConditionPathIsMountPoint={{ node['home_path'] }}/data +RequiresMountsFor={{ node['home_path'] }}/data + +[Service] +Type=oneshot +ExecStart=/usr/bin/btrfs scrub start -Bd {{ node['home_path'] }}/data +Nice=19 +IOSchedulingClass=idle diff --git a/config/services/systemd/app/btrfs/btrfs-scrub.timer.j2 b/config/services/systemd/app/btrfs/btrfs-scrub.timer.j2 new file mode 100644 index 0000000..9bd2559 --- /dev/null +++ b/config/services/systemd/app/btrfs/btrfs-scrub.timer.j2 @@ -0,0 +1,10 @@ +[Unit] +Description=Monthly BTRFS auto scrub + +[Timer] +OnCalendar=*-*-01 04:00:00 +Persistent=true +RandomizedDelaySec=300 + +[Install] +WantedBy=timers.target