summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Uwsgi.hs
blob: b1b567b40c106a031fdc7405e6331427070ee979 (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.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"