summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
l---------config.hs2
-rw-r--r--debian/changelog13
-rw-r--r--doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap.mdwn3
-rw-r--r--doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_1_8ab6b313c80486f8f87a5e13e830bfa9._comment20
-rw-r--r--doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_2_773fc1441dd06e9dd41508bd800298eb._comment13
-rw-r--r--doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_3_f48a6191c56bed41eda55436f0aa3e9c._comment15
-rw-r--r--doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_4_b1769231a633ad2b978ee4c9fa90591c._comment9
-rw-r--r--doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_5_6dc24952c8efa31a401191a8cf2d0b39._comment14
-rw-r--r--doc/forum/Git.cloned_deletes_harmless_empty_directory.mdwn3
-rw-r--r--doc/forum/Git.cloned_deletes_harmless_empty_directory/comment_1_7cd0521c6d071b25852f8355f4f61f94._comment20
-rw-r--r--doc/forum/Git.cloned_deletes_harmless_empty_directory/comment_2_289f157f129511242d93beae76fd03a3._comment11
-rw-r--r--doc/forum/Manage_multiple_different_projects_with_propellor.mdwn7
-rw-r--r--doc/forum/Manage_multiple_different_projects_with_propellor/comment_1_dbad48163b2efd6434ea7c37a72dfd30._comment14
-rw-r--r--doc/forum/Using_propellor_for_continers_only.mdwn5
-rw-r--r--doc/forum/Using_propellor_for_continers_only/comment_1_95e8b7103f248d93570fecb6b8999996._comment20
-rw-r--r--doc/forum/Using_propellor_for_continers_only/comment_2_42b45a126cfdf1dfc370b166c8042690._comment8
-rw-r--r--doc/news/version_4.0.1.mdwn6
-rw-r--r--doc/news/version_4.0.2.mdwn12
-rw-r--r--doc/todo/initial_spin_compile_failure_recovery.mdwn5
-rw-r--r--doc/todo/property_to_install_propellor.mdwn14
-rw-r--r--privdata/relocate1
-rw-r--r--propellor.cabal2
-rw-r--r--src/Propellor/Property/Fstab.hs29
-rw-r--r--src/Propellor/Property/Mount.hs14
24 files changed, 240 insertions, 20 deletions
diff --git a/config.hs b/config.hs
index 97d90636..ec313725 120000
--- a/config.hs
+++ b/config.hs
@@ -1 +1 @@
-joeyconfig.hs \ No newline at end of file
+config-simple.hs \ No newline at end of file
diff --git a/debian/changelog b/debian/changelog
index 11c9922f..dcbe0a3e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,4 +1,11 @@
-propellor (4.0.2) UNRELEASED; urgency=medium
+propellor (4.0.3) UNRELEASED; urgency=medium
+
+ * Added Fstab.listed, Fstab.swap, and Mount.swapOn properties.
+ Thanks, Daniel Brooks.
+
+ -- Joey Hess <id@joeyh.name> Thu, 06 Apr 2017 19:40:12 -0400
+
+propellor (4.0.2) unstable; urgency=medium
* Apt.mirror can be used to set the preferred apt mirror of a host,
overriding the default CDN. This info is used by
@@ -10,8 +17,8 @@ propellor (4.0.2) UNRELEASED; urgency=medium
properties added to a chroot that way from being seen when propellor
was running inside the chroot. This affected disk image creation, and
possibly other things that use chroots.
-
- -- Joey Hess <id@joeyh.name> Sun, 19 Mar 2017 16:37:27 -0400
+
+ -- Joey Hess <id@joeyh.name> Fri, 24 Mar 2017 14:04:50 -0400
propellor (4.0.1) unstable; urgency=medium
diff --git a/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap.mdwn b/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap.mdwn
new file mode 100644
index 00000000..61cd10cc
--- /dev/null
+++ b/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap.mdwn
@@ -0,0 +1,3 @@
+The mount command won't work when activating a swap partition/file, so we should call swapon instead.
+
+https://github.com/ArchiveTeam/glowing-computing-machine/tree/fstab-swap
diff --git a/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_1_8ab6b313c80486f8f87a5e13e830bfa9._comment b/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_1_8ab6b313c80486f8f87a5e13e830bfa9._comment
new file mode 100644
index 00000000..4a144df5
--- /dev/null
+++ b/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_1_8ab6b313c80486f8f87a5e13e830bfa9._comment
@@ -0,0 +1,20 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 1"""
+ date="2017-04-05T02:17:00Z"
+ content="""
+This idea kind of makes sense, because swap partitions in /etc/fstab
+get swaponed at boot.
+
+But, the implementation doesn't take the types into account. The `mounted`
+property takes a FilePath for the mountpoint, but for swap that
+needs to be "none", which is not really a file-path. Also, the `fstabbed`
+property has a separate `SwapPartition` type, so making `mount` support
+swap partitions without using that type feels wrong.
+
+It might be simpler all round to treat swap partitions being able to
+be specified in /etc/fstab as a historical accident, which it kind of
+is (increasingly so, since eg systemd has other ways to accomplish
+that), and instead of shoehorning this into the `mounted` property,
+add a new `swaponed` property.
+"""]]
diff --git a/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_2_773fc1441dd06e9dd41508bd800298eb._comment b/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_2_773fc1441dd06e9dd41508bd800298eb._comment
new file mode 100644
index 00000000..62cabc0a
--- /dev/null
+++ b/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_2_773fc1441dd06e9dd41508bd800298eb._comment
@@ -0,0 +1,13 @@
+[[!comment format=mdwn
+ username="db48x@80bd751a72d5a80737e2f875342cf845629c7202"
+ nickname="db48x"
+ avatar="http://cdn.libravatar.org/avatar/ad2688127feb555a92154b16d8eeb5d3"
+ subject="comment 2"
+ date="2017-04-05T02:48:08Z"
+ content="""
+Yes, perhaps if it took an Option FilePath (am I saying this correctly in Haskellese?) it would be nicer.
+
+I don't mind much how it's structured; this was just the smallest obvious change, since it was failing to mount it. Perhaps breaking it up into smaller, more primitive, pieces would help. Fstab.mounted could = Fstab.fstabbed `onChange` Fstab.mounted, for instance, and then I could write Fstab.fstabbed `onChange` Swap.swapEnabled (oh, but Fstab.fstabbed already exists; I'm not using it because it replaces the whole file, which seems like an odd thing to do. Maybe call it Fstab.listed instead?).
+
+Also, for maximum irony I was just perusing your most recent dozen commits or so, and saw you enable Apt.serviceInstalledRunning \"swapspace\" on one of your machines. That's amazing; I had no idea it existed! I am re-evaluating all of my life choices now.
+"""]]
diff --git a/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_3_f48a6191c56bed41eda55436f0aa3e9c._comment b/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_3_f48a6191c56bed41eda55436f0aa3e9c._comment
new file mode 100644
index 00000000..95c69551
--- /dev/null
+++ b/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_3_f48a6191c56bed41eda55436f0aa3e9c._comment
@@ -0,0 +1,15 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 3"""
+ date="2017-04-05T03:08:30Z"
+ content="""
+I like the idea of composing smaller properties to build the current
+property, and add flexability.
+
+Renaming the existing `fstabbed` would probably be too much bother.
+(Also, I think I picked that name because it kind of hints that the
+existing fstab does not come out alive.)
+
+(The swapspace package is great if you can eat the now tiny overhead of a
+swap file compared to a swap partition.)
+"""]]
diff --git a/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_4_b1769231a633ad2b978ee4c9fa90591c._comment b/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_4_b1769231a633ad2b978ee4c9fa90591c._comment
new file mode 100644
index 00000000..ca04f945
--- /dev/null
+++ b/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_4_b1769231a633ad2b978ee4c9fa90591c._comment
@@ -0,0 +1,9 @@
+[[!comment format=mdwn
+ username="db48x@80bd751a72d5a80737e2f875342cf845629c7202"
+ nickname="db48x"
+ avatar="http://cdn.libravatar.org/avatar/ad2688127feb555a92154b16d8eeb5d3"
+ subject="comment 4"
+ date="2017-04-05T06:39:49Z"
+ content="""
+I took a stab at implementing this. It compiles, but I've not tested it yet as I need to get some sleep; consider it a work in progress. Looks right to me though.
+"""]]
diff --git a/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_5_6dc24952c8efa31a401191a8cf2d0b39._comment b/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_5_6dc24952c8efa31a401191a8cf2d0b39._comment
new file mode 100644
index 00000000..f87500b2
--- /dev/null
+++ b/doc/forum/Fstab.mounted_could_call_swapon_when_activating_swap/comment_5_6dc24952c8efa31a401191a8cf2d0b39._comment
@@ -0,0 +1,14 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 5"""
+ date="2017-04-06T23:51:08Z"
+ content="""
+Merged. Have not tested it either.
+
+On my Debian system, the swapon command does not support the
+`--no-headings` that you used. It's `--noheadings` here. Is that a typo in
+your patch?
+
+I've simply removed that option for now, since it probably won't
+hurt if it treats the heading like another device that's swapped on.
+"""]]
diff --git a/doc/forum/Git.cloned_deletes_harmless_empty_directory.mdwn b/doc/forum/Git.cloned_deletes_harmless_empty_directory.mdwn
new file mode 100644
index 00000000..ce3c192c
--- /dev/null
+++ b/doc/forum/Git.cloned_deletes_harmless_empty_directory.mdwn
@@ -0,0 +1,3 @@
+In my case I have carefully set up the directory that I'm going to clone into with the correct group ownership and setgid permission, so that the cloned files will also have the correct ownership. This change just checks to see if the directory actually has anything in it before it deletes it.
+
+https://github.com/ArchiveTeam/glowing-computing-machine/tree/git-in-emtpy-directory
diff --git a/doc/forum/Git.cloned_deletes_harmless_empty_directory/comment_1_7cd0521c6d071b25852f8355f4f61f94._comment b/doc/forum/Git.cloned_deletes_harmless_empty_directory/comment_1_7cd0521c6d071b25852f8355f4f61f94._comment
new file mode 100644
index 00000000..91b403b0
--- /dev/null
+++ b/doc/forum/Git.cloned_deletes_harmless_empty_directory/comment_1_7cd0521c6d071b25852f8355f4f61f94._comment
@@ -0,0 +1,20 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 1"""
+ date="2017-04-05T02:22:54Z"
+ content="""
+I am not entirely happy with this patch, because it seems that if
+Git.cloned took care to preserve permissions in this case, it could be
+argued that it should also preserve permissions when the directory already
+exists but has the wrong content. Or equally well argued that it should not
+preserve permissions, which might be a leftover from some past unwanted
+state.
+
+Is that really the best way to do it? You could instead say:
+
+ Git.cloned user repo dir Nothing
+ `onChange` recursiveSetGID user dir
+
+And then you just have to write a recursiveSetGID which would be a
+generally useful property.
+"""]]
diff --git a/doc/forum/Git.cloned_deletes_harmless_empty_directory/comment_2_289f157f129511242d93beae76fd03a3._comment b/doc/forum/Git.cloned_deletes_harmless_empty_directory/comment_2_289f157f129511242d93beae76fd03a3._comment
new file mode 100644
index 00000000..1a8c1447
--- /dev/null
+++ b/doc/forum/Git.cloned_deletes_harmless_empty_directory/comment_2_289f157f129511242d93beae76fd03a3._comment
@@ -0,0 +1,11 @@
+[[!comment format=mdwn
+ username="db48x@80bd751a72d5a80737e2f875342cf845629c7202"
+ nickname="db48x"
+ avatar="http://cdn.libravatar.org/avatar/ad2688127feb555a92154b16d8eeb5d3"
+ subject="comment 2"
+ date="2017-04-05T02:37:44Z"
+ content="""
+Yea, I guess that's a fair point about the other cases.
+
+It just seems inelegant to go back over all the files and fix up their permissions, when it could just have been set right to begin with.
+"""]]
diff --git a/doc/forum/Manage_multiple_different_projects_with_propellor.mdwn b/doc/forum/Manage_multiple_different_projects_with_propellor.mdwn
new file mode 100644
index 00000000..bcba383c
--- /dev/null
+++ b/doc/forum/Manage_multiple_different_projects_with_propellor.mdwn
@@ -0,0 +1,7 @@
+Hi there,
+
+I've been tasked with investigating propellor as an alternative to Ansible. I'm a little bit confused about how one might go about managing a *single* project's hosts with propellor, without infecting the global propellor config. It seems that everything is concerned with the ~/.propellor repository. However, I don't want project A's hosts to know about project B's and vice versa. I'm sure I'm overlooking something obvious!
+
+Thanks very much!
+
+Mitchell
diff --git a/doc/forum/Manage_multiple_different_projects_with_propellor/comment_1_dbad48163b2efd6434ea7c37a72dfd30._comment b/doc/forum/Manage_multiple_different_projects_with_propellor/comment_1_dbad48163b2efd6434ea7c37a72dfd30._comment
new file mode 100644
index 00000000..7513cc09
--- /dev/null
+++ b/doc/forum/Manage_multiple_different_projects_with_propellor/comment_1_dbad48163b2efd6434ea7c37a72dfd30._comment
@@ -0,0 +1,14 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 1"""
+ date="2017-03-24T18:14:14Z"
+ content="""
+There did not used to be a good way to do that, but since propellor 3.2.3,
+when you run eg "propellor --spin host", it first checks to see if there is
+a `./config.hs` file, and if so, uses it instead of the user-global
+`~/.propellor/config.hs`.
+
+So, just make different git repos for the different projects with propellor
+`config.hs` files in them, and `cd` into the one you want to run before running
+propellor.
+"""]]
diff --git a/doc/forum/Using_propellor_for_continers_only.mdwn b/doc/forum/Using_propellor_for_continers_only.mdwn
new file mode 100644
index 00000000..faf07956
--- /dev/null
+++ b/doc/forum/Using_propellor_for_continers_only.mdwn
@@ -0,0 +1,5 @@
+Hi,
+
+I was wondering: Is it possible to use propellor to generate images only without actually managing any hosts per-se? I couldn't find any documentation on that.
+
+Ideally, I'd also be able to use it directly from a sandbox so that I wouldn't have to even "pollute" the GHC/Cabal "global" (user home dir) database on the development machine. I see that there's support for having the config.hs stored in a different directory than ~/.propellor, but I haven't managed to get it working when I use a sandbox in e.g. ~/foo with the config.hs stored in the same directory. Perhaps that's just a bug? If it's supposed to work I can provide detailed error messages, etc. **EDIT:** I'd also like to manage the git repository myself -- is that possible?
diff --git a/doc/forum/Using_propellor_for_continers_only/comment_1_95e8b7103f248d93570fecb6b8999996._comment b/doc/forum/Using_propellor_for_continers_only/comment_1_95e8b7103f248d93570fecb6b8999996._comment
new file mode 100644
index 00000000..dc6cc616
--- /dev/null
+++ b/doc/forum/Using_propellor_for_continers_only/comment_1_95e8b7103f248d93570fecb6b8999996._comment
@@ -0,0 +1,20 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 1"""
+ date="2017-03-29T19:09:37Z"
+ content="""
+Sounds like you may want to write a program that uses propellor as a
+library. `Propellor.Engine.mainProperties` is a reasonable
+entry point, just pass it a Host that has the properties you want
+to run.
+
+For example:
+
+ import Propellor
+ import Propellor.Engine
+ import Propellor.Property.DiskImage
+
+ main :: IO ()
+ main = mainProperties $ host "whatever" $ props
+ & imageBuilt "/some/disk.img" ...
+"""]]
diff --git a/doc/forum/Using_propellor_for_continers_only/comment_2_42b45a126cfdf1dfc370b166c8042690._comment b/doc/forum/Using_propellor_for_continers_only/comment_2_42b45a126cfdf1dfc370b166c8042690._comment
new file mode 100644
index 00000000..45cd3e0c
--- /dev/null
+++ b/doc/forum/Using_propellor_for_continers_only/comment_2_42b45a126cfdf1dfc370b166c8042690._comment
@@ -0,0 +1,8 @@
+[[!comment format=mdwn
+ username="bardur.arantsson"
+ avatar="http://cdn.libravatar.org/avatar/a0be0039b44d33262b7ae650a0803ad5"
+ subject="comment 2"
+ date="2017-04-06T02:14:58Z"
+ content="""
+I'll try that this weekend, thanks!
+"""]]
diff --git a/doc/news/version_4.0.1.mdwn b/doc/news/version_4.0.1.mdwn
deleted file mode 100644
index e870a510..00000000
--- a/doc/news/version_4.0.1.mdwn
+++ /dev/null
@@ -1,6 +0,0 @@
-propellor 4.0.1 released with [[!toggle text="these changes"]]
-[[!toggleable text="""
- * Fix build with pre-AMP ghc.
- * Tor: Restart daemon after installing private key.
- * Tor.named, Tor.torPrivKey: Include the new ed25519 public/private key
- pair in addition to the old secret\_id\_key."""]] \ No newline at end of file
diff --git a/doc/news/version_4.0.2.mdwn b/doc/news/version_4.0.2.mdwn
new file mode 100644
index 00000000..b955c579
--- /dev/null
+++ b/doc/news/version_4.0.2.mdwn
@@ -0,0 +1,12 @@
+propellor 4.0.2 released with [[!toggle text="these changes"]]
+[[!toggleable text="""
+ * Apt.mirror can be used to set the preferred apt mirror of a host,
+ overriding the default CDN. This info is used by
+ Apt.stdSourcesList and Sbuild.builtFor.
+ Thanks, Sean Whitton.
+ * Property.Partition: Update kpartx output parser, as its output format
+ changed around version 0.6. Both output formats are supported now.
+ * Fix bug when using setContainerProps with a chroot that prevented
+ properties added to a chroot that way from being seen when propellor
+ was running inside the chroot. This affected disk image creation, and
+ possibly other things that use chroots."""]] \ No newline at end of file
diff --git a/doc/todo/initial_spin_compile_failure_recovery.mdwn b/doc/todo/initial_spin_compile_failure_recovery.mdwn
new file mode 100644
index 00000000..423b279c
--- /dev/null
+++ b/doc/todo/initial_spin_compile_failure_recovery.mdwn
@@ -0,0 +1,5 @@
+When initial propellor --spin host fails to compile propellor
+perhaps due to a ghc compatability bug, spinning again doesn't fix the
+problem. IIRC /usr/local/propellor has a git repo set up, but no remote
+set, and so the subsequent spin doesn't update it, since propellor is not
+running there to receive a git push into the repo. --[[Joey]]
diff --git a/doc/todo/property_to_install_propellor.mdwn b/doc/todo/property_to_install_propellor.mdwn
new file mode 100644
index 00000000..25db8193
--- /dev/null
+++ b/doc/todo/property_to_install_propellor.mdwn
@@ -0,0 +1,14 @@
+This seems redundant, since propellor must be running to ensure such a
+Property, but a Property to install propellor is useful when eg, creating a
+disk image that itself will need to run propellor. --[[Joey]]
+
+Should support:
+
+* Cloning the git repo propellor is running in. (Using eg `hostChroot`)
+* Cloning some other git repo.
+* Installing the precompiled propellor binary.
+* Installing the propellor haskell library using cabal/stack/apt.
+
+Much of this is already implemented, in non-Property form, in
+Propellor.Bootstrap, but will need adjustments for this new context.
+--[[Joey]]
diff --git a/privdata/relocate b/privdata/relocate
deleted file mode 100644
index 271692d8..00000000
--- a/privdata/relocate
+++ /dev/null
@@ -1 +0,0 @@
-.joeyconfig
diff --git a/propellor.cabal b/propellor.cabal
index f4a1f23a..714c3235 100644
--- a/propellor.cabal
+++ b/propellor.cabal
@@ -1,5 +1,5 @@
Name: propellor
-Version: 4.0.1
+Version: 4.0.2
Cabal-Version: >= 1.8
License: BSD2
Maintainer: Joey Hess <id@joeyh.name>
diff --git a/src/Propellor/Property/Fstab.hs b/src/Propellor/Property/Fstab.hs
index 60f11d8e..29b85426 100644
--- a/src/Propellor/Property/Fstab.hs
+++ b/src/Propellor/Property/Fstab.hs
@@ -24,19 +24,32 @@ import Utility.Table
-- Note that if anything else is already mounted at the `MountPoint`, it
-- will be left as-is by this property.
mounted :: FsType -> Source -> MountPoint -> MountOpts -> Property Linux
-mounted fs src mnt opts = tightenTargets $
- "/etc/fstab" `File.containsLine` l
- `describe` (mnt ++ " mounted by fstab")
+mounted fs src mnt opts = tightenTargets $
+ listed fs src mnt opts
`onChange` mountnow
where
- l = intercalate "\t" [src, mnt, fs, formatMountOpts opts, dump, passno]
- dump = "0"
- passno = "2"
-- This use of mountPoints, which is linux-only, is why this
-- property currently only supports linux.
mountnow = check (notElem mnt <$> mountPoints) $
cmdProperty "mount" [mnt]
+-- | Ensures that </etc/fstab> contains a line mounting the specified
+-- `Source` on the specified `MountPoint`. Does not ensure that it's
+-- currently `mounted`.
+listed :: FsType -> Source -> MountPoint -> MountOpts -> Property UnixLike
+listed fs src mnt opts = "/etc/fstab" `File.containsLine` l
+ `describe` (mnt ++ " mounted by fstab")
+ where
+ l = intercalate "\t" [src, mnt, fs, formatMountOpts opts, dump, passno]
+ dump = "0"
+ passno = "2"
+
+-- | Ensures that </etc/fstab> contains a line enabling the specified
+-- `Source` to be used as swap space, and that it's enabled.
+swap :: Source -> Property Linux
+swap src = listed "swap" src "none" mempty
+ `onChange` swapOn src
+
newtype SwapPartition = SwapPartition FilePath
-- | Replaces </etc/fstab> with a file that should cause the currently
@@ -77,8 +90,8 @@ genFstab mnts swaps mnttransform = do
, pure "0"
, pure (if mnt == "/" then "1" else "2")
]
- getswapcfg (SwapPartition swap) = sequence
- [ fromMaybe swap <$> getM (\a -> a swap)
+ getswapcfg (SwapPartition s) = sequence
+ [ fromMaybe s <$> getM (\a -> a s)
[ uuidprefix getSourceUUID
, sourceprefix getSourceLabel
]
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