From 2891006d9f18b9f50b7d8dfc6d32e326499913f0 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 1 Nov 2015 11:48:55 -0400 Subject: propellor spin --- src/Propellor/Spin.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/Propellor/Spin.hs') diff --git a/src/Propellor/Spin.hs b/src/Propellor/Spin.hs index 478d1517..0650e54d 100644 --- a/src/Propellor/Spin.hs +++ b/src/Propellor/Spin.hs @@ -64,7 +64,6 @@ spin' mprivdata relay target hst = do getprivdata -- And now we can run it. - flushConcurrentOutput unlessM (boolSystem "ssh" (map Param $ cacheparams ++ ["-t", sshtarget, shellWrap runcmd])) $ error "remote propellor failed" where @@ -105,8 +104,10 @@ spin' mprivdata relay target hst = do d <- readPrivDataFile f nukeFile f return d - | otherwise -> - filterPrivData hst <$> decryptPrivData + | otherwise -> do + d <- filterPrivData hst <$> decryptPrivData + flushConcurrentOutput + return d Just pd -> pure pd -- Check if the Host contains an IP address that matches one of the IPs -- cgit v1.2.3 From 0afa0c0593b655af475ecc9db1e3add7d2c18299 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 1 Nov 2015 11:51:08 -0400 Subject: Revert "propellor spin" This reverts commit 2891006d9f18b9f50b7d8dfc6d32e326499913f0. --- src/Propellor/Spin.hs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/Propellor/Spin.hs') diff --git a/src/Propellor/Spin.hs b/src/Propellor/Spin.hs index 0650e54d..478d1517 100644 --- a/src/Propellor/Spin.hs +++ b/src/Propellor/Spin.hs @@ -64,6 +64,7 @@ spin' mprivdata relay target hst = do getprivdata -- And now we can run it. + flushConcurrentOutput unlessM (boolSystem "ssh" (map Param $ cacheparams ++ ["-t", sshtarget, shellWrap runcmd])) $ error "remote propellor failed" where @@ -104,10 +105,8 @@ spin' mprivdata relay target hst = do d <- readPrivDataFile f nukeFile f return d - | otherwise -> do - d <- filterPrivData hst <$> decryptPrivData - flushConcurrentOutput - return d + | otherwise -> + filterPrivData hst <$> decryptPrivData Just pd -> pure pd -- Check if the Host contains an IP address that matches one of the IPs -- cgit v1.2.3 From ada8035a2a1d4d6cf7463266272a51bc2768fb63 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 1 Nov 2015 12:15:16 -0400 Subject: a few tweaks for concurrent output Force console mode when --spin calls SimpleRun --- src/Propellor/CmdLine.hs | 5 +++-- src/Propellor/Spin.hs | 14 ++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'src/Propellor/Spin.hs') diff --git a/src/Propellor/CmdLine.hs b/src/Propellor/CmdLine.hs index 4bca3986..4a4f71fe 100644 --- a/src/Propellor/CmdLine.hs +++ b/src/Propellor/CmdLine.hs @@ -120,8 +120,9 @@ defaultMain hostlist = withConcurrentOutput $ do go False (Spin hs mrelay) = do commitSpin forM_ hs $ \hn -> withhost hn $ spin mrelay hn - go False cmdline@(SimpleRun hn) = buildFirst cmdline $ - go False (Run hn) + go False cmdline@(SimpleRun hn) = do + forceConsole + buildFirst cmdline $ go False (Run hn) go False (Run hn) = ifM ((==) 0 <$> getRealUserID) ( onlyprocess $ withhost hn mainProperties , go True (Spin [hn] Nothing) diff --git a/src/Propellor/Spin.hs b/src/Propellor/Spin.hs index 478d1517..6048a1cd 100644 --- a/src/Propellor/Spin.hs +++ b/src/Propellor/Spin.hs @@ -29,7 +29,6 @@ import Propellor.Types.Info import qualified Propellor.Shim as Shim import Utility.FileMode import Utility.SafeCommand -import Utility.ConcurrentOutput commitSpin :: IO () commitSpin = do @@ -61,10 +60,9 @@ spin' mprivdata relay target hst = do updateServer target relay hst (proc "ssh" $ cacheparams ++ [sshtarget, shellWrap probecmd]) (proc "ssh" $ cacheparams ++ [sshtarget, shellWrap updatecmd]) - getprivdata + =<< getprivdata -- And now we can run it. - flushConcurrentOutput unlessM (boolSystem "ssh" (map Param $ cacheparams ++ ["-t", sshtarget, shellWrap runcmd])) $ error "remote propellor failed" where @@ -191,16 +189,16 @@ updateServer -> Host -> CreateProcess -> CreateProcess - -> IO PrivMap + -> PrivMap -> IO () -updateServer target relay hst connect haveprecompiled getprivdata = +updateServer target relay hst connect haveprecompiled privdata = withIOHandles createProcessSuccess connect go where hn = fromMaybe target relay go (toh, fromh) = do let loop = go (toh, fromh) - let restart = updateServer hn relay hst connect haveprecompiled getprivdata + let restart = updateServer hn relay hst connect haveprecompiled privdata let done = return () v <- maybe Nothing readish <$> getMarked fromh statusMarker case v of @@ -208,7 +206,7 @@ updateServer target relay hst connect haveprecompiled getprivdata = sendRepoUrl toh loop (Just NeedPrivData) -> do - sendPrivData hn toh =<< getprivdata + sendPrivData hn toh privdata loop (Just NeedGitClone) -> do hClose toh @@ -219,7 +217,7 @@ updateServer target relay hst connect haveprecompiled getprivdata = hClose toh hClose fromh sendPrecompiled hn - updateServer hn relay hst haveprecompiled (error "loop") getprivdata + updateServer hn relay hst haveprecompiled (error "loop") privdata (Just NeedGitPush) -> do sendGitUpdate hn fromh toh hClose fromh -- cgit v1.2.3 From 4d63a9f0ad327cba305e239e51d02e5e33213eda Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 1 Nov 2015 13:37:49 -0400 Subject: run editor processes in foreground --- src/Propellor/Gpg.hs | 21 +++++++++++++-------- src/Propellor/PrivData.hs | 5 ++++- src/Propellor/Spin.hs | 8 +++++--- 3 files changed, 22 insertions(+), 12 deletions(-) (limited to 'src/Propellor/Spin.hs') diff --git a/src/Propellor/Gpg.hs b/src/Propellor/Gpg.hs index 60b0d52d..9c58a5d1 100644 --- a/src/Propellor/Gpg.hs +++ b/src/Propellor/Gpg.hs @@ -16,6 +16,7 @@ import Utility.Monad import Utility.Misc import Utility.Tmp import Utility.FileSystemEncoding +import Utility.ConcurrentOutput type KeyId = String @@ -111,10 +112,7 @@ gitCommitKeyRing action = do -- Commit explicitly the keyring and privdata files, as other -- changes may be staged by the user and shouldn't be committed. tocommit <- filterM doesFileExist [ privDataFile, keyring] - gitCommit $ (map File tocommit) ++ - [ Param "-m" - , Param ("propellor " ++ action) - ] + gitCommit (Just ("propellor " ++ action)) (map File tocommit) -- Adds --gpg-sign if there's a keyring. gpgSignParams :: [CommandParam] -> IO [CommandParam] @@ -124,10 +122,17 @@ gpgSignParams ps = ifM (doesFileExist keyring) ) -- Automatically sign the commit if there'a a keyring. -gitCommit :: [CommandParam] -> IO Bool -gitCommit ps = do - ps' <- gpgSignParams ps - boolSystem "git" (Param "commit" : ps') +gitCommit :: Maybe String -> [CommandParam] -> IO Bool +gitCommit msg ps = do + let ps' = Param "commit" : ps ++ + maybe [] (\m -> [Param "-m", Param m]) msg + ps'' <- gpgSignParams ps' + if isNothing msg + then do + (_, _, _, p) <- createProcessForeground $ + proc "git" (toCommand ps'') + checkSuccessProcess p + else boolSystem "git" ps'' gpgDecrypt :: FilePath -> IO String gpgDecrypt f = ifM (doesFileExist f) diff --git a/src/Propellor/PrivData.hs b/src/Propellor/PrivData.hs index e59f42c3..6b77f782 100644 --- a/src/Propellor/PrivData.hs +++ b/src/Propellor/PrivData.hs @@ -54,6 +54,8 @@ import Utility.FileMode import Utility.Env import Utility.Table import Utility.FileSystemEncoding +import Utility.ConcurrentOutput +import Utility.Process -- | Allows a Property to access the value of a specific PrivDataField, -- for use in a specific Context or HostContext. @@ -192,7 +194,8 @@ editPrivData field context = do hClose th maybe noop (\p -> writeFileProtected' f (`L.hPut` privDataByteString p)) v editor <- getEnvDefault "EDITOR" "vi" - unlessM (boolSystem editor [File f]) $ + (_, _, _, p) <- createProcessForeground $ proc editor [f] + unlessM (checkSuccessProcess p) $ error "Editor failed; aborting." PrivData <$> readFile f setPrivDataTo field context v' diff --git a/src/Propellor/Spin.hs b/src/Propellor/Spin.hs index 6048a1cd..ae7e7af5 100644 --- a/src/Propellor/Spin.hs +++ b/src/Propellor/Spin.hs @@ -33,7 +33,8 @@ import Utility.SafeCommand commitSpin :: IO () commitSpin = do void $ actionMessage "Git commit" $ - gitCommit [Param "--allow-empty", Param "-a", Param "-m", Param spinCommitMessage] + gitCommit (Just spinCommitMessage) + [Param "--allow-empty", Param "-a"] -- Push to central origin repo first, if possible. -- The remote propellor will pull from there, which avoids -- us needing to send stuff directly to the remote host. @@ -336,8 +337,9 @@ mergeSpin = do old_head <- getCurrentGitSha1 branch old_commit <- findLastNonSpinCommit rungit "reset" [Param old_commit] - rungit "commit" [Param "-a", Param "--allow-empty"] - rungit "merge" =<< gpgSignParams [Param "-s", Param "ours", Param old_head] + unlessM (gitCommit Nothing [Param "-a", Param "--allow-empty"]) $ + error "git commit failed" + rungit "merge" =<< gpgSignParams [Param "-s", Param "ours", Param old_head, Param "--no-edit"] current_commit <- getCurrentGitSha1 branch rungit "update-ref" [Param branchref, Param current_commit] rungit "checkout" [Param branch] -- cgit v1.2.3