summaryrefslogtreecommitdiff
path: root/Propellor/SimpleSh.hs
diff options
context:
space:
mode:
authorJoey Hess2014-04-01 13:51:58 -0400
committerJoey Hess2014-04-01 13:51:58 -0400
commit79cbdf35b1188d83e64a713efa82bc7a0a72a181 (patch)
tree4ad96d9fa0d2e61f6cd15a2b635fef67ea7c9bb1 /Propellor/SimpleSh.hs
parent2c328ad142421302b41bc961aa175f60e27f0ab3 (diff)
better method of starting propellor simplesh inside docker
Diffstat (limited to 'Propellor/SimpleSh.hs')
-rw-r--r--Propellor/SimpleSh.hs20
1 files changed, 19 insertions, 1 deletions
diff --git a/Propellor/SimpleSh.hs b/Propellor/SimpleSh.hs
index 25a154a9..741c1bc8 100644
--- a/Propellor/SimpleSh.hs
+++ b/Propellor/SimpleSh.hs
@@ -12,6 +12,8 @@ import System.Process (std_in, std_out, std_err)
import System.Exit
import Propellor
+import Utility.FileMode
+import Utility.ThreadScheduler
data Cmd = Cmd String [String]
deriving (Read, Show)
@@ -22,7 +24,9 @@ data Resp = StdoutLine String | StderrLine String | Done ExitCode
simpleSh :: FilePath -> IO ()
simpleSh namedpipe = do
nukeFile namedpipe
- createDirectoryIfMissing True (takeDirectory namedpipe)
+ let dir = takeDirectory namedpipe
+ createDirectoryIfMissing True dir
+ modifyFileMode dir (removeModes otherGroupModes)
s <- socket AF_UNIX Stream defaultProtocol
bind s (SockAddrUnix namedpipe)
listen s 2
@@ -73,6 +77,20 @@ simpleShClient namedpipe cmd params handler = do
resps <- catMaybes . map readish . lines <$> hGetContents h
hClose h `after` handler resps
+simpleShClientRetry :: Int -> FilePath -> String -> [String] -> ([Resp] -> IO a) -> IO a
+simpleShClientRetry retries namedpipe cmd params handler = go retries
+ where
+ run = simpleShClient namedpipe cmd params handler
+ go n
+ | n < 1 = run
+ | otherwise = do
+ v <- tryIO run
+ case v of
+ Right r -> return r
+ Left _ -> do
+ threadDelaySeconds (Seconds 1)
+ go (n - 1)
+
getStdout :: Resp -> Maybe String
getStdout (StdoutLine s) = Just s
getStdout _ = Nothing