summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Prosody.hs
blob: e47b9ac56211437d5907edd8cd27a5e2bee81ddc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-- | Maintainer: Félix Sipma <felix+propellor@gueux.org>

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 = 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 NoInfo
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 NoInfo
installed = Apt.installed ["prosody"]

restarted :: Property NoInfo
restarted = Service.restarted "prosody"

reloaded :: Property NoInfo
reloaded = Service.reloaded "prosody"