summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Uwsgi.hs
diff options
context:
space:
mode:
authorFélix Sipma2015-10-08 08:56:32 +0200
committerJoey Hess2015-10-08 11:08:49 -0400
commitb0e04b51324417e1c7f30c1c9526288fc288f186 (patch)
treec54aca4e7d4fe177d468507a93405e7073acc1c1 /src/Propellor/Property/Uwsgi.hs
parent660a480e8144946847257021f0a667b35ac62397 (diff)
add basic Uwsgi module
Signed-off-by: Félix Sipma <felix.sipma@no-log.org>
Diffstat (limited to 'src/Propellor/Property/Uwsgi.hs')
-rw-r--r--src/Propellor/Property/Uwsgi.hs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/Propellor/Property/Uwsgi.hs b/src/Propellor/Property/Uwsgi.hs
new file mode 100644
index 00000000..b1b567b4
--- /dev/null
+++ b/src/Propellor/Property/Uwsgi.hs
@@ -0,0 +1,54 @@
+-- | Maintainer: Félix Sipma <felix+propellor@gueux.org>
+
+module Propellor.Property.Uwsgi 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]
+
+appEnabled :: HostName -> ConfigFile -> RevertableProperty
+appEnabled hn cf = enable <!> disable
+ where
+ enable = check test prop
+ `describe` ("uwsgi app enabled " ++ hn)
+ `requires` appAvailable hn cf
+ `requires` installed
+ `onChange` reloaded
+ where
+ test = not <$> doesFileExist (appVal hn)
+ prop = property "uwsgi app in place" $ makeChange $
+ createSymbolicLink target dir
+ target = appValRelativeCfg hn
+ dir = appVal hn
+ disable = trivial $ File.notPresent (appVal hn)
+ `describe` ("uwsgi app disable" ++ hn)
+ `requires` installed
+ `onChange` reloaded
+
+appAvailable :: HostName -> ConfigFile -> Property NoInfo
+appAvailable hn cf = ("uwsgi app available " ++ hn) ==>
+ appCfg hn `File.hasContent` (comment : cf)
+ where
+ comment = "# deployed with propellor, do not modify"
+
+appCfg :: HostName -> FilePath
+appCfg hn = "/etc/uwsgi/apps-available/" ++ hn
+
+appVal :: HostName -> FilePath
+appVal hn = "/etc/uwsgi/apps-enabled/" ++ hn
+
+appValRelativeCfg :: HostName -> FilePath
+appValRelativeCfg hn = "../apps-available/" ++ hn
+
+installed :: Property NoInfo
+installed = Apt.installed ["uwsgi"]
+
+restarted :: Property NoInfo
+restarted = Service.restarted "uwsgi"
+
+reloaded :: Property NoInfo
+reloaded = Service.reloaded "uwsgi"