summaryrefslogtreecommitdiff
path: root/Propellor/Property/Apache.hs
blob: 81daf9e7582eb40d9a719d8af240de9fda6578c1 (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
module Propellor.Property.Apache where

import Propellor
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.Service as Service

type ConfigFile = [String]

siteEnabled :: HostName -> ConfigFile -> RevertableProperty
siteEnabled hn cf = RevertableProperty enable disable
  where
	enable = cmdProperty "a2ensite" ["--quiet", hn]
		`requires` siteAvailable hn cf
		`requires` installed
		`onChange` reloaded
	disable = File.notPresent (siteCfg hn)
		`onChange` cmdProperty "a2dissite" ["--quiet", hn]
		`requires` installed
		`onChange` reloaded

siteAvailable :: HostName -> ConfigFile -> Property
siteAvailable hn cf = siteCfg hn `File.hasContent` (comment:cf)
	`describe` ("apache site available " ++ hn)
  where
	comment = "# deployed with propellor, do not modify"

modEnabled :: String -> RevertableProperty
modEnabled modname = RevertableProperty enable disable
  where
	enable = cmdProperty "a2enmod" ["--quiet", modname]
		`requires` installed
		`onChange` reloaded
	disable = cmdProperty "a2dismod" ["--quiet", modname]
		`requires` installed
		`onChange` reloaded

siteCfg :: HostName -> FilePath
siteCfg hn = "/etc/apache2/sites-available/" ++ hn

installed :: Property
installed = Apt.installed ["apache2"]

restarted :: Property
restarted = cmdProperty "service" ["apache2", "restart"]

reloaded :: Property
reloaded = Service.reloaded "apache2"