propellor/src/Propellor/Property/Apache.hs

63 lines
1.9 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-14 18:09:41 +00:00
enable = trivial $ 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-14 18:09:41 +00:00
disable = trivial $ 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
2014-04-14 18:09:41 +00:00
enable = trivial $ 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
2014-04-14 18:09:41 +00:00
disable = trivial $ 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"
2014-04-14 01:04:34 +00:00
-- | Configure apache to use SNI to differentiate between
-- https hosts.
multiSSL :: Property
multiSSL = "/etc/apache2/conf.d/ssl" `File.hasContent`
[ "NameVirtualHost *:443"
, "SSLStrictSNIVHostCheck off"
]
`describe` "apache SNI enabled"
`onChange` reloaded