From 2222911ad5bf4db3fcd57818e8764b5bbb53979c Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sun, 2 Sep 2018 17:46:23 +0200 Subject: Nullmailer: handle nullmailer configuration --- propellor.cabal | 1 + src/Propellor/Property/Nullmailer.hs | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/Propellor/Property/Nullmailer.hs diff --git a/propellor.cabal b/propellor.cabal index 6c8c42e1..529996cd 100644 --- a/propellor.cabal +++ b/propellor.cabal @@ -109,6 +109,7 @@ Library Propellor.Property.Mount Propellor.Property.Network Propellor.Property.Nginx + Propellor.Property.Nullmailer Propellor.Property.Obnam Propellor.Property.OpenId Propellor.Property.Openssl diff --git a/src/Propellor/Property/Nullmailer.hs b/src/Propellor/Property/Nullmailer.hs new file mode 100644 index 00000000..fe03f5dd --- /dev/null +++ b/src/Propellor/Property/Nullmailer.hs @@ -0,0 +1,42 @@ +-- | Maintainer: Nicolas Schodet +-- +-- Support for Nullmailer. + +module Propellor.Property.Nullmailer ( + installed, + configured, + configured', +) where + +import Propellor +import Propellor.Base +import qualified Propellor.Property.Apt as Apt +import qualified Propellor.Property.File as File +import qualified Propellor.Property.Systemd as Systemd + +-- | Make sure needed tools are installed. +installed :: RevertableProperty DebianLike DebianLike +installed = install remove + where + install = Apt.installed packages + remove = Apt.removed packages + packages = ["nullmailer"] + +-- | Configure nullmailer using the hostname of the `Host`. +configured :: HostName -> String -> Property DebianLike +configured relayHost adminAddr = property' "nullmailer configured" $ \w -> + ensureProperty w . configured' relayHost adminAddr =<< asks hostName + +-- | Like configured, but allow to specify the hostname. +configured' :: HostName -> String -> HostName -> Property DebianLike +configured' relayHost adminAddr hn = + (setup `onChange` reload) `requires` installed + where + setup :: Property UnixLike + setup = combineProperties desc $ props + & config "defaulthost" hn + & config "adminaddr" adminAddr + & config "remotes" (relayHost ++ " smtp") + desc = "nullmailer configured" + config name value = File.hasContent ("/etc/nullmailer" name) [value] + reload = Systemd.restarted "nullmailer" -- cgit v1.2.3