propellor spin

This commit is contained in:
Joey Hess 2014-10-23 02:34:42 -04:00
parent b971afeccd
commit fbba9639d6
Failed to extract signature
2 changed files with 26 additions and 2 deletions

View File

@ -53,7 +53,7 @@ darkstar = host "darkstar.kitenet.net"
& Apt.buildDep ["git-annex"] `period` Daily & Apt.buildDep ["git-annex"] `period` Daily
& Docker.configured & Docker.configured
! Docker.docked hosts "android-git-annex" ! Docker.docked hosts "android-git-annex"
! Docker.docked hosts "webserver" & Docker.docked hosts "test"
clam :: Host clam :: Host
clam = standardSystem "clam.kitenet.net" Unstable "amd64" clam = standardSystem "clam.kitenet.net" Unstable "amd64"

View File

@ -30,6 +30,8 @@ module Propellor.Property.Docker (
cpuShares, cpuShares,
link, link,
ContainerAlias, ContainerAlias,
restart,
RestartPolicy(..),
-- * Internal use -- * Internal use
chain, chain,
) where ) where
@ -150,7 +152,7 @@ findContainer mhost cid cn mk = case mhost of
mkContainer :: ContainerId -> Host -> Maybe Container mkContainer :: ContainerId -> Host -> Maybe Container
mkContainer cid@(ContainerId hn _cn) h = Container mkContainer cid@(ContainerId hn _cn) h = Container
<$> fromVal (_dockerImage info) <$> fromVal (_dockerImage info)
<*> pure (map (\a -> a hn) (_dockerRunParams info)) <*> pure (map (\mkparam -> mkparam hn) (_dockerRunParams info))
where where
info = _dockerinfo $ hostInfo h' info = _dockerinfo $ hostInfo h'
h' = h h' = h
@ -159,6 +161,7 @@ mkContainer cid@(ContainerId hn _cn) h = Container
-- name the container in a predictable way so we -- name the container in a predictable way so we
-- and the user can easily find it later -- and the user can easily find it later
& name (fromContainerId cid) & name (fromContainerId cid)
& restart RestartAlways
-- | Causes *any* docker images that are not in use by running containers to -- | Causes *any* docker images that are not in use by running containers to
-- be deleted. And deletes any containers that propellor has set up -- be deleted. And deletes any containers that propellor has set up
@ -274,6 +277,27 @@ 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.
restart :: RestartPolicy -> Property
restart policy = runProp "restart" (serialize policy)
where
serialize NoRestart = "no"
serialize (RestartOnFailure Nothing) = "on-failure"
serialize (RestartOnFailure n) = "on-failure:" ++ show n
serialize RestartAlways = "always"
-- | NoRestart 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 repeated restarts.
--
-- RestartAlways is the 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.
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.
data ContainerId = ContainerId HostName ContainerName data ContainerId = ContainerId HostName ContainerName