diff options
author | FĂ©lix Sipma <gueux@gueux.org> | 2014-10-30 21:10:23 +0100 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-10-30 16:34:01 -0400 |
commit | a6e712a6457638a3ea8c653357d06fd4fbb3d5f3 (patch) | |
tree | 929bb86271968d3325c97553ce70e995e459c181 | |
parent | 4fc7142b0fb32359ebaaaaf3978a4f4ba4db90a9 (diff) |
basic nginx support
-rw-r--r-- | propellor.cabal | 1 | ||||
-rw-r--r-- | src/Propellor/Property/Nginx.hs | 47 |
2 files changed, 48 insertions, 0 deletions
diff --git a/propellor.cabal b/propellor.cabal index 282a5e04..c63bed37 100644 --- a/propellor.cabal +++ b/propellor.cabal @@ -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 diff --git a/src/Propellor/Property/Nginx.hs b/src/Propellor/Property/Nginx.hs new file mode 100644 index 00000000..97792fcc --- /dev/null +++ b/src/Propellor/Property/Nginx.hs @@ -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" |