diff options
| author | Joey Hess <joey@kitenet.net> | 2014-11-20 14:06:55 -0400 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-11-20 14:15:26 -0400 |
| commit | b8b746a7f1bdbf179136959a85138fde60c43588 (patch) | |
| tree | 48e9b5c95a7f0ec1ef0f899513e65de96124c31a /src/Propellor/Property/Chroot.hs | |
| parent | cc8bbcf95b9b0cdcd2db17ee6049263498caa79b (diff) | |
starting work on a Chroot module
factored out info up-propigation code rom Docker
Diffstat (limited to 'src/Propellor/Property/Chroot.hs')
| -rw-r--r-- | src/Propellor/Property/Chroot.hs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/Propellor/Property/Chroot.hs b/src/Propellor/Property/Chroot.hs new file mode 100644 index 00000000..e5046937 --- /dev/null +++ b/src/Propellor/Property/Chroot.hs @@ -0,0 +1,57 @@ +module Propellor.Property.Chroot ( + Chroot, + chroot, + provisioned, +) where + +import Propellor +import qualified Propellor.Property.Debootstrap as Debootstrap + +import qualified Data.Map as M + +data Chroot = Chroot FilePath System Host + +instance Hostlike Chroot where + (Chroot l s h) & p = Chroot l s (h & p) + (Chroot l s h) &^ p = Chroot l s (h &^ p) + getHost (Chroot _ _ h) = h + +-- | Defines a Chroot at the given location, containing the specified +-- System. Properties can be added to configure the Chroot. +-- +-- > chroot "/srv/chroot/ghc-dev" (System (Debian Unstable) "amd64" +-- > & Apt.installed ["build-essential", "ghc", "haskell-platform"] +-- > & ... +chroot :: FilePath -> System -> Chroot +chroot location system = Chroot location system (Host location [] mempty) + +-- | Ensures that the chroot exists and is provisioned according to its +-- properties. +-- +-- Reverting this property removes the chroot. Note that it does not ensure +-- that any processes that might be running inside the chroot are stopped. +provisioned :: Chroot -> RevertableProperty +provisioned c@(Chroot loc system _) = RevertableProperty + (propigateChrootInfo c (go "exists" setup)) + (go "removed" teardown) + where + go desc a = property ("chroot " ++ loc ++ " " ++ desc) $ do + ensureProperties [a] + + setup = provisionChroot c `requires` built + + built = case system of + (System (Debian _) _) -> debootstrap + (System (Ubuntu _) _) -> debootstrap + + debootstrap = unrevertable (Debootstrap.built loc system []) + + teardown = undefined + +propigateChrootInfo :: Chroot -> Property -> Property +propigateChrootInfo c@(Chroot loc _ h) p = propigateInfo c p (<> chrootinfo) + where + chrootinfo = mempty $ mempty { _chroots = M.singleton loc h } + +provisionChroot :: Chroot -> Property +provisionChroot = undefined |
