summaryrefslogtreecommitdiff
path: root/Propellor
diff options
context:
space:
mode:
Diffstat (limited to 'Propellor')
-rw-r--r--Propellor/CmdLine.hs28
-rw-r--r--Propellor/Message.hs5
-rw-r--r--Propellor/Property/Docker.hs7
3 files changed, 35 insertions, 5 deletions
diff --git a/Propellor/CmdLine.hs b/Propellor/CmdLine.hs
index 62f86e63..8edfe19e 100644
--- a/Propellor/CmdLine.hs
+++ b/Propellor/CmdLine.hs
@@ -1,8 +1,12 @@
module Propellor.CmdLine where
-import System.Environment
+import System.Environment (getArgs)
import Data.List
import System.Exit
+import System.Log.Logger
+import System.Log.Formatter
+import System.Log.Handler (setFormatter, LogHandler)
+import System.Log.Handler.Simple
import Propellor
import Propellor.SimpleSh
@@ -47,7 +51,9 @@ processCmdLine = go =<< getArgs
Nothing -> errorMessage "--continue serialization failure"
go ("--simplesh":f:[]) = return $ SimpleSh f
go ("--chain":h:[]) = return $ Chain h
- go (h:[]) = return $ Run h
+ go (h:[])
+ | "--" `isPrefixOf` h = usage
+ | otherwise = return $ Run h
go [] = do
s <- takeWhile (/= '\n') <$> readProcess "hostname" ["-f"]
if null s
@@ -56,7 +62,11 @@ processCmdLine = go =<< getArgs
go _ = usage
defaultMain :: [HostName -> Maybe [Property]] -> IO ()
-defaultMain getprops = go True =<< processCmdLine
+defaultMain getprops = do
+ checkDebugMode
+ cmdline <- processCmdLine
+ debug ["command line: ", show cmdline]
+ go True cmdline
where
go _ (Continue cmdline) = go False cmdline
go _ (Set host field) = setPrivData host field
@@ -301,3 +311,15 @@ getUrl = maybe nourl return =<< getM get urls
return $ case v of
Just url | not (null url) -> Just url
_ -> Nothing
+
+checkDebugMode :: IO ()
+checkDebugMode = go =<< getEnv "PROPELLOR_DEBUG"
+ where
+ go (Just s)
+ | s == "1" = do
+ f <- setFormatter
+ <$> streamHandler stderr DEBUG
+ <*> pure (simpleLogFormatter "[$time] $msg")
+ updateGlobalLogger rootLoggerName $
+ setLevel DEBUG . setHandlers [f]
+ go _ = noop
diff --git a/Propellor/Message.hs b/Propellor/Message.hs
index 90163649..c15661a7 100644
--- a/Propellor/Message.hs
+++ b/Propellor/Message.hs
@@ -2,6 +2,7 @@ module Propellor.Message where
import System.Console.ANSI
import System.IO
+import System.Log.Logger
import Propellor.Types
@@ -35,3 +36,7 @@ errorMessage :: String -> IO a
errorMessage s = do
warningMessage s
error "Propellor failed!"
+
+-- | Causes a debug message to be displayed when PROPELLOR_DEBUG=1
+debug :: [String] -> IO ()
+debug = debugM "propellor" . unwords
diff --git a/Propellor/Property/Docker.hs b/Propellor/Property/Docker.hs
index 450f397b..cacff5ce 100644
--- a/Propellor/Property/Docker.hs
+++ b/Propellor/Property/Docker.hs
@@ -211,8 +211,11 @@ runProp field val = Containerized [param] (Property param (return NoChange))
param = field++"="++val
-- | Lift a Property to run inside the container.
-inside :: Property -> Containerized Property
-inside p = Containerized [] p
+inside1 :: Property -> Containerized Property
+inside1 = Containerized []
+
+inside :: [Property] -> Containerized Property
+inside = Containerized [] . combineProperties
-- | Set custom dns server for container.
dns :: String -> Containerized Property