summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoey Hess2014-11-22 12:13:41 -0400
committerJoey Hess2014-11-22 12:13:41 -0400
commit7cbf4841de39761953cf31d32ed86bb4bd949672 (patch)
tree3d8bb9ecd83a24494a40de5211a10f19036a2949 /src
parent557fab609175d7d0a59ffe1269fed02f49f8004e (diff)
parent57ec60d6f307dbf3e237b924e635b90ba889af18 (diff)
Merge branch 'joeyconfig'
Diffstat (limited to 'src')
-rw-r--r--src/Propellor/CmdLine.hs27
-rw-r--r--src/Propellor/Engine.hs15
-rw-r--r--src/Propellor/Git.hs2
-rw-r--r--src/Propellor/Protocol.hs2
-rw-r--r--src/Propellor/Server.hs63
-rw-r--r--src/Propellor/Shim.hs2
-rw-r--r--src/Utility/Applicative.hs2
-rw-r--r--src/Utility/Data.hs2
-rw-r--r--src/Utility/Directory.hs2
-rw-r--r--src/Utility/Env.hs2
-rw-r--r--src/Utility/Exception.hs2
-rw-r--r--src/Utility/FileMode.hs2
-rw-r--r--src/Utility/FileSystemEncoding.hs2
-rw-r--r--src/Utility/LinuxMkLibs.hs2
-rw-r--r--src/Utility/Misc.hs2
-rw-r--r--src/Utility/Monad.hs2
-rw-r--r--src/Utility/Path.hs2
-rw-r--r--src/Utility/PosixFiles.hs2
-rw-r--r--src/Utility/Process.hs2
-rw-r--r--src/Utility/QuickCheck.hs2
-rw-r--r--src/Utility/SafeCommand.hs2
-rw-r--r--src/Utility/Scheduled.hs2
-rw-r--r--src/Utility/Table.hs2
-rw-r--r--src/Utility/ThreadScheduler.hs2
-rw-r--r--src/Utility/Tmp.hs2
-rw-r--r--src/Utility/UserInfo.hs2
26 files changed, 105 insertions, 46 deletions
diff --git a/src/Propellor/CmdLine.hs b/src/Propellor/CmdLine.hs
index 142efa1d..ec2ca7ed 100644
--- a/src/Propellor/CmdLine.hs
+++ b/src/Propellor/CmdLine.hs
@@ -114,16 +114,19 @@ unknownhost h hosts = errorMessage $ unlines
]
buildFirst :: CmdLine -> IO () -> IO ()
-buildFirst cmdline next = do
- oldtime <- getmtime
- ifM (actionMessage "Propellor build" $ boolSystem "make" [Param "build"])
- ( do
- newtime <- getmtime
- if newtime == oldtime
- then next
- else void $ boolSystem "./propellor" [Param "--continue", Param (show cmdline)]
- , errorMessage "Propellor build failed!"
- )
+buildFirst cmdline next = ifM (doesFileExist "Makefile")
+ ( do
+ oldtime <- getmtime
+ ifM (actionMessage "Propellor build" $ boolSystem "make" [Param "build"])
+ ( do
+ newtime <- getmtime
+ if newtime == oldtime
+ then next
+ else void $ boolSystem "./propellor" [Param "--continue", Param (show cmdline)]
+ , errorMessage "Propellor build failed!"
+ )
+ , next
+ )
where
getmtime = catchMaybeIO $ getModificationTime "propellor"
@@ -172,11 +175,11 @@ spin hn hst = do
updatecmd = mkcmd
[ "if [ ! -d " ++ localdir ++ " ]"
- , "then " ++ intercalate " && "
+ , "then (" ++ intercalate " && "
[ "apt-get update"
, "apt-get --no-install-recommends --no-upgrade -y install git make"
, "echo " ++ toMarked statusMarker (show NeedGitClone)
- ]
+ ] ++ ") || echo " ++ toMarked statusMarker (show NeedPrecompiled)
, "else " ++ intercalate " && "
[ "cd " ++ localdir
, "if ! test -x ./propellor; then make deps build; fi"
diff --git a/src/Propellor/Engine.hs b/src/Propellor/Engine.hs
index 969769ce..b551ca05 100644
--- a/src/Propellor/Engine.hs
+++ b/src/Propellor/Engine.hs
@@ -11,7 +11,6 @@ import "mtl" Control.Monad.Reader
import Control.Exception (bracket)
import System.PosixCompat
import System.Posix.IO
-import Data.Maybe
import Propellor.Types
import Propellor.Message
@@ -28,7 +27,9 @@ mainProperties :: Host -> IO ()
mainProperties host = do
r <- runPropellor host $
ensureProperties [Property "overall" (ensureProperties $ hostProperties host) mempty]
- setTitle "propellor: done"
+ h <- mkMessageHandle
+ whenConsole h $
+ setTitle "propellor: done"
hFlush stdout
case r of
FailedChange -> exitWith (ExitFailure 1)
@@ -74,8 +75,14 @@ processChainOutput h = go Nothing
go lastline = do
v <- catchMaybeIO (hGetLine h)
case v of
- Nothing -> pure $ fromMaybe FailedChange $
- readish =<< lastline
+ Nothing -> case lastline of
+ Nothing -> pure FailedChange
+ Just l -> case readish l of
+ Just r -> pure r
+ Nothing -> do
+ putStrLn l
+ hFlush stdout
+ return FailedChange
Just s -> do
maybe noop (\l -> unless (null l) (putStrLn l)) lastline
hFlush stdout
diff --git a/src/Propellor/Git.hs b/src/Propellor/Git.hs
index 73de1def..e5f464c0 100644
--- a/src/Propellor/Git.hs
+++ b/src/Propellor/Git.hs
@@ -38,7 +38,7 @@ getRepoUrl = getM get urls
_ -> Nothing
hasOrigin :: IO Bool
-hasOrigin = do
+hasOrigin = catchDefaultIO False $ do
rs <- lines <$> readProcess "git" ["remote"]
return $ "origin" `elem` rs
diff --git a/src/Propellor/Protocol.hs b/src/Propellor/Protocol.hs
index 68c2443b..95a671bc 100644
--- a/src/Propellor/Protocol.hs
+++ b/src/Propellor/Protocol.hs
@@ -13,7 +13,7 @@ import Data.List
import Propellor
-data Stage = NeedGitClone | NeedRepoUrl | NeedPrivData | NeedGitPush
+data Stage = NeedGitClone | NeedRepoUrl | NeedPrivData | NeedGitPush | NeedPrecompiled
deriving (Read, Show, Eq)
type Marker = String
diff --git a/src/Propellor/Server.hs b/src/Propellor/Server.hs
index 513a81f4..19a2c901 100644
--- a/src/Propellor/Server.hs
+++ b/src/Propellor/Server.hs
@@ -1,3 +1,7 @@
+-- When propellor --spin is running, the local host acts as a server,
+-- which connects to the remote host's propellor and responds to its
+-- requests.
+
module Propellor.Server (
update,
updateServer,
@@ -8,7 +12,9 @@ import Data.List
import System.Exit
import System.PosixCompat
import System.Posix.IO
+import System.Posix.Directory
import Control.Concurrent.Async
+import Control.Exception (bracket)
import qualified Data.ByteString as B
import Propellor
@@ -16,6 +22,7 @@ import Propellor.Protocol
import Propellor.PrivData.Paths
import Propellor.Git
import Propellor.Ssh
+import qualified Propellor.Shim as Shim
import Utility.FileMode
import Utility.SafeCommand
@@ -24,17 +31,19 @@ import Utility.SafeCommand
-- running the updateServer
update :: IO ()
update = do
- req NeedRepoUrl repoUrlMarker setRepoUrl
+ whenM hasOrigin $
+ req NeedRepoUrl repoUrlMarker setRepoUrl
makePrivDataDir
req NeedPrivData privDataMarker $
writeFileProtected privDataLocal
- req NeedGitPush gitPushMarker $ \_ -> do
- hin <- dup stdInput
- hout <- dup stdOutput
- hClose stdin
- hClose stdout
- unlessM (boolSystem "git" (pullparams hin hout)) $
- errorMessage "git pull from client failed"
+ whenM hasOrigin $
+ req NeedGitPush gitPushMarker $ \_ -> do
+ hin <- dup stdInput
+ hout <- dup stdOutput
+ hClose stdin
+ hClose stdout
+ unlessM (boolSystem "git" (pullparams hin hout)) $
+ errorMessage "git pull from client failed"
where
pullparams hin hout =
[ Param "pull"
@@ -69,6 +78,11 @@ updateServer hn hst connect = connect go
hClose fromh
sendGitClone hn
updateServer hn hst connect
+ (Just NeedPrecompiled) -> do
+ hClose toh
+ hClose fromh
+ sendPrecompiled hn
+ updateServer hn hst connect
Nothing -> return ()
sendRepoUrl :: Handle -> IO ()
@@ -113,6 +127,39 @@ sendGitClone hn = void $ actionMessage ("Clone git repository to " ++ hn) $ do
, "rm -f " ++ remotebundle
]
+-- Send a tarball containing the precompiled propellor, and libraries.
+-- This should be reasonably portable, as long as the remote host has the
+-- same architecture as the build host.
+sendPrecompiled :: HostName -> IO ()
+sendPrecompiled hn = void $ actionMessage ("Uploading locally compiled propellor as a last resort") $ do
+ bracket getWorkingDirectory changeWorkingDirectory $ \_ ->
+ withTmpDir "propellor" go
+ where
+ go tmpdir = do
+ cacheparams <- sshCachingParams hn
+ let shimdir = takeFileName localdir
+ createDirectoryIfMissing True (tmpdir </> shimdir)
+ changeWorkingDirectory (tmpdir </> shimdir)
+ me <- readSymbolicLink "/proc/self/exe"
+ shim <- Shim.setup me "."
+ when (shim /= "propellor") $
+ renameFile shim "propellor"
+ changeWorkingDirectory tmpdir
+ withTmpFile "propellor.tar." $ \tarball _ -> allM id
+ [ boolSystem "strip" [File me]
+ , boolSystem "tar" [Param "czf", File tarball, File shimdir]
+ , boolSystem "scp" $ cacheparams ++ [File tarball, Param ("root@"++hn++":"++remotetarball)]
+ , boolSystem "ssh" $ cacheparams ++ [Param ("root@"++hn), Param unpackcmd]
+ ]
+
+ remotetarball = "/usr/local/propellor.tar"
+
+ unpackcmd = shellWrap $ intercalate " && "
+ [ "cd " ++ takeDirectory remotetarball
+ , "tar xzf " ++ remotetarball
+ , "rm -f " ++ remotetarball
+ ]
+
-- Shim for git push over the propellor ssh channel.
-- Reads from stdin and sends it to hout;
-- reads from hin and sends it to stdout.
diff --git a/src/Propellor/Shim.hs b/src/Propellor/Shim.hs
index 5b5aa68e..1bfbb0ca 100644
--- a/src/Propellor/Shim.hs
+++ b/src/Propellor/Shim.hs
@@ -45,6 +45,8 @@ setup propellorbin dest = do
modifyFileMode shim (addModes executeModes)
return shim
+-- Called when the shimmed propellor is running, so that commands it runs
+-- don't see it.
cleanEnv :: IO ()
cleanEnv = void $ unsetEnv "GCONV_PATH"
diff --git a/src/Utility/Applicative.hs b/src/Utility/Applicative.hs
index fd8944b2..fce3c048 100644
--- a/src/Utility/Applicative.hs
+++ b/src/Utility/Applicative.hs
@@ -1,6 +1,6 @@
{- applicative stuff
-
- - Copyright 2012 Joey Hess <joey@kitenet.net>
+ - Copyright 2012 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/Data.hs b/src/Utility/Data.hs
index 2df12b36..5ecd218f 100644
--- a/src/Utility/Data.hs
+++ b/src/Utility/Data.hs
@@ -1,6 +1,6 @@
{- utilities for simple data types
-
- - Copyright 2013 Joey Hess <joey@kitenet.net>
+ - Copyright 2013 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/Directory.hs b/src/Utility/Directory.hs
index d92327c0..6b50016f 100644
--- a/src/Utility/Directory.hs
+++ b/src/Utility/Directory.hs
@@ -1,6 +1,6 @@
{- directory manipulation
-
- - Copyright 2011-2014 Joey Hess <joey@kitenet.net>
+ - Copyright 2011-2014 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/Env.hs b/src/Utility/Env.hs
index 6763c24e..dd502fd3 100644
--- a/src/Utility/Env.hs
+++ b/src/Utility/Env.hs
@@ -1,6 +1,6 @@
{- portable environment variables
-
- - Copyright 2013 Joey Hess <joey@kitenet.net>
+ - Copyright 2013 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/Exception.hs b/src/Utility/Exception.hs
index 1fecf65d..c6510dbc 100644
--- a/src/Utility/Exception.hs
+++ b/src/Utility/Exception.hs
@@ -1,6 +1,6 @@
{- Simple IO exception handling (and some more)
-
- - Copyright 2011-2012 Joey Hess <joey@kitenet.net>
+ - Copyright 2011-2012 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/FileMode.hs b/src/Utility/FileMode.hs
index c2ef683a..82568f6e 100644
--- a/src/Utility/FileMode.hs
+++ b/src/Utility/FileMode.hs
@@ -1,6 +1,6 @@
{- File mode utilities.
-
- - Copyright 2010-2012 Joey Hess <joey@kitenet.net>
+ - Copyright 2010-2012 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/FileSystemEncoding.hs b/src/Utility/FileSystemEncoding.hs
index b81fdc53..4e8f2ffe 100644
--- a/src/Utility/FileSystemEncoding.hs
+++ b/src/Utility/FileSystemEncoding.hs
@@ -1,6 +1,6 @@
{- GHC File system encoding handling.
-
- - Copyright 2012-2014 Joey Hess <joey@kitenet.net>
+ - Copyright 2012-2014 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/LinuxMkLibs.hs b/src/Utility/LinuxMkLibs.hs
index 1dc4e1ea..d32de1a1 100644
--- a/src/Utility/LinuxMkLibs.hs
+++ b/src/Utility/LinuxMkLibs.hs
@@ -1,6 +1,6 @@
{- Linux library copier and binary shimmer
-
- - Copyright 2013 Joey Hess <joey@kitenet.net>
+ - Copyright 2013 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/Misc.hs b/src/Utility/Misc.hs
index 949f41e7..e4eccac4 100644
--- a/src/Utility/Misc.hs
+++ b/src/Utility/Misc.hs
@@ -1,6 +1,6 @@
{- misc utility functions
-
- - Copyright 2010-2011 Joey Hess <joey@kitenet.net>
+ - Copyright 2010-2011 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/Monad.hs b/src/Utility/Monad.hs
index eba3c428..878e0da6 100644
--- a/src/Utility/Monad.hs
+++ b/src/Utility/Monad.hs
@@ -1,6 +1,6 @@
{- monadic stuff
-
- - Copyright 2010-2012 Joey Hess <joey@kitenet.net>
+ - Copyright 2010-2012 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/Path.hs b/src/Utility/Path.hs
index 99c9438b..ea62157f 100644
--- a/src/Utility/Path.hs
+++ b/src/Utility/Path.hs
@@ -1,6 +1,6 @@
{- path manipulation
-
- - Copyright 2010-2014 Joey Hess <joey@kitenet.net>
+ - Copyright 2010-2014 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/PosixFiles.hs b/src/Utility/PosixFiles.hs
index 5abbb578..5a94ead0 100644
--- a/src/Utility/PosixFiles.hs
+++ b/src/Utility/PosixFiles.hs
@@ -2,7 +2,7 @@
-
- This is like System.PosixCompat.Files, except with a fixed rename.
-
- - Copyright 2014 Joey Hess <joey@kitenet.net>
+ - Copyright 2014 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/Process.hs b/src/Utility/Process.hs
index 4550d94f..3e010541 100644
--- a/src/Utility/Process.hs
+++ b/src/Utility/Process.hs
@@ -1,7 +1,7 @@
{- System.Process enhancements, including additional ways of running
- processes, and logging.
-
- - Copyright 2012 Joey Hess <joey@kitenet.net>
+ - Copyright 2012 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/QuickCheck.hs b/src/Utility/QuickCheck.hs
index a498ee61..54200d3f 100644
--- a/src/Utility/QuickCheck.hs
+++ b/src/Utility/QuickCheck.hs
@@ -1,6 +1,6 @@
{- QuickCheck with additional instances
-
- - Copyright 2012-2014 Joey Hess <joey@kitenet.net>
+ - Copyright 2012-2014 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/SafeCommand.hs b/src/Utility/SafeCommand.hs
index 86e60db0..a5556200 100644
--- a/src/Utility/SafeCommand.hs
+++ b/src/Utility/SafeCommand.hs
@@ -1,6 +1,6 @@
{- safely running shell commands
-
- - Copyright 2010-2013 Joey Hess <joey@kitenet.net>
+ - Copyright 2010-2013 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/Scheduled.hs b/src/Utility/Scheduled.hs
index 305410c5..3a1a6cd3 100644
--- a/src/Utility/Scheduled.hs
+++ b/src/Utility/Scheduled.hs
@@ -1,6 +1,6 @@
{- scheduled activities
-
- - Copyright 2013-2014 Joey Hess <joey@kitenet.net>
+ - Copyright 2013-2014 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/Table.hs b/src/Utility/Table.hs
index 910038e8..4e862ff6 100644
--- a/src/Utility/Table.hs
+++ b/src/Utility/Table.hs
@@ -1,6 +1,6 @@
{- text based table generation
-
- - Copyright 2014 Joey Hess <joey@kitenet.net>
+ - Copyright 2014 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/ThreadScheduler.hs b/src/Utility/ThreadScheduler.hs
index fc026d7e..eb009742 100644
--- a/src/Utility/ThreadScheduler.hs
+++ b/src/Utility/ThreadScheduler.hs
@@ -1,6 +1,6 @@
{- thread scheduling
-
- - Copyright 2012, 2013 Joey Hess <joey@kitenet.net>
+ - Copyright 2012, 2013 Joey Hess <id@joeyh.name>
- Copyright 2011 Bas van Dijk & Roel van Dijk
-
- License: BSD-2-clause
diff --git a/src/Utility/Tmp.hs b/src/Utility/Tmp.hs
index 0dc9f2c0..d0cae337 100644
--- a/src/Utility/Tmp.hs
+++ b/src/Utility/Tmp.hs
@@ -1,6 +1,6 @@
{- Temporary files and directories.
-
- - Copyright 2010-2013 Joey Hess <joey@kitenet.net>
+ - Copyright 2010-2013 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
diff --git a/src/Utility/UserInfo.hs b/src/Utility/UserInfo.hs
index 617c3e94..e2c248b1 100644
--- a/src/Utility/UserInfo.hs
+++ b/src/Utility/UserInfo.hs
@@ -1,6 +1,6 @@
{- user info
-
- - Copyright 2012 Joey Hess <joey@kitenet.net>
+ - Copyright 2012 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}