basic nginx support

This commit is contained in:
Félix Sipma 2014-10-30 21:10:23 +01:00 committed by Joey Hess
parent 4fc7142b0f
commit a6e712a645
2 changed files with 48 additions and 0 deletions

View File

@ -82,6 +82,7 @@ Library
Propellor.Property.Gpg
Propellor.Property.Grub
Propellor.Property.Network
Propellor.Property.Nginx
Propellor.Property.Obnam
Propellor.Property.OpenId
Propellor.Property.Postfix

View File

@ -0,0 +1,47 @@
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
type ConfigFile = [String]
siteEnabled :: HostName -> ConfigFile -> RevertableProperty
siteEnabled hn cf = RevertableProperty enable disable
where
enable = trivial (cmdProperty "ln" ["-s", siteValRelativeCfg hn, siteVal hn])
`describe` ("nginx site enabled " ++ hn)
`requires` siteAvailable hn cf
`requires` installed
`onChange` reloaded
disable = trivial $
("nginx site disabled " ++ hn) ==>
File.notPresent (siteCfg hn)
`onChange` cmdProperty "rm" [siteVal hn]
`requires` installed
`onChange` reloaded
siteAvailable :: HostName -> ConfigFile -> Property
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
installed = Apt.installed ["nginx"]
restarted :: Property
restarted = Service.restarted "nginx"
reloaded :: Property
reloaded = Service.reloaded "nginx"