summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorTimo Kaufmann <timokau@zoho.com>2020-06-19 22:55:19 +0200
committerGitHub <noreply@github.com>2020-06-19 22:55:19 +0200
commit4843eab3a1238ac358c980a6e92cd5773c2092e4 (patch)
tree1f828784ac3ae5012e25c6b26a292383cf8545bb /nixos
parentae423cfeab1ea99add7642d7d4d9b3b39a80d1c8 (diff)
parent55d16d533446a815c5d266b72ff84bc97300fddc (diff)
Merge pull request #84135 from symphorien/btrfs-scrub-success
nixos/btrfs autoScrub: don't fail when scrub finishes successfully
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/tasks/filesystems/btrfs.nix5
1 files changed, 4 insertions, 1 deletions
diff --git a/nixos/modules/tasks/filesystems/btrfs.nix b/nixos/modules/tasks/filesystems/btrfs.nix
index f64493e1a3c78..c0ff28039b16e 100644
--- a/nixos/modules/tasks/filesystems/btrfs.nix
+++ b/nixos/modules/tasks/filesystems/btrfs.nix
@@ -128,7 +128,10 @@ in
             Nice = 19;
             IOSchedulingClass = "idle";
             ExecStart = "${pkgs.btrfs-progs}/bin/btrfs scrub start -B ${fs}";
-            ExecStop  = "${pkgs.btrfs-progs}/bin/btrfs scrub cancel ${fs}";
+            # if the service is stopped before scrub end, cancel it
+            ExecStop  = pkgs.writeShellScript "btrfs-scrub-maybe-cancel" ''
+              (${pkgs.btrfs-progs}/bin/btrfs scrub status ${fs} | ${pkgs.gnugrep}/bin/grep finished) || ${pkgs.btrfs-progs}/bin/btrfs scrub cancel ${fs}
+            '';
           };
         };
       in listToAttrs (map scrubService cfgScrub.fileSystems);