diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2018-04-09 15:04:42 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2018-04-09 15:04:42 +0200 |
commit | 40770405e32fc0a2edad52a64963f9beff0692c7 (patch) | |
tree | 0fc9ebb71d262c545b03c2e0a9c70799daa78a8e /custom | |
parent | 215ab1596bc5adfc16789844e2e9d3b27cc698c0 (diff) | |
download | nixos-40770405e32fc0a2edad52a64963f9beff0692c7.tar nixos-40770405e32fc0a2edad52a64963f9beff0692c7.tar.gz nixos-40770405e32fc0a2edad52a64963f9beff0692c7.tar.bz2 nixos-40770405e32fc0a2edad52a64963f9beff0692c7.tar.xz nixos-40770405e32fc0a2edad52a64963f9beff0692c7.zip |
Hold lock while snapshot exists
Diffstat (limited to 'custom')
-rw-r--r-- | custom/lvm-snapshots.nix | 14 |
1 files changed, 10 insertions, 4 deletions
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 { | |||
71 | 71 | ||
72 | unitConfig = { | 72 | unitConfig = { |
73 | StopWhenUnneeded = !scfg.persist; | 73 | StopWhenUnneeded = !scfg.persist; |
74 | AssertPathIsDirectory = "/var/lock"; | ||
74 | }; | 75 | }; |
75 | 76 | ||
76 | path = with pkgs; [ devicemapper ]; | 77 | path = with pkgs; [ devicemapper utillinux ]; |
77 | 78 | ||
78 | script = '' | 79 | script = '' |
79 | lvcreate -s ${scfg.cowSize} --name ${snapshotName name} ${scfg.VG}/${scfg.LV} | 80 | ( |
81 | flock -xn 9 || exit 1 | ||
82 | |||
83 | lvcreate -s ${scfg.cowSize} --name ${snapshotName name} ${scfg.VG}/${scfg.LV} | ||
84 | |||
85 | sleep infinity & | ||
86 | ) 9>/var/lock/lvm-snapshot.${scfg.VG} | ||
80 | ''; | 87 | ''; |
81 | 88 | ||
82 | preStop = '' | 89 | preStop = '' |
@@ -84,8 +91,7 @@ in { | |||
84 | ''; | 91 | ''; |
85 | 92 | ||
86 | serviceConfig = with pkgs; { | 93 | serviceConfig = with pkgs; { |
87 | Type = "oneshot"; | 94 | Type = "forking"; |
88 | RemainAfterExit = true; | ||
89 | }; | 95 | }; |
90 | }) cfg.snapshots; | 96 | }) cfg.snapshots; |
91 | 97 | ||