From b0e04b51324417e1c7f30c1c9526288fc288f186 Mon Sep 17 00:00:00 2001 From: Félix Sipma Date: Thu, 8 Oct 2015 08:56:32 +0200 Subject: add basic Uwsgi module Signed-off-by: Félix Sipma --- src/Propellor/Property/Uwsgi.hs | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/Propellor/Property/Uwsgi.hs (limited to 'src/Propellor') 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 + +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" -- cgit v1.2.3 From 886053fa9736b7c61b34edfa5367349b43de8d7b Mon Sep 17 00:00:00 2001 From: Félix Sipma Date: Thu, 8 Oct 2015 11:47:16 +0200 Subject: Uwsgi: replace HostName by AppName Signed-off-by: Félix Sipma --- src/Propellor/Property/Uwsgi.hs | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'src/Propellor') diff --git a/src/Propellor/Property/Uwsgi.hs b/src/Propellor/Property/Uwsgi.hs index b1b567b4..d1cdb550 100644 --- a/src/Propellor/Property/Uwsgi.hs +++ b/src/Propellor/Property/Uwsgi.hs @@ -10,39 +10,41 @@ import System.Posix.Files type ConfigFile = [String] -appEnabled :: HostName -> ConfigFile -> RevertableProperty -appEnabled hn cf = enable disable +type AppName = String + +appEnabled :: AppName -> ConfigFile -> RevertableProperty +appEnabled an cf = enable disable where enable = check test prop - `describe` ("uwsgi app enabled " ++ hn) - `requires` appAvailable hn cf + `describe` ("uwsgi app enabled " ++ an) + `requires` appAvailable an cf `requires` installed `onChange` reloaded where - test = not <$> doesFileExist (appVal hn) + test = not <$> doesFileExist (appVal an) 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) + target = appValRelativeCfg an + dir = appVal an + disable = trivial $ File.notPresent (appVal an) + `describe` ("uwsgi app disable" ++ an) `requires` installed `onChange` reloaded -appAvailable :: HostName -> ConfigFile -> Property NoInfo -appAvailable hn cf = ("uwsgi app available " ++ hn) ==> - appCfg hn `File.hasContent` (comment : cf) +appAvailable :: AppName -> ConfigFile -> Property NoInfo +appAvailable an cf = ("uwsgi app available " ++ an) ==> + appCfg an `File.hasContent` (comment : cf) where comment = "# deployed with propellor, do not modify" -appCfg :: HostName -> FilePath -appCfg hn = "/etc/uwsgi/apps-available/" ++ hn +appCfg :: AppName -> FilePath +appCfg an = "/etc/uwsgi/apps-available/" ++ an -appVal :: HostName -> FilePath -appVal hn = "/etc/uwsgi/apps-enabled/" ++ hn +appVal :: AppName -> FilePath +appVal an = "/etc/uwsgi/apps-enabled/" ++ an -appValRelativeCfg :: HostName -> FilePath -appValRelativeCfg hn = "../apps-available/" ++ hn +appValRelativeCfg :: AppName -> FilePath +appValRelativeCfg an = "../apps-available/" ++ an installed :: Property NoInfo installed = Apt.installed ["uwsgi"] -- cgit v1.2.3 From c387c179da71cc378a40bcf00f8ac1399a17b18e Mon Sep 17 00:00:00 2001 From: Per Olofsson Date: Thu, 8 Oct 2015 13:18:17 +0200 Subject: Add Apt.hasForeignArch. Signed-off-by: Per Olofsson --- src/Propellor/Property/Apt.hs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/Propellor') diff --git a/src/Propellor/Property/Apt.hs b/src/Propellor/Property/Apt.hs index 2e913540..15c45629 100644 --- a/src/Propellor/Property/Apt.hs +++ b/src/Propellor/Property/Apt.hs @@ -297,3 +297,11 @@ aptKeyFile k = "/etc/apt/trusted.gpg.d" keyname k ++ ".gpg" cacheCleaned :: Property NoInfo cacheCleaned = trivial $ cmdProperty "apt-get" ["clean"] `describe` "apt cache cleaned" + +-- | Add a foreign architecture to dpkg and apt. +hasForeignArch :: String -> Property NoInfo +hasForeignArch arch = check notAdded add + `describe` ("dpkg has foreign architecture " ++ arch) + where + notAdded = (not . elem arch . lines) <$> readProcess "dpkg" ["--print-foreign-architectures"] + add = cmdProperty "dpkg" ["--add-architecture", arch] `before` update -- cgit v1.2.3