basic prosody support

Signed-off-by: Félix Sipma <felix.sipma@no-log.org>
This commit is contained in:
Félix Sipma 2014-11-10 11:13:06 +01:00 committed by Joey Hess
parent f3a31c9192
commit 3541260436
2 changed files with 57 additions and 4 deletions

View File

@ -36,11 +36,11 @@ Executable propellor
Main-Is: wrapper.hs
GHC-Options: -Wall -threaded -O0
Hs-Source-Dirs: src
Build-Depends: MissingH, directory, filepath, base >= 4.5, base < 5,
Build-Depends: MissingH, directory, filepath, base >= 4.5, base < 5,
IfElse, process, bytestring, hslogger, unix-compat, ansi-terminal,
containers, network, async, time, QuickCheck, mtl,
MonadCatchIO-transformers
if (! os(windows))
Build-Depends: unix
@ -48,7 +48,7 @@ Executable propellor-config
Main-Is: config.hs
GHC-Options: -Wall -threaded -O0
Hs-Source-Dirs: src
Build-Depends: MissingH, directory, filepath, base >= 4.5, base < 5,
Build-Depends: MissingH, directory, filepath, base >= 4.5, base < 5,
IfElse, process, bytestring, hslogger, unix-compat, ansi-terminal,
containers, network, async, time, QuickCheck, mtl,
MonadCatchIO-transformers
@ -59,7 +59,7 @@ Executable propellor-config
Library
GHC-Options: -Wall -O0
Hs-Source-Dirs: src
Build-Depends: MissingH, directory, filepath, base >= 4.5, base < 5,
Build-Depends: MissingH, directory, filepath, base >= 4.5, base < 5,
IfElse, process, bytestring, hslogger, unix-compat, ansi-terminal,
containers, network, async, time, QuickCheck, mtl,
MonadCatchIO-transformers
@ -87,6 +87,7 @@ Library
Propellor.Property.Obnam
Propellor.Property.OpenId
Propellor.Property.Postfix
Propellor.Property.Prosody
Propellor.Property.Reboot
Propellor.Property.Scheduled
Propellor.Property.Service

View File

@ -0,0 +1,52 @@
module Propellor.Property.Prosody where
import Propellor
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.Service as Service
import System.Posix.Files
type ConfigFile = [String]
type Conf = String
confEnabled :: Conf -> ConfigFile -> RevertableProperty
confEnabled conf cf = RevertableProperty enable disable
where
enable = check test prop
`describe` ("prosody conf enabled " ++ conf)
`requires` confAvailable conf cf
`requires` installed
`onChange` reloaded
where
test = not <$> doesFileExist (confValPath conf)
prop = property "prosody conf in place" $ makeChange $
createSymbolicLink target dir
target = confValRelativePath conf
dir = confValPath conf
confValRelativePath conf' = "../conf.avail" </> conf' <.> "cfg.lua"
disable = trivial $ File.notPresent (confValPath conf)
`describe` ("prosody conf disabled " ++ conf)
`requires` installed
`onChange` reloaded
confAvailable :: Conf -> ConfigFile -> Property
confAvailable conf cf = ("prosody conf available " ++ conf) ==>
confAvailPath conf `File.hasContent` (comment : cf)
where
comment = "-- deployed with propellor, do not modify"
confAvailPath :: Conf -> FilePath
confAvailPath conf = "/etc/prosody/conf.avail" </> conf <.> "cfg.lua"
confValPath :: Conf -> FilePath
confValPath conf = "/etc/prosody/conf.d" </> conf <.> "cfg.lua"
installed :: Property
installed = Apt.installed ["prosody"]
restarted :: Property
restarted = Service.restarted "prosody"
reloaded :: Property
reloaded = Service.reloaded "prosody"