From 40770405e32fc0a2edad52a64963f9beff0692c7 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 9 Apr 2018 15:04:42 +0200 Subject: Hold lock while snapshot exists --- custom/lvm-snapshots.nix | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'custom') diff --git a/custom/lvm-snapshots.nix b/custom/lvm-snapshots.nix index af8b61bb..afa5a9d6 100644 --- a/custom/lvm-snapshots.nix +++ b/custom/lvm-snapshots.nix @@ -71,12 +71,19 @@ in { unitConfig = { StopWhenUnneeded = !scfg.persist; + AssertPathIsDirectory = "/var/lock"; }; - path = with pkgs; [ devicemapper ]; + path = with pkgs; [ devicemapper utillinux ]; script = '' - lvcreate -s ${scfg.cowSize} --name ${snapshotName name} ${scfg.VG}/${scfg.LV} + ( + flock -xn 9 || exit 1 + + lvcreate -s ${scfg.cowSize} --name ${snapshotName name} ${scfg.VG}/${scfg.LV} + + sleep infinity & + ) 9>/var/lock/lvm-snapshot.${scfg.VG} ''; preStop = '' @@ -84,8 +91,7 @@ in { ''; serviceConfig = with pkgs; { - Type = "oneshot"; - RemainAfterExit = true; + Type = "forking"; }; }) cfg.snapshots; -- cgit v1.2.3