Run remote propellor --spin with a controlling terminal.

Avoids need for hack to make ansi colors work, but also things like apt-get
and wget process bars will be displayed.
This commit is contained in:
Joey Hess 2014-11-18 01:01:50 -04:00
parent 973025723c
commit 40f6d06f1a
4 changed files with 16 additions and 16 deletions

1
debian/changelog vendored
View File

@ -8,6 +8,7 @@ propellor (0.9.3) UNRELEASED; urgency=medium
* DigitalOcean.distroKernel property now reboots into the distribution
kernel when necessary.
* Avoid outputting color setting sequences when not run on a terminal.
* Run remote propellor --spin with a controlling terminal.
-- Joey Hess <joeyh@debian.org> Mon, 10 Nov 2014 11:15:27 -0400

View File

@ -41,7 +41,7 @@ processCmdLine = go =<< getArgs
where
go ("--help":_) = usage
go ("--spin":h:[]) = return $ Spin h
go ("--boot":h:[]) = return $ Boot h
go ("--sync":[]) = return $ Sync
go ("--add-key":k:[]) = return $ AddKey k
go ("--set":f:c:[]) = withprivfield f c Set
go ("--dump":f:c:[]) = withprivfield f c Dump
@ -91,7 +91,7 @@ defaultMain hostlist = do
( onlyProcess $ withhost hn mainProperties
, go True (Spin hn)
)
go False (Boot hn) = onlyProcess $ withhost hn boot
go False Sync = onlyProcess sync
withhost :: HostName -> (Host -> IO ()) -> IO ()
withhost hn a = maybe (unknownhost hn hostlist) a (findHost hostlist hn)
@ -186,6 +186,8 @@ spin hn hst = do
void $ boolSystem "git" [Param "push"]
cacheparams <- toCommand <$> sshCachingParams hn
go cacheparams url =<< hostprivdata
unlessM (boolSystem "ssh" (map Param (cacheparams ++ ["-t", user, spincmd]))) $
error "remote propellor failed"
where
hostprivdata = show . filterPrivData hst <$> decryptPrivData
@ -209,7 +211,9 @@ spin hn hst = do
user = "root@"++hn
bootstrapcmd = shellWrap $ intercalate " ; "
mkcmd = shellWrap . intercalate " ; "
bootstrapcmd = mkcmd
[ "if [ ! -d " ++ localdir ++ " ]"
, "then " ++ intercalate " && "
[ "apt-get update"
@ -219,11 +223,14 @@ spin hn hst = do
, "else " ++ intercalate " && "
[ "cd " ++ localdir
, "if ! test -x ./propellor; then make deps build; fi"
, "./propellor --boot " ++ hn
, "./propellor --sync"
]
, "fi"
]
spincmd = mkcmd
[ "cd " ++ localdir ++ " && ./propellor --spin " ++ hn ]
getstatus :: Handle -> IO BootStrapStatus
getstatus h = do
l <- hGetLine h
@ -295,16 +302,14 @@ fromMarked marker s
len = length marker
matches = filter (marker `isPrefixOf`) $ lines s
boot :: Host -> IO ()
boot h = do
sync :: IO ()
sync = do
sendMarked stdout statusMarker $ show Ready
reply <- hGetContentsStrict stdin
makePrivDataDir
maybe noop (writeFileProtected privDataLocal) $
fromMarked privDataMarker reply
forceConsoleMode
mainProperties h
getUrl :: IO String
getUrl = maybe nourl return =<< getM get urls

View File

@ -6,26 +6,20 @@ import System.Console.ANSI
import System.IO
import System.Log.Logger
import "mtl" Control.Monad.Reader
import Control.Applicative
import Data.Maybe
import Propellor.Types
import Utility.Monad
import Utility.Env
data MessageHandle
= ConsoleMessageHandle
| TextMessageHandle
mkMessageHandle :: IO MessageHandle
mkMessageHandle = ifM (hIsTerminalDevice stdout <||> (isJust <$> getEnv "TERM"))
mkMessageHandle = ifM (hIsTerminalDevice stdout)
( return ConsoleMessageHandle
, return TextMessageHandle
)
forceConsoleMode :: IO ()
forceConsoleMode = void $ setEnv "TERM" "vt100" False
whenConsole :: MessageHandle -> IO () -> IO ()
whenConsole ConsoleMessageHandle a = a
whenConsole _ _ = return ()

View File

@ -137,7 +137,6 @@ instance ActionResult Result where
data CmdLine
= Run HostName
| Spin HostName
| Boot HostName
| Set PrivDataField Context
| Dump PrivDataField Context
| Edit PrivDataField Context
@ -145,5 +144,6 @@ data CmdLine
| AddKey String
| Continue CmdLine
| Chain HostName
| Sync
| Docker HostName
deriving (Read, Show, Eq)