summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Nginx.hs
diff options
context:
space:
mode:
authorJoey Hess2014-10-31 10:21:37 -0400
committerJoey Hess2014-10-31 10:21:37 -0400
commit43935ae7b06b44223cae4dc32613cd6751bc80f4 (patch)
tree424120ce08af0bce3f1409a31861daf84b40951a /src/Propellor/Property/Nginx.hs
parentb1c4ddff04b5571e7ec60e7bfb014db76fd48eae (diff)
parentca06c64bae82322348a07a97de924a1758a38b8f (diff)
Merge branch 'joeyconfig'
Conflicts: privdata/privdata.gpg
Diffstat (limited to 'src/Propellor/Property/Nginx.hs')
-rw-r--r--src/Propellor/Property/Nginx.hs47
1 files changed, 47 insertions, 0 deletions
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"