propellor spin
This commit is contained in:
parent
595794a250
commit
5674818300
|
@ -69,6 +69,12 @@ check c property = Property (propertyDesc property) $ ifM c
|
||||||
, return NoChange
|
, return NoChange
|
||||||
)
|
)
|
||||||
|
|
||||||
|
boolProperty :: Desc -> IO Bool -> Property
|
||||||
|
boolProperty desc a = Property desc $ ifM a
|
||||||
|
( return MadeChange
|
||||||
|
, return FailedChange
|
||||||
|
)
|
||||||
|
|
||||||
-- | Undoes the effect of a property.
|
-- | Undoes the effect of a property.
|
||||||
revert :: RevertableProperty -> RevertableProperty
|
revert :: RevertableProperty -> RevertableProperty
|
||||||
revert (RevertableProperty p1 p2) = RevertableProperty p2 p1
|
revert (RevertableProperty p1 p2) = RevertableProperty p2 p1
|
||||||
|
|
|
@ -54,12 +54,14 @@ docked findc hn cn = findContainer findc hn cn $
|
||||||
runningContainer cid image containerprops
|
runningContainer cid image containerprops
|
||||||
`requires`
|
`requires`
|
||||||
installed
|
installed
|
||||||
teardown = Property ("undocked " ++ fromContainerId cid) $
|
teardown = combineProperties ("undocked " ++ fromContainerId cid)
|
||||||
|
[ stoppedContainer cid
|
||||||
|
, Property ("cleaned up " ++ fromContainerId cid) $
|
||||||
report <$> mapM id
|
report <$> mapM id
|
||||||
[ stopContainerIfRunning cid
|
[ removeContainer cid
|
||||||
, removeContainer cid
|
|
||||||
, removeImage image
|
, removeImage image
|
||||||
]
|
]
|
||||||
|
]
|
||||||
in RevertableProperty setup teardown
|
in RevertableProperty setup teardown
|
||||||
where
|
where
|
||||||
cid = ContainerId hn cn
|
cid = ContainerId hn cn
|
||||||
|
@ -260,10 +262,9 @@ runningContainer cid@(ContainerId hn cn) image containerprops = containerDesc ci
|
||||||
clearProvisionedFlag cid
|
clearProvisionedFlag cid
|
||||||
createDirectoryIfMissing True (takeDirectory $ identFile cid)
|
createDirectoryIfMissing True (takeDirectory $ identFile cid)
|
||||||
writeFile (identFile cid) (show ident)
|
writeFile (identFile cid) (show ident)
|
||||||
ifM (runContainer img (runps ++ ["-i", "-d", "-t"]) chaincmd)
|
ensureProperty $ boolProperty "run" $ runContainer img
|
||||||
( return MadeChange
|
(runps ++ ["-i", "-d", "-t"])
|
||||||
, return FailedChange
|
chaincmd
|
||||||
)
|
|
||||||
|
|
||||||
-- | Called when propellor is running inside a docker container.
|
-- | Called when propellor is running inside a docker container.
|
||||||
-- The string should be the container's ContainerId.
|
-- The string should be the container's ContainerId.
|
||||||
|
@ -338,11 +339,14 @@ provisionContainer cid = containerDesc cid $ Property "provision" $ do
|
||||||
stopContainer :: ContainerId -> IO Bool
|
stopContainer :: ContainerId -> IO Bool
|
||||||
stopContainer cid = boolSystem dockercmd [Param "stop", Param $ fromContainerId cid ]
|
stopContainer cid = boolSystem dockercmd [Param "stop", Param $ fromContainerId cid ]
|
||||||
|
|
||||||
stopContainerIfRunning :: ContainerId -> IO Bool
|
stoppedContainer :: ContainerId -> Property
|
||||||
stopContainerIfRunning cid = ifM (elem cid <$> listContainers RunningContainers)
|
stoppedContainer cid = containerDesc cid $ Property desc $
|
||||||
( stopContainer cid
|
ifM (elem cid <$> listContainers RunningContainers)
|
||||||
, return True
|
( ensureProperty $ boolProperty desc $ stopContainer cid
|
||||||
|
, return NoChange
|
||||||
)
|
)
|
||||||
|
where
|
||||||
|
desc = "stopped"
|
||||||
|
|
||||||
removeContainer :: ContainerId -> IO Bool
|
removeContainer :: ContainerId -> IO Bool
|
||||||
removeContainer cid = catchBoolIO $
|
removeContainer cid = catchBoolIO $
|
||||||
|
|
Loading…
Reference in New Issue