From 955aa64d87f970b6fc3bf715a0010cdf7e4a2e1e Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Tue, 18 Dec 2018 01:41:47 +0000 Subject: [PATCH] Add fstrim timer to ansible play --- ansible/etc/systemd/system/fstrim.service | 6 ++++++ ansible/etc/systemd/system/fstrim.timer | 11 +++++++++++ ansible/main.yml | 22 ++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 ansible/etc/systemd/system/fstrim.service create mode 100644 ansible/etc/systemd/system/fstrim.timer diff --git a/ansible/etc/systemd/system/fstrim.service b/ansible/etc/systemd/system/fstrim.service new file mode 100644 index 0000000..cf740d3 --- /dev/null +++ b/ansible/etc/systemd/system/fstrim.service @@ -0,0 +1,6 @@ +[Unit] +Description=Discard unused blocks + +[Service] +Type=oneshot +ExecStart=/sbin/fstrim -av diff --git a/ansible/etc/systemd/system/fstrim.timer b/ansible/etc/systemd/system/fstrim.timer new file mode 100644 index 0000000..3a3762d --- /dev/null +++ b/ansible/etc/systemd/system/fstrim.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Discard unused blocks once a week +Documentation=man:fstrim + +[Timer] +OnCalendar=weekly +AccuracySec=1h +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/ansible/main.yml b/ansible/main.yml index b2ca6aa..596ac63 100644 --- a/ansible/main.yml +++ b/ansible/main.yml @@ -38,6 +38,28 @@ when: apt_update is changed + # ------------------------------------------------------------------------- + # Loki uses SSDs so use fstrim on a timer. + # ------------------------------------------------------------------------- + + - name: Copy fstrim service file + copy: + src: ./etc/systemd/system/fstrim.service + dest: /etc/systemd/system/fstrim.service + mode: 0644 + + - name: Copy fstrim timer file + copy: + src: ./etc/systemd/system/fstrim.timer + dest: /etc/systemd/system/fstrim.timer + mode: 0644 + + - name: Enable and start fstrim.timer + service: + name: fstrim.timer + state: started + enabled: yes + # ------------------------------------------------------------------------- # Apparmor. # -------------------------------------------------------------------------