module Propellor.Property.Nginx where
import Propellor.Base
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.Service as Service
type ConfigFile = [String]
siteEnabled :: HostName -> ConfigFile -> RevertableProperty DebianLike DebianLike
siteEnabled :: HostName
-> ConfigFile
-> RevertableProperty
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
siteEnabled HostName
hn ConfigFile
cf = Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
enable Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
-> Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
-> RevertableProperty
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
forall setupmetatypes undometatypes.
Property setupmetatypes
-> Property undometatypes
-> RevertableProperty setupmetatypes undometatypes
<!> Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
disable
where
enable :: CombinedType
(Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]))
(Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]))
enable = HostName -> HostName
siteVal HostName
hn HostName -> LinkTarget -> RevertableProperty UnixLike UnixLike
`File.isSymlinkedTo` HostName -> LinkTarget
siteValRelativeCfg HostName
hn
RevertableProperty UnixLike UnixLike
-> HostName -> RevertableProperty UnixLike UnixLike
forall p. IsProp p => p -> HostName -> p
`describe` (HostName
"nginx site enabled " HostName -> HostName -> HostName
forall a. [a] -> [a] -> [a]
++ HostName
hn)
RevertableProperty UnixLike UnixLike
-> Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
-> CombinedType
(RevertableProperty UnixLike UnixLike)
(Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]))
forall x y. Combines x y => x -> y -> CombinedType x y
`requires` HostName
-> ConfigFile
-> Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
siteAvailable HostName
hn ConfigFile
cf
Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
-> Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
-> CombinedType
(Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]))
(Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]))
forall x y. Combines x y => x -> y -> CombinedType x y
`requires` Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
installed
Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
-> Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
-> CombinedType
(Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]))
(Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]))
forall x y. Combines x y => x -> y -> CombinedType x y
`onChange` Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
reloaded
disable :: CombinedType
(Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]))
(Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]))
disable = HostName -> Property UnixLike
File.notPresent (HostName -> HostName
siteVal HostName
hn)
Property UnixLike -> HostName -> Property UnixLike
forall p. IsProp p => p -> HostName -> p
`describe` (HostName
"nginx site disable" HostName -> HostName -> HostName
forall a. [a] -> [a] -> [a]
++ HostName
hn)
Property UnixLike
-> Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
-> CombinedType
(Property UnixLike)
(Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]))
forall x y. Combines x y => x -> y -> CombinedType x y
`requires` Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
installed
Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
-> Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
-> CombinedType
(Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]))
(Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish]))
forall x y. Combines x y => x -> y -> CombinedType x y
`onChange` Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
reloaded
siteAvailable :: HostName -> ConfigFile -> Property DebianLike
siteAvailable :: HostName
-> ConfigFile
-> Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
siteAvailable HostName
hn ConfigFile
cf = HostName
"nginx site available " HostName -> HostName -> HostName
forall a. [a] -> [a] -> [a]
++ HostName
hn HostName
-> Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
-> Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
forall i.
IsProp (Property i) =>
HostName -> Property i -> Property i
==> Property UnixLike
-> Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
forall (p :: * -> *) (untightened :: [MetaType])
(tightened :: [MetaType]).
(TightenTargets p, TightenTargetsAllowed untightened tightened,
SingI tightened) =>
p (MetaTypes untightened) -> p (MetaTypes tightened)
tightenTargets Property UnixLike
go
where
comment :: HostName
comment = HostName
"# deployed with propellor, do not modify"
go :: Property UnixLike
go = HostName -> HostName
siteCfg HostName
hn HostName -> ConfigFile -> Property UnixLike
`File.hasContent` (HostName
comment HostName -> ConfigFile -> ConfigFile
forall a. a -> [a] -> [a]
: ConfigFile
cf)
siteCfg :: HostName -> FilePath
siteCfg :: HostName -> HostName
siteCfg HostName
hn = HostName
"/etc/nginx/sites-available/" HostName -> HostName -> HostName
forall a. [a] -> [a] -> [a]
++ HostName
hn
siteVal :: HostName -> FilePath
siteVal :: HostName -> HostName
siteVal HostName
hn = HostName
"/etc/nginx/sites-enabled/" HostName -> HostName -> HostName
forall a. [a] -> [a] -> [a]
++ HostName
hn
siteValRelativeCfg :: HostName -> File.LinkTarget
siteValRelativeCfg :: HostName -> LinkTarget
siteValRelativeCfg HostName
hn = HostName -> LinkTarget
File.LinkTarget (HostName
"../sites-available/" HostName -> HostName -> HostName
forall a. [a] -> [a] -> [a]
++ HostName
hn)
installed :: Property DebianLike
installed :: Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
installed = ConfigFile
-> Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
Apt.installed [HostName
"nginx"]
restarted :: Property DebianLike
restarted :: Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
restarted = HostName
-> Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
Service.restarted HostName
"nginx"
reloaded :: Property DebianLike
reloaded :: Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
reloaded = HostName
-> Property
(MetaTypes '[ 'Targeting 'OSDebian, 'Targeting 'OSBuntish])
Service.reloaded HostName
"nginx"