summaryrefslogtreecommitdiff
path: root/src/Propellor
diff options
context:
space:
mode:
authorJoey Hess2014-10-23 12:28:33 -0400
committerJoey Hess2014-10-23 12:28:33 -0400
commitf5b5159f76ef20a5dcf190e6f3d92bea8aae69e1 (patch)
tree68440d9d31ccddd018abf35576bcbab7c0671cc4 /src/Propellor
parent76ad306aaeb30230f9d1356d079be7693908e661 (diff)
don't need RestartPolicy data type; simplify
Diffstat (limited to 'src/Propellor')
-rw-r--r--src/Propellor/Property/Docker.hs37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/Propellor/Property/Docker.hs b/src/Propellor/Property/Docker.hs
index c91530c3..d9d5f191 100644
--- a/src/Propellor/Property/Docker.hs
+++ b/src/Propellor/Property/Docker.hs
@@ -29,8 +29,9 @@ module Propellor.Property.Docker (
cpuShares,
link,
ContainerAlias,
- restart,
- RestartPolicy(..),
+ restartAlways,
+ restartOnFailure,
+ restartNever,
-- * Internal use
chain,
) where
@@ -157,7 +158,7 @@ mkContainer cid@(ContainerId hn _cn) h = Container
h' = h
-- Restart by default so container comes up on
-- boot or when docker is upgraded.
- &^ restart RestartAlways
+ &^ restartAlways
-- Expose propellor directory inside the container.
& volume (localdir++":"++localdir)
-- 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.
type ContainerAlias = String
--- | Restart policy to apply when a container exits.
-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
+-- | This property is enabled by default for docker containers configured by
-- propellor; as well as keeping badly behaved containers running,
-- it ensures that containers get started back up after reboot or
-- after docker is upgraded.
---
--- NoRestart makes docker not restart a container when it exits
+restartAlways :: Property
+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!
---
--- RestartOnFailure will restart the container if it exits nonzero.
--- A max-retry value can be provided to prevent too many restarts.
-data RestartPolicy = NoRestart | RestartOnFailure (Maybe Int) | RestartAlways
+restartNever :: Property
+restartNever = runProp "restart" "no"
-- | A container is identified by its name, and the host
-- on which it's deployed.