summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Mount.hs
diff options
context:
space:
mode:
authorJoey Hess2017-04-09 17:52:04 -0400
committerJoey Hess2017-04-09 17:52:04 -0400
commitb0cb72410d59a5a111d4235dec05fda666ee6ff8 (patch)
treeede43750e4e95d9090ccb19beff067a2facb5035 /src/Propellor/Property/Mount.hs
parent6a632221a2d2d1e31859c8deb79543056224a76f (diff)
parent57525e0d0d1d300aa807f1c876945ee5e38a29df (diff)
Merge remote-tracking branch 'origin' into joeyconfig
Diffstat (limited to 'src/Propellor/Property/Mount.hs')
-rw-r--r--src/Propellor/Property/Mount.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Propellor/Property/Mount.hs b/src/Propellor/Property/Mount.hs
index 026509a9..5dcc5fe1 100644
--- a/src/Propellor/Property/Mount.hs
+++ b/src/Propellor/Property/Mount.hs
@@ -40,6 +40,9 @@ formatMountOpts (MountOpts []) = "defaults"
formatMountOpts (MountOpts l) = intercalate "," l
-- | Mounts a device, without listing it in </etc/fstab>.
+--
+-- Note that this property will fail if the device is already mounted
+-- at the MountPoint.
mounted :: FsType -> Source -> MountPoint -> MountOpts -> Property UnixLike
mounted fs src mnt opts = property (mnt ++ " mounted") $
toResult <$> liftIO (mount fs src mnt opts)
@@ -52,6 +55,17 @@ bindMount src dest = tightenTargets $
`assume` MadeChange
`describe` ("bind mounted " ++ src ++ " to " ++ dest)
+-- | Enables swapping to a device, which must be formatted already as a swap
+-- partition.
+swapOn :: Source -> RevertableProperty Linux Linux
+swapOn mnt = tightenTargets doswapon <!> tightenTargets doswapoff
+ where
+ swaps = lines <$> readProcess "swapon" ["--show=NAME"]
+ doswapon = check (notElem mnt <$> swaps) $
+ cmdProperty "swapon" [mnt]
+ doswapoff = check (elem mnt <$> swaps) $
+ cmdProperty "swapoff" [mnt]
+
mount :: FsType -> Source -> MountPoint -> MountOpts -> IO Bool
mount fs src mnt opts = boolSystem "mount" $
[ Param "-t", Param fs