@@ -13,23 +13,19 @@ import System.IO
1313 , hSetBinaryMode
1414 )
1515import Data.Binary (decode)
16−import qualified Data.ByteString.Lazy as BSL (ByteString, getContents)
16+import qualified Data.ByteString.Lazy as BSL (ByteString, getContents, length)
1717import Control.Monad (unless, forM, forM_, join)
18−import Control.Exception (throwIO)
19−import Control.Distributed.Process.Backend.Azure
20− ( AzureParameters(azureSshUserName)
21− , defaultAzureParameters
22− , initializeBackend
23− , cloudServices
24− , CloudService(cloudServiceName, cloudServiceVMs)
25− , VirtualMachine(vmName)
26− , Backend(copyToVM, checkMD5, callOnVM)
27− )
18+import Control.Exception (throwIO, SomeException)
19+import Control.Applicative ((<$>), (<*>), (<|>))
20+import Control.Monad.IO.Class (liftIO)
21+
22+-- SSH
2823import qualified Network.SSH.Client.LibSSH2.Foreign as SSH
2924 ( initialize
3025 , exit
3126 )
32−import Control.Applicative ((<$>), (<*>), (<|>))
27+
28+-- Command line options
3329import Options.Applicative
3430 ( Parser
3531 , strOption
@@ -47,17 +43,30 @@ import Options.Applicative
4743 , header
4844 , switch
4945 )
46+
47+-- CH
5048import Control.Distributed.Process
5149 ( RemoteTable
5250 , Closure
5351 , Process
5452 , unClosure
5553 , Static
54+ , catch
5655 )
5756import Control.Distributed.Process.Node (newLocalNode, runProcess, initRemoteTable)
5857import Control.Distributed.Process.Serializable (Serializable)
5958import Control.Distributed.Process.Closure (SerializableDict)
6059import Network.Transport.TCP (createTransport, defaultTCPParameters)
60+import Control.Distributed.Process.Backend.Azure
61+ ( AzureParameters(azureSshUserName)
62+ , defaultAzureParameters
63+ , initializeBackend
64+ , cloudServices
65+ , CloudService(cloudServiceName, cloudServiceVMs)
66+ , VirtualMachine(vmName)
67+ , Backend(copyToVM, checkMD5, callOnVM)
68+ )
69+import qualified Control.Distributed.Process.Backend.Azure as Azure (remoteTable)
6170
6271--------------------------------------------------------------------------------
6372-- Main --
@@ -112,7 +121,9 @@ genericMain remoteTable cmds = do
112121 ProcessPair rProc lProc dict ->
113122 callOnVM backend dict vm (remotePort cmd) rProc >>= lProc
114123 OnVmCommand (vmCmd@OnVmRun {}) -> do
115− onVmRun (remoteTable initRemoteTable) (onVmIP vmCmd) (onVmPort vmCmd)
124+ onVmRun (remoteTable . Azure.remoteTable $ initRemoteTable)
125+ (onVmIP vmCmd)
126+ (onVmPort vmCmd)
116127 SSH.exit
117128 where
118129 opts = info (helper <*> commandParser)
@@ -144,13 +155,16 @@ azureParameters opts (Just sshOpts) = do
144155onVmRun :: RemoteTable -> String -> String -> IO ()
145156onVmRun rtable host port = do
146157 hSetBinaryMode stdin True
158+ hSetBinaryMode stdout True
147159 proc <- BSL.getContents :: IO BSL.ByteString
148160 mTransport <- createTransport host port defaultTCPParameters
149161 case mTransport of
150162 Left err -> throwIO err
151163 Right transport -> do
152164 node <- newLocalNode transport rtable
153− runProcess node $ join . unClosure . decode $ proc
165+ runProcess node $
166+ catch (join . unClosure . decode $ proc)
167+ (\e -> liftIO (print (e :: SomeException) >> throwIO e))
154168
155169--------------------------------------------------------------------------------
156170-- Command line options --