summaryrefslogtreecommitdiff
path: root/Propellor
diff options
context:
space:
mode:
authorJoey Hess2014-04-01 12:37:57 -0400
committerJoey Hess2014-04-01 12:38:09 -0400
commit2fd17d628c380059f2f4c9faab1de413b99e8716 (patch)
treed7fc4384c715fdcadf06bece434506a871fd6ace /Propellor
parenta4eec61238db9df3b669cd63d1bd34d8f87dcb6d (diff)
fix 2 docker bugs
Diffstat (limited to 'Propellor')
-rw-r--r--Propellor/Property/Docker.hs22
1 files changed, 16 insertions, 6 deletions
diff --git a/Propellor/Property/Docker.hs b/Propellor/Property/Docker.hs
index cacff5ce..3e19db4f 100644
--- a/Propellor/Property/Docker.hs
+++ b/Propellor/Property/Docker.hs
@@ -99,7 +99,7 @@ hasContainer hn cn findcontainer =
ensureContainer :: ContainerId -> Image -> [Containerized Property] -> IO Result
ensureContainer cid image containerprops = do
- l <- listRunningContainers
+ l <- listContainers Running
if cid `elem` l
then do
runningident <- getrunningident
@@ -111,7 +111,8 @@ ensureContainer cid image containerprops = do
removeContainer cid
go oldimage
else do
- removeContainer cid
+ whenM (elem cid <$> listContainers Stopped) $
+ removeContainer cid
go image
where
ident = ContainerIdent image cid runps
@@ -199,14 +200,23 @@ commitContainer cid = catchMaybeIO $
takeWhile (/= '\n')
<$> readProcess dockercmd ["commit", fromContainerId cid]
+data ContainerStatus = Running | Stopped
+ deriving (Eq)
+
-- | Only lists propellor managed containers.
-listRunningContainers :: IO [ContainerId]
-listRunningContainers =
+listContainers :: ContainerStatus -> IO [ContainerId]
+listContainers status =
catMaybes . map readish . catMaybes . map (lastMaybe . words) . lines
- <$> readProcess dockercmd ["ps", "--no-trunc"]
+ <$> readProcess dockercmd ps
+ where
+ ps
+ | status == Stopped = baseps ++ ["--all"]
+ | otherwise = baseps
+ baseps = ["ps", "--no-trunc"]
runProp :: String -> RunParam -> Containerized Property
-runProp field val = Containerized [param] (Property param (return NoChange))
+runProp field val =
+ Containerized ["--" ++ param] (Property param (return NoChange))
where
param = field++"="++val