propellor/Propellor/Property/Apache.hs

53 lines
1.6 KiB
Haskell
Raw Normal View History

2014-04-13 18:01:30 +00:00
module Propellor.Property.Apache where
import Propellor
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Apt as Apt
2014-04-13 18:36:19 +00:00
import qualified Propellor.Property.Service as Service
2014-04-13 18:01:30 +00:00
type ConfigFile = [String]
siteEnabled :: HostName -> ConfigFile -> RevertableProperty
siteEnabled hn cf = RevertableProperty enable disable
where
2014-04-13 18:36:19 +00:00
enable = cmdProperty "a2ensite" ["--quiet", hn]
2014-04-13 21:50:44 +00:00
`describe` ("apache site enabled " ++ hn)
2014-04-13 18:36:19 +00:00
`requires` siteAvailable hn cf
`requires` installed
`onChange` reloaded
2014-04-13 18:01:30 +00:00
disable = File.notPresent (siteCfg hn)
2014-04-13 21:50:44 +00:00
`describe` ("apache site disabled " ++ hn)
2014-04-13 18:01:30 +00:00
`onChange` cmdProperty "a2dissite" ["--quiet", hn]
2014-04-13 18:36:19 +00:00
`requires` installed
`onChange` reloaded
2014-04-13 18:01:30 +00:00
siteAvailable :: HostName -> ConfigFile -> Property
siteAvailable hn cf = siteCfg hn `File.hasContent` (comment:cf)
`describe` ("apache site available " ++ hn)
where
comment = "# deployed with propellor, do not modify"
2014-04-13 18:36:19 +00:00
modEnabled :: String -> RevertableProperty
modEnabled modname = RevertableProperty enable disable
where
enable = cmdProperty "a2enmod" ["--quiet", modname]
2014-04-13 21:50:44 +00:00
`describe` ("apache module enabled " ++ modname)
2014-04-13 18:36:19 +00:00
`requires` installed
`onChange` reloaded
disable = cmdProperty "a2dismod" ["--quiet", modname]
2014-04-13 21:50:44 +00:00
`describe` ("apache module disabled " ++ modname)
2014-04-13 18:36:19 +00:00
`requires` installed
`onChange` reloaded
2014-04-13 18:01:30 +00:00
siteCfg :: HostName -> FilePath
2014-04-13 18:36:19 +00:00
siteCfg hn = "/etc/apache2/sites-available/" ++ hn
installed :: Property
installed = Apt.installed ["apache2"]
restarted :: Property
restarted = cmdProperty "service" ["apache2", "restart"]
2014-04-13 18:01:30 +00:00
2014-04-13 18:36:19 +00:00
reloaded :: Property
reloaded = Service.reloaded "apache2"