blob: a8c7b187fd5c45d7d00e36c3db379fc9e689d8c7 (
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.Nginx 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]
siteEnabled :: HostName -> ConfigFile -> RevertableProperty
siteEnabled hn cf = enable <!> disable
where
enable = check test prop
`describe` ("nginx site enabled " ++ hn)
`requires` siteAvailable hn cf
`requires` installed
`onChange` reloaded
where
test = not <$> doesFileExist (siteVal hn)
prop = property "nginx site in place" $ makeChange $
createSymbolicLink target dir
target = siteValRelativeCfg hn
dir = siteVal hn
disable = trivial $ File.notPresent (siteVal hn)
`describe` ("nginx site disable" ++ hn)
`requires` installed
`onChange` reloaded
siteAvailable :: HostName -> ConfigFile -> Property NoInfo
siteAvailable hn cf = ("nginx site available " ++ hn) ==>
siteCfg hn `File.hasContent` (comment : cf)
where
comment = "# deployed with propellor, do not modify"
siteCfg :: HostName -> FilePath
siteCfg hn = "/etc/nginx/sites-available/" ++ hn
siteVal :: HostName -> FilePath
siteVal hn = "/etc/nginx/sites-enabled/" ++ hn
siteValRelativeCfg :: HostName -> FilePath
siteValRelativeCfg hn = "../sites-available/" ++ hn
installed :: Property NoInfo
installed = Apt.installed ["nginx"]
restarted :: Property NoInfo
restarted = Service.restarted "nginx"
reloaded :: Property NoInfo
reloaded = Service.reloaded "nginx"
|