use HostAttr to simplify config file
This commit is contained in:
parent
25942fb0cc
commit
2372d6a3f8
|
@ -40,36 +40,40 @@ installed = Apt.installed ["docker.io"]
|
||||||
-- removed.
|
-- removed.
|
||||||
docked
|
docked
|
||||||
:: (HostName -> ContainerName -> Maybe (Container))
|
:: (HostName -> ContainerName -> Maybe (Container))
|
||||||
-> HostName
|
|
||||||
-> ContainerName
|
-> ContainerName
|
||||||
-> RevertableProperty
|
-> RevertableProperty
|
||||||
docked findc hn cn = findContainer findc hn cn $
|
docked findc cn = RevertableProperty (go "docked" setup) (go "undocked" teardown)
|
||||||
\(Container image containerprops) ->
|
where
|
||||||
let setup = provisionContainer cid
|
go desc a = Property (desc ++ " " ++ cn) $ do
|
||||||
`requires`
|
hn <- getHostName
|
||||||
runningContainer cid image containerprops
|
let cid = ContainerId hn cn
|
||||||
`requires`
|
ensureProperties [findContainer findc hn cn $ a cid]
|
||||||
installed
|
|
||||||
teardown = combineProperties ("undocked " ++ fromContainerId cid)
|
setup cid (Container image containerprops) =
|
||||||
[ stoppedContainer cid
|
provisionContainer cid
|
||||||
|
`requires`
|
||||||
|
runningContainer cid image containerprops
|
||||||
|
`requires`
|
||||||
|
installed
|
||||||
|
|
||||||
|
teardown cid (Container image _) =
|
||||||
|
combineProperties ("undocked " ++ fromContainerId cid)
|
||||||
|
[ stoppedContainer cid
|
||||||
, Property ("cleaned up " ++ fromContainerId cid) $
|
, Property ("cleaned up " ++ fromContainerId cid) $
|
||||||
liftIO $ report <$> mapM id
|
liftIO $ report <$> mapM id
|
||||||
[ removeContainer cid
|
[ removeContainer cid
|
||||||
, removeImage image
|
, removeImage image
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
in RevertableProperty setup teardown
|
|
||||||
where
|
|
||||||
cid = ContainerId hn cn
|
|
||||||
|
|
||||||
findContainer
|
findContainer
|
||||||
:: (HostName -> ContainerName -> Maybe (Container))
|
:: (HostName -> ContainerName -> Maybe (Container))
|
||||||
-> HostName
|
-> HostName
|
||||||
-> ContainerName
|
-> ContainerName
|
||||||
-> (Container -> RevertableProperty)
|
-> (Container -> Property)
|
||||||
-> RevertableProperty
|
-> Property
|
||||||
findContainer findc hn cn mk = case findc hn cn of
|
findContainer findc hn cn mk = case findc hn cn of
|
||||||
Nothing -> RevertableProperty cantfind cantfind
|
Nothing -> cantfind
|
||||||
Just container -> mk container
|
Just container -> mk container
|
||||||
where
|
where
|
||||||
cid = ContainerId hn cn
|
cid = ContainerId hn cn
|
||||||
|
|
|
@ -3,14 +3,17 @@ module Propellor.Property.Hostname where
|
||||||
import Propellor
|
import Propellor
|
||||||
import qualified Propellor.Property.File as File
|
import qualified Propellor.Property.File as File
|
||||||
|
|
||||||
-- | Sets the hostname. Configures both /etc/hostname and the current
|
-- | Ensures that the hostname is set to the HostAttr value.
|
||||||
-- hostname.
|
-- Configures both /etc/hostname and the current hostname.
|
||||||
--
|
--
|
||||||
-- When provided with a FQDN, also configures /etc/hosts,
|
-- When the hostname is a FQDN, also configures /etc/hosts,
|
||||||
-- with an entry for 127.0.1.1, which is standard at least on Debian
|
-- with an entry for 127.0.1.1, which is standard at least on Debian
|
||||||
-- to set the FDQN (127.0.0.1 is localhost).
|
-- to set the FDQN (127.0.0.1 is localhost).
|
||||||
set :: HostName -> Property
|
sane :: Property
|
||||||
set hostname = combineProperties desc go
|
sane = Property ("sane hostname") (ensureProperty . setTo =<< getHostName)
|
||||||
|
|
||||||
|
setTo :: HostName -> Property
|
||||||
|
setTo hostname = combineProperties desc go
|
||||||
`onChange` cmdProperty "hostname" [host]
|
`onChange` cmdProperty "hostname" [host]
|
||||||
where
|
where
|
||||||
desc = "hostname " ++ hostname
|
desc = "hostname " ++ hostname
|
||||||
|
|
|
@ -27,7 +27,7 @@ data RevertableProperty = RevertableProperty Property Property
|
||||||
|
|
||||||
-- | Propellor's monad provides read-only access to attributes of the
|
-- | Propellor's monad provides read-only access to attributes of the
|
||||||
-- system.
|
-- system.
|
||||||
newtype Propellor a = Propellor { runWithHostAttr :: ReaderT HostAttr IO a }
|
newtype Propellor p = Propellor { runWithHostAttr :: ReaderT HostAttr IO p }
|
||||||
deriving
|
deriving
|
||||||
( Monad
|
( Monad
|
||||||
, Functor
|
, Functor
|
||||||
|
|
|
@ -32,35 +32,35 @@ main = defaultMain [host, Docker.containerProperties container]
|
||||||
-- Edit this to configure propellor!
|
-- Edit this to configure propellor!
|
||||||
host :: HostName -> Maybe [Property]
|
host :: HostName -> Maybe [Property]
|
||||||
-- Clam is a tor bridge, and an olduse.net shellbox and other fun stuff.
|
-- Clam is a tor bridge, and an olduse.net shellbox and other fun stuff.
|
||||||
host hostname@"clam.kitenet.net" = Just $ withSystemd $ props
|
host "clam.kitenet.net" = Just $ withSystemd $ props
|
||||||
& cleanCloudAtCost hostname
|
& cleanCloudAtCost
|
||||||
& standardSystem Unstable
|
& standardSystem Unstable
|
||||||
& Apt.unattendedUpgrades
|
& Apt.unattendedUpgrades
|
||||||
& Network.ipv6to4
|
& Network.ipv6to4
|
||||||
& Apt.installed ["git-annex", "mtr"]
|
& Apt.installed ["git-annex", "mtr"]
|
||||||
& Tor.isBridge
|
& Tor.isBridge
|
||||||
& JoeySites.oldUseNetshellBox
|
& JoeySites.oldUseNetshellBox
|
||||||
& Docker.docked container hostname "openid-provider"
|
& Docker.docked container "openid-provider"
|
||||||
`requires` Apt.installed ["ntp"]
|
`requires` Apt.installed ["ntp"]
|
||||||
& Docker.docked container hostname "ancient-kitenet"
|
& Docker.docked container "ancient-kitenet"
|
||||||
& Docker.configured
|
& Docker.configured
|
||||||
& Docker.garbageCollected `period` Daily
|
& Docker.garbageCollected `period` Daily
|
||||||
-- Orca is the main git-annex build box.
|
-- Orca is the main git-annex build box.
|
||||||
host hostname@"orca.kitenet.net" = Just $ props -- no systemd due to #726375
|
host "orca.kitenet.net" = Just $ props -- no systemd due to #726375
|
||||||
& standardSystem Unstable
|
& standardSystem Unstable
|
||||||
& Hostname.set hostname
|
& Hostname.sane
|
||||||
& Apt.unattendedUpgrades
|
& Apt.unattendedUpgrades
|
||||||
& Docker.configured
|
& Docker.configured
|
||||||
& Apt.buildDep ["git-annex"] `period` Daily
|
& Apt.buildDep ["git-annex"] `period` Daily
|
||||||
& Docker.docked container hostname "amd64-git-annex-builder"
|
& Docker.docked container "amd64-git-annex-builder"
|
||||||
& Docker.docked container hostname "i386-git-annex-builder"
|
& Docker.docked container "i386-git-annex-builder"
|
||||||
! Docker.docked container hostname "armel-git-annex-builder-companion"
|
! Docker.docked container "armel-git-annex-builder-companion"
|
||||||
! Docker.docked container hostname "armel-git-annex-builder"
|
! Docker.docked container "armel-git-annex-builder"
|
||||||
& Docker.garbageCollected `period` Daily
|
& Docker.garbageCollected `period` Daily
|
||||||
-- Diatom is my downloads and git repos server, and secondary dns server.
|
-- Diatom is my downloads and git repos server, and secondary dns server.
|
||||||
host hostname@"diatom.kitenet.net" = Just $ props
|
host "diatom.kitenet.net" = Just $ props
|
||||||
& standardSystem Stable
|
& standardSystem Stable
|
||||||
& Hostname.set hostname
|
& Hostname.sane
|
||||||
& Apt.unattendedUpgrades
|
& Apt.unattendedUpgrades
|
||||||
& Apt.serviceInstalledRunning "ntp"
|
& Apt.serviceInstalledRunning "ntp"
|
||||||
& Dns.zones myDnsSecondary
|
& Dns.zones myDnsSecondary
|
||||||
|
@ -78,7 +78,7 @@ host hostname@"diatom.kitenet.net" = Just $ props
|
||||||
-- gitweb
|
-- gitweb
|
||||||
-- downloads.kitenet.net setup (including ssh key to turtle)
|
-- downloads.kitenet.net setup (including ssh key to turtle)
|
||||||
-- My laptop
|
-- My laptop
|
||||||
host _hostname@"darkstar.kitenet.net" = Just $ props
|
host "darkstar.kitenet.net" = Just $ props
|
||||||
& Docker.configured
|
& Docker.configured
|
||||||
& Apt.buildDep ["git-annex"] `period` Daily
|
& Apt.buildDep ["git-annex"] `period` Daily
|
||||||
|
|
||||||
|
@ -192,9 +192,9 @@ standardContainer suite arch ps = Docker.containerFrom
|
||||||
] ++ ps
|
] ++ ps
|
||||||
|
|
||||||
-- Clean up a system as installed by cloudatcost.com
|
-- Clean up a system as installed by cloudatcost.com
|
||||||
cleanCloudAtCost :: HostName -> Property
|
cleanCloudAtCost :: Property
|
||||||
cleanCloudAtCost hostname = propertyList "cloudatcost cleanup"
|
cleanCloudAtCost = propertyList "cloudatcost cleanup"
|
||||||
[ Hostname.set hostname
|
[ Hostname.sane
|
||||||
, Ssh.uniqueHostKeys
|
, Ssh.uniqueHostKeys
|
||||||
, "worked around grub/lvm boot bug #743126" ==>
|
, "worked around grub/lvm boot bug #743126" ==>
|
||||||
"/etc/default/grub" `File.containsLine` "GRUB_DISABLE_LINUX_UUID=true"
|
"/etc/default/grub" `File.containsLine` "GRUB_DISABLE_LINUX_UUID=true"
|
||||||
|
|
|
@ -25,7 +25,7 @@ main = defaultMain [host, Docker.containerProperties container]
|
||||||
--
|
--
|
||||||
-- Edit this to configure propellor!
|
-- Edit this to configure propellor!
|
||||||
host :: HostName -> Maybe [Property]
|
host :: HostName -> Maybe [Property]
|
||||||
host hostname@"mybox.example.com" = Just $ props
|
host "mybox.example.com" = Just $ props
|
||||||
& Apt.stdSourcesList Unstable
|
& Apt.stdSourcesList Unstable
|
||||||
`onChange` Apt.upgrade
|
`onChange` Apt.upgrade
|
||||||
& Apt.unattendedUpgrades
|
& Apt.unattendedUpgrades
|
||||||
|
@ -34,7 +34,7 @@ host hostname@"mybox.example.com" = Just $ props
|
||||||
& User.hasSomePassword "root"
|
& User.hasSomePassword "root"
|
||||||
& Network.ipv6to4
|
& Network.ipv6to4
|
||||||
& File.dirExists "/var/www"
|
& File.dirExists "/var/www"
|
||||||
& Docker.docked container hostname "webserver"
|
& Docker.docked container "webserver"
|
||||||
& Docker.garbageCollected `period` Daily
|
& Docker.garbageCollected `period` Daily
|
||||||
& Cron.runPropellor "30 * * * *"
|
& Cron.runPropellor "30 * * * *"
|
||||||
-- add more hosts here...
|
-- add more hosts here...
|
||||||
|
|
Loading…
Reference in New Issue