diff options
Diffstat (limited to 'src/Propellor')
| -rw-r--r-- | src/Propellor/Property/SiteSpecific/JoeySites.hs | 67 | ||||
| -rw-r--r-- | src/Propellor/Property/Unbound.hs | 66 |
2 files changed, 103 insertions, 30 deletions
diff --git a/src/Propellor/Property/SiteSpecific/JoeySites.hs b/src/Propellor/Property/SiteSpecific/JoeySites.hs index 9d7423d7..1ce8204b 100644 --- a/src/Propellor/Property/SiteSpecific/JoeySites.hs +++ b/src/Propellor/Property/SiteSpecific/JoeySites.hs @@ -909,20 +909,23 @@ alarmClock oncalendar (User user) command = combineProperties "goodmorning timer & "/etc/systemd/logind.conf" `ConfFile.containsIniSetting` ("Login", "LidSwitchIgnoreInhibited", "no") --- My home power monitor. -homePowerMonitor :: IsContext c => User -> [Host] -> c -> (SshKeyType, Ssh.PubKeyText) -> Property (HasInfo + DebianLike) -homePowerMonitor user hosts ctx sshkey = propertyList "home power monitor" $ props +homePower :: IsContext c => User -> [Host] -> c -> (SshKeyType, Ssh.PubKeyText) -> Property (HasInfo + DebianLike) +homePower user hosts ctx sshkey = propertyList "home power" $ props & Apache.installed & Apt.installed ["python", "python-pymodbus", "rrdtool", "rsync"] & File.ownerGroup "/var/www/html" user (userGroup user) - & Git.cloned user "git://git.kitenet.net/joey/homepower" d Nothing - & buildpoller + & Git.cloned user "https://git.joeyh.name/git/joey/homepower.git" d Nothing + & Git.cloned user "https://git.joeyh.name/git/reactive-banana-automation.git" (d </> "reactive-banana-automation") Nothing + & build & Systemd.enabled setupservicename `requires` setupserviceinstalled `onChange` Systemd.started setupservicename - & Systemd.enabled servicename - `requires` serviceinstalled - `onChange` Systemd.started servicename + & Systemd.enabled pollerservicename + `requires` pollerserviceinstalled + `onChange` Systemd.started pollerservicename + & Systemd.enabled controllerservicename + `requires` controllerserviceinstalled + `onChange` Systemd.started controllerservicename & User.hasGroup user (Group "dialout") & Group.exists (Group "gpio") Nothing & User.hasGroup user (Group "gpio") @@ -936,23 +939,53 @@ homePowerMonitor user hosts ctx sshkey = propertyList "home power monitor" $ pro where d = "/var/www/html/homepower" sshkeyfile = d </> ".ssh/key" - buildpoller = userScriptProperty (User "joey") - [ "cd " ++ d + build = userScriptProperty (User "joey") + [ "cd " ++ d </> "reactive-banana-automation" + , "cabal install" + , "cd " ++ d , "make" ] `assume` MadeChange - `requires` Apt.installed ["ghc", "make"] - servicename = "homepower" - servicefile = "/etc/systemd/system/" ++ servicename ++ ".service" - serviceinstalled = servicefile `File.hasContent` + `requires` Apt.installed + [ "ghc", "cabal-install", "make" + , "libghc-http-types-dev" + , "libghc-stm-dev" + , "libghc-aeson-dev" + , "libghc-wai-dev" + , "libghc-warp-dev" + , "libghc-http-client-dev" + , "libghc-reactive-banana-dev" + , "libghc-hinotify-dev" + ] + pollerservicename = "homepower" + pollerservicefile = "/etc/systemd/system/" ++ pollerservicename ++ ".service" + pollerserviceinstalled = pollerservicefile `File.hasContent` [ "[Unit]" - , "Description=home power monitor" + , "Description=home power poller" , "" , "[Service]" , "ExecStart=" ++ d ++ "/poller" , "WorkingDirectory=" ++ d , "User=joey" , "Group=joey" + , "Restart=always" + , "" + , "[Install]" + , "WantedBy=multi-user.target" + , "WantedBy=homepower-controller.target" + ] + controllerservicename = "homepower-controller" + controllerservicefile = "/etc/systemd/system/" ++ controllerservicename ++ ".service" + controllerserviceinstalled = controllerservicefile `File.hasContent` + [ "[Unit]" + , "Description=home power controller" + , "" + , "[Service]" + , "ExecStart=" ++ d ++ "/controller" + , "WorkingDirectory=" ++ d + , "User=joey" + , "Group=joey" + , "Restart=always" , "" , "[Install]" , "WantedBy=multi-user.target" @@ -1007,7 +1040,9 @@ homeRouter = propertyList "home router" $ props , "bogus-priv" , "interface=wlan0" , "domain=kitenet.net" - , "dhcp-range=10.1.1.100,10.1.1.150,24h" + -- lease time is short because the homepower + -- controller wants to know when clients disconnect + , "dhcp-range=10.1.1.100,10.1.1.150,5m" , "no-hosts" , "address=/honeybee.kitenet.net/10.1.1.1" , "address=/house.kitenet.net/10.1.1.1" diff --git a/src/Propellor/Property/Unbound.hs b/src/Propellor/Property/Unbound.hs index 470aad7e..ec8b6d83 100644 --- a/src/Propellor/Property/Unbound.hs +++ b/src/Propellor/Property/Unbound.hs @@ -64,6 +64,10 @@ config = "/etc/unbound/unbound.conf.d/propellor.conf" -- | Provided a [UnboundSection], a [UnboundZone] and a [UnboundHost], -- cachingDnsServer ensure unbound is configured accordingly. -- +-- Be carefull with CNAMEs, unbound is not a primary DNS server, so it will +-- resolve these by itself. For a locally served zone, you probably want A/AAAA +-- records instead. +-- -- Example property: -- -- > cachingDnsServer @@ -115,13 +119,47 @@ genRecord' dom r = " local-data: \"" ++ fromMaybe "" (genRecord dom r) ++ "\" genRecord :: BindDomain -> Record -> Maybe String genRecord dom (Address addr) = Just $ genAddressNoTtl dom addr -genRecord dom (MX priority dest) = Just $ genMX dom priority dest -genRecord dom (PTR revip) = Just $ genPTR dom revip -genRecord _ (CNAME _) = Nothing -genRecord _ (NS _) = Nothing -genRecord _ (TXT _) = Nothing -genRecord _ (SRV _ _ _ _) = Nothing -genRecord _ (SSHFP _ _ _) = Nothing +genRecord dom (MX priority dest) = Just $ unwords + [ dValue dom + , "MX" + , val priority + , dValue dest + ] +genRecord dom (PTR revip) = Just $ unwords + [ revip ++ "." + , "PTR" + , dValue dom + ] +genRecord dom (CNAME dest) = Just $ unwords + [ dValue dom + , "CNAME" + , dValue dest + ] +genRecord dom (NS serv) = Just $ unwords + [ dValue dom + , "NS" + , dValue serv + ] +genRecord dom (TXT txt) = Just $ unwords + [ dValue dom + , "TXT" + , txt + ] +genRecord dom (SRV priority weight port target) = Just $ unwords + [ dValue dom + , "SRV" + , val priority + , val weight + , val port + , dValue target + ] +genRecord dom (SSHFP algo hash fingerprint) = Just $ unwords + [ dValue dom + , "SSHFP" + , val algo + , val hash + , fingerprint + ] genRecord _ (INCLUDE _) = Nothing genAddressNoTtl :: BindDomain -> IPAddr -> String @@ -133,10 +171,10 @@ genAddress dom ttl addr = case addr of IPv6 _ -> genAddress' "AAAA" dom ttl addr genAddress' :: String -> BindDomain -> Maybe Int -> IPAddr -> String -genAddress' recordtype dom ttl addr = dValue dom ++ " " ++ maybe "" (\ttl' -> val ttl' ++ " ") ttl ++ "IN " ++ recordtype ++ " " ++ val addr - -genMX :: BindDomain -> Int -> BindDomain -> String -genMX dom priority dest = dValue dom ++ " " ++ "MX" ++ " " ++ val priority ++ " " ++ dValue dest - -genPTR :: BindDomain -> ReverseIP -> String -genPTR dom revip = revip ++ ". " ++ "PTR" ++ " " ++ dValue dom +genAddress' recordtype dom ttl addr = unwords $ + [ dValue dom ] + ++ maybe [] (\ttl' -> [val ttl']) ttl ++ + [ "IN" + , recordtype + , val addr + ] |
