diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Propellor/Property/Chroot.hs | 20 | ||||
| -rw-r--r-- | src/Propellor/Property/Hostname.hs | 13 | ||||
| -rw-r--r-- | src/Propellor/Property/Systemd.hs | 2 |
3 files changed, 29 insertions, 6 deletions
diff --git a/src/Propellor/Property/Chroot.hs b/src/Propellor/Property/Chroot.hs index ecac1115..771c4b99 100644 --- a/src/Propellor/Property/Chroot.hs +++ b/src/Propellor/Property/Chroot.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE FlexibleContexts, GADTs #-} +{-# LANGUAGE FlexibleContexts, GADTs, DeriveDataTypeable #-} module Propellor.Property.Chroot ( debootstrapped, @@ -8,6 +8,7 @@ module Propellor.Property.Chroot ( ChrootBootstrapper(..), Debootstrapped(..), ChrootTarball(..), + inChroot, -- * Internal use provisioned', propagateChrootInfo, @@ -207,7 +208,7 @@ chain hostlist (ChrootChain hn loc systemdonly onconsole) = changeWorkingDirectory localdir when onconsole forceConsole onlyProcess (provisioningLock loc) $ do - r <- runPropellor h $ ensureProperties $ + r <- runPropellor (setInChroot h) $ ensureProperties $ if systemdonly then [Systemd.installed] else map ignoreInfo $ @@ -243,3 +244,18 @@ mungeloc = replace "/" "_" chrootDesc :: Chroot -> String -> String chrootDesc (Chroot loc _ _) desc = "chroot " ++ loc ++ " " ++ desc + +-- | Check if propellor is currently running within a chroot. +-- +-- This allows properties to check and avoid performing actions that +-- should not be done in a chroot. +inChroot :: Propellor Bool +inChroot = extract . fromMaybe (InChroot False) . fromInfoVal <$> askInfo + where + extract (InChroot b) = b + +setInChroot :: Host -> Host +setInChroot h = h { hostInfo = hostInfo h `addInfo` InfoVal (InChroot True) } + +newtype InChroot = InChroot Bool + deriving (Typeable, Show) diff --git a/src/Propellor/Property/Hostname.hs b/src/Propellor/Property/Hostname.hs index 78ec872f..8033bef8 100644 --- a/src/Propellor/Property/Hostname.hs +++ b/src/Propellor/Property/Hostname.hs @@ -2,13 +2,17 @@ module Propellor.Property.Hostname where import Propellor.Base import qualified Propellor.Property.File as File +import Propellor.Property.Chroot (inChroot) import Data.List import Data.List.Utils --- | Ensures that the hostname is set using best practices. +-- | Ensures that the hostname is set using best practices, to whatever +-- name the `Host` has. -- --- Configures </etc/hostname> and the current hostname. +-- Configures both </etc/hostname> and the current hostname. +-- (However, if used inside a chroot, avoids setting the current hostname +-- as that would impact the system outside the chroot.) -- -- Configures </etc/mailname> with the domain part of the hostname. -- @@ -25,6 +29,8 @@ sane' :: ExtractDomain -> Property NoInfo sane' extractdomain = property ("sane hostname") $ ensureProperty . setTo' extractdomain =<< asks hostName +-- Like `sane`, but you can specify the hostname to use, instead +-- of the default hostname of the `Host`. setTo :: HostName -> Property NoInfo setTo = setTo' extractDomain @@ -41,7 +47,8 @@ setTo' extractdomain hn = combineProperties desc go then Nothing else Just $ trivial $ hostsline "127.0.1.1" [hn, basehost] , Just $ trivial $ hostsline "127.0.0.1" ["localhost"] - , Just $ trivial $ cmdProperty "hostname" [basehost] + , Just $ trivial $ check (not <$> inChroot) $ + cmdProperty "hostname" [basehost] , Just $ "/etc/mailname" `File.hasContent` [if null domain then hn else domain] ] diff --git a/src/Propellor/Property/Systemd.hs b/src/Propellor/Property/Systemd.hs index 700bc350..8761d842 100644 --- a/src/Propellor/Property/Systemd.hs +++ b/src/Propellor/Property/Systemd.hs @@ -217,7 +217,7 @@ nspawned c@(Container name (Chroot.Chroot loc builder _) h) = -- Chroot provisioning is run in systemd-only mode, -- which sets up the chroot and ensures systemd and dbus are - -- installed, but does not handle the other provisions. + -- installed, but does not handle the other properties. chrootprovisioned = Chroot.provisioned' (Chroot.propagateChrootInfo chroot) chroot True -- Use nsenter to enter container and and run propellor to |
