Dns primary and secondary properties are now revertable.

This commit is contained in:
Joey Hess 2014-04-19 11:00:48 -04:00
parent 2279979d32
commit fffa3e003a
3 changed files with 33 additions and 16 deletions

View File

@ -39,11 +39,18 @@ import Data.List
-- The [(BindDomain, Record)] list can be used for additional records -- The [(BindDomain, Record)] list can be used for additional records
-- that cannot be configured elsewhere. For example, it might contain -- that cannot be configured elsewhere. For example, it might contain
-- CNAMEs pointing at hosts that propellor does not control. -- CNAMEs pointing at hosts that propellor does not control.
primary :: [Host] -> Domain -> SOA -> [(BindDomain, Record)] -> Property primary :: [Host] -> Domain -> SOA -> [(BindDomain, Record)] -> RevertableProperty
primary hosts domain soa rs = withwarnings (check needupdate baseprop) primary hosts domain soa rs = RevertableProperty setup cleanup
`requires` servingZones
`onChange` Service.reloaded "bind9"
where where
setup = withwarnings (check needupdate baseprop)
`requires` servingZones
`onChange` Service.reloaded "bind9"
cleanup = check (doesFileExist zonefile) $
property ("removed dns primary for " ++ domain)
(makeChange $ removeZoneFile zonefile)
`requires` namedConfWritten
`onChange` Service.reloaded "bind9"
(partialzone, warnings) = genZone hosts domain soa (partialzone, warnings) = genZone hosts domain soa
zone = partialzone { zHosts = zHosts partialzone ++ rs } zone = partialzone { zHosts = zHosts partialzone ++ rs }
zonefile = "/etc/bind/propellor/db." ++ domain zonefile = "/etc/bind/propellor/db." ++ domain
@ -77,7 +84,7 @@ primary hosts domain soa rs = withwarnings (check needupdate baseprop)
-- --
-- Note that if a host is declared to be a primary and a secondary dns -- Note that if a host is declared to be a primary and a secondary dns
-- server for the same domain, the primary server config always wins. -- server for the same domain, the primary server config always wins.
secondary :: [Host] -> Domain -> Property secondary :: [Host] -> Domain -> RevertableProperty
secondary hosts domain = secondaryFor masters hosts domain secondary hosts domain = secondaryFor masters hosts domain
where where
masters = M.keys $ M.filter ismaster $ hostAttrMap hosts masters = M.keys $ M.filter ismaster $ hostAttrMap hosts
@ -87,10 +94,13 @@ secondary hosts domain = secondaryFor masters hosts domain
-- | This variant is useful if the primary server does not have its DNS -- | This variant is useful if the primary server does not have its DNS
-- configured via propellor. -- configured via propellor.
secondaryFor :: [HostName] -> [Host] -> Domain -> Property secondaryFor :: [HostName] -> [Host] -> Domain -> RevertableProperty
secondaryFor masters hosts domain = pureAttrProperty desc (addNamedConf conf) secondaryFor masters hosts domain = RevertableProperty setup cleanup
`requires` servingZones
where where
setup = pureAttrProperty desc (addNamedConf conf)
`requires` servingZones
cleanup = namedConfWritten
desc = "dns secondary for " ++ domain desc = "dns secondary for " ++ domain
conf = NamedConf conf = NamedConf
{ confDomain = domain { confDomain = domain
@ -104,15 +114,16 @@ secondaryFor masters hosts domain = pureAttrProperty desc (addNamedConf conf)
-- configured by `primary` and `secondary`, and ensures that bind9 is -- configured by `primary` and `secondary`, and ensures that bind9 is
-- running. -- running.
servingZones :: Property servingZones :: Property
servingZones = property "serving configured dns zones" go servingZones = namedConfWritten
`requires` Apt.serviceInstalledRunning "bind9" `requires` Apt.serviceInstalledRunning "bind9"
`onChange` Service.reloaded "bind9" `onChange` Service.reloaded "bind9"
where
go = do namedConfWritten :: Property
zs <- getNamedConf namedConfWritten = property "named.conf configured" $ do
ensureProperty $ zs <- getNamedConf
hasContent namedConfFile $ ensureProperty $
concatMap confStanza $ M.elems zs hasContent namedConfFile $
concatMap confStanza $ M.elems zs
confStanza :: NamedConf -> [Line] confStanza :: NamedConf -> [Line]
confStanza c = confStanza c =
@ -223,6 +234,11 @@ writeZoneFile z f = do
writeFile f (genZoneFile z') writeFile f (genZoneFile z')
writeZonePropellorFile f z' writeZonePropellorFile f z'
removeZoneFile :: FilePath -> IO ()
removeZoneFile f = do
nukeFile f
nukeFile (zonePropellorFile f)
-- | Next to the zone file, is a ".propellor" file, which contains -- | Next to the zone file, is a ".propellor" file, which contains
-- the serialized Zone. This saves the bother of parsing -- the serialized Zone. This saves the bother of parsing
-- the horrible bind zone file format. -- the horrible bind zone file format.

View File

@ -245,7 +245,7 @@ cleanCloudAtCost = propertyList "cloudatcost cleanup"
] ]
myDnsSecondary :: Property myDnsSecondary :: Property
myDnsSecondary = propertyList "dns secondary for all my domains" myDnsSecondary = propertyList "dns secondary for all my domains" $ map toProp
[ Dns.secondaryFor wren hosts "kitenet.net" [ Dns.secondaryFor wren hosts "kitenet.net"
, Dns.secondaryFor wren hosts "joeyh.name" , Dns.secondaryFor wren hosts "joeyh.name"
, Dns.secondaryFor wren hosts "ikiwiki.info" , Dns.secondaryFor wren hosts "ikiwiki.info"

1
debian/changelog vendored
View File

@ -2,6 +2,7 @@ propellor (0.5.0) UNRELEASED; urgency=medium
* Removed root domain records from SOA. Instead, use RootDomain * Removed root domain records from SOA. Instead, use RootDomain
when calling Dns.primary. when calling Dns.primary.
* Dns primary and secondary properties are now revertable.
-- Joey Hess <joeyh@debian.org> Sat, 19 Apr 2014 10:46:35 -0400 -- Joey Hess <joeyh@debian.org> Sat, 19 Apr 2014 10:46:35 -0400