From 9cde582c3599f32917f64664a440b5bc5b7f36c4 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 2 Apr 2014 13:56:16 -0400 Subject: better container reversion --- Propellor/Property/Docker.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Propellor') diff --git a/Propellor/Property/Docker.hs b/Propellor/Property/Docker.hs index 0cec9e1e..e9715cad 100644 --- a/Propellor/Property/Docker.hs +++ b/Propellor/Property/Docker.hs @@ -55,7 +55,7 @@ docked findc hn cn = findContainer findc hn cn $ teardown = Property ("undocked " ++ fromContainerId cid) $ report <$> mapM id - [ stopContainer cid + [ stopContainerIfRunning cid , removeContainer cid , removeImage image ] @@ -337,6 +337,12 @@ provisionContainer cid = containerDesc cid $ Property "provision" $ do stopContainer :: ContainerId -> IO Bool stopContainer cid = boolSystem dockercmd [Param "stop", Param $ fromContainerId cid ] +stopContainerIfRunning :: ContainerId -> IO Bool +stopContainerIfRunning cid = ifM (elem cid <$> listContainers RunningContainers) + ( stopContainer cid + , return True + ) + removeContainer :: ContainerId -> IO Bool removeContainer cid = catchBoolIO $ snd <$> processTranscript dockercmd ["rm", fromContainerId cid ] Nothing -- cgit v1.2.3