don't need RestartPolicy data type; simplify

This commit is contained in:
Joey Hess 2014-10-23 12:28:33 -04:00
parent 76ad306aae
commit f5b5159f76
1 changed files with 18 additions and 19 deletions

View File

@ -29,8 +29,9 @@ module Propellor.Property.Docker (
cpuShares, cpuShares,
link, link,
ContainerAlias, ContainerAlias,
restart, restartAlways,
RestartPolicy(..), restartOnFailure,
restartNever,
-- * Internal use -- * Internal use
chain, chain,
) where ) where
@ -157,7 +158,7 @@ mkContainer cid@(ContainerId hn _cn) h = Container
h' = h h' = h
-- Restart by default so container comes up on -- Restart by default so container comes up on
-- boot or when docker is upgraded. -- boot or when docker is upgraded.
&^ restart RestartAlways &^ restartAlways
-- Expose propellor directory inside the container. -- Expose propellor directory inside the container.
& volume (localdir++":"++localdir) & volume (localdir++":"++localdir)
-- Name the container in a predictable way so we -- Name the container in a predictable way so we
@ -279,26 +280,24 @@ link linkwith calias = genProp "link" $ \hn ->
-- Each container has its own alias namespace. -- Each container has its own alias namespace.
type ContainerAlias = String type ContainerAlias = String
-- | Restart policy to apply when a container exits. -- | This property is enabled by default for docker containers configured by
restart :: RestartPolicy -> Property
restart policy = runProp "restart" (serialize policy)
where
serialize NoRestart = "no"
serialize (RestartOnFailure Nothing) = "on-failure"
serialize (RestartOnFailure (Just n)) = "on-failure:" ++ show n
serialize RestartAlways = "always"
-- | RestartAlways is the default for docker containers configured by
-- propellor; as well as keeping badly behaved containers running, -- propellor; as well as keeping badly behaved containers running,
-- it ensures that containers get started back up after reboot or -- it ensures that containers get started back up after reboot or
-- after docker is upgraded. -- after docker is upgraded.
-- restartAlways :: Property
-- NoRestart makes docker not restart a container when it exits restartAlways = runProp "restart" "always"
-- | Docker will restart the container if it exits nonzero.
-- If a number is provided, it will be restarted only up to that many
-- times.
restartOnFailure :: Maybe Int -> Property
restartOnFailure Nothing = runProp "restart" "on-failure"
restartOnFailure (Just n) = runProp "restart" ("on-failure:" ++ show n)
-- | Makes docker not restart a container when it exits
-- Note that this includes not restarting it on boot! -- Note that this includes not restarting it on boot!
-- restartNever :: Property
-- RestartOnFailure will restart the container if it exits nonzero. restartNever = runProp "restart" "no"
-- A max-retry value can be provided to prevent too many restarts.
data RestartPolicy = NoRestart | RestartOnFailure (Maybe Int) | RestartAlways
-- | A container is identified by its name, and the host -- | A container is identified by its name, and the host
-- on which it's deployed. -- on which it's deployed.