git.iko.soy/distributed-process
on master help sign in
Initialize SSH once
8496c31Edsko de Vries
distributed-process-azure/src/Control/Distributed/Process/Backend/Azure.hs+2−7
@@ -33,9 +33,7 @@ import qualified Network.SSH.Client.LibSSH2 as SSH
33 , readAllChannel
33 , readAllChannel
34 )
34 )
35import qualified Network.SSH.Client.LibSSH2.Foreign as SSH
35import qualified Network.SSH.Client.LibSSH2.Foreign as SSH
36− ( initialize
37− , exit
38− , openChannelSession
36+ ( openChannelSession
39 , retryIfNeeded
37 , retryIfNeeded
40 , channelExecute
38 , channelExecute
41 , writeChannel
39 , writeChannel
@@ -100,7 +98,6 @@ initializeBackend params = do
100-- | Start a CH node on the given virtual machine
98-- | Start a CH node on the given virtual machine
101apiCopyToVM :: AzureParameters -> VirtualMachine -> IO ()
99apiCopyToVM :: AzureParameters -> VirtualMachine -> IO ()
102apiCopyToVM params (Azure.vmSshEndpoint -> Just ep) = do
100apiCopyToVM params (Azure.vmSshEndpoint -> Just ep) = do
103− _ <- SSH.initialize True
104 _ <- SSH.withSSH2 (azureSshKnownHosts params)
101 _ <- SSH.withSSH2 (azureSshKnownHosts params)
105 (azureSshPublicKey params)
102 (azureSshPublicKey params)
106 (azureSshPrivateKey params)
103 (azureSshPrivateKey params)
@@ -110,14 +107,13 @@ apiCopyToVM params (Azure.vmSshEndpoint -> Just ep) = do
110 (read $ endpointPort ep) $ \fd s -> do
107 (read $ endpointPort ep) $ \fd s -> do
111 SSH.scpSendFile fd s 0o700 (azureSshLocalPath params) (azureSshRemotePath params)
108 SSH.scpSendFile fd s 0o700 (azureSshLocalPath params) (azureSshRemotePath params)
112 -- SSH.execCommands fd s ["nohup /home/edsko/testservice >/dev/null 2>&1 &"]
109 -- SSH.execCommands fd s ["nohup /home/edsko/testservice >/dev/null 2>&1 &"]
113− SSH.exit
110+ return ()
114apiCopyToVM _ _ =
111apiCopyToVM _ _ =
115 error "copyToVM: No SSH endpoint"
112 error "copyToVM: No SSH endpoint"
116
113
117apiCheckMD5 :: AzureParameters -> VirtualMachine -> IO Bool
114apiCheckMD5 :: AzureParameters -> VirtualMachine -> IO Bool
118apiCheckMD5 params (Azure.vmSshEndpoint -> Just ep) = do
115apiCheckMD5 params (Azure.vmSshEndpoint -> Just ep) = do
119 hash <- localHash params
116 hash <- localHash params
120− _ <- SSH.initialize True
121 match <- SSH.withSSH2 (azureSshKnownHosts params)
117 match <- SSH.withSSH2 (azureSshKnownHosts params)
122 (azureSshPublicKey params)
118 (azureSshPublicKey params)
123 (azureSshPrivateKey params)
119 (azureSshPrivateKey params)
@@ -131,7 +127,6 @@ apiCheckMD5 params (Azure.vmSshEndpoint -> Just ep) = do
131 SSH.channelSendEOF ch
127 SSH.channelSendEOF ch
132 SSH.readAllChannel fd ch
128 SSH.readAllChannel fd ch
133 return (r == 0)
129 return (r == 0)
134− SSH.exit
135 return match
130 return match
136apiCheckMD5 _ _ =
131apiCheckMD5 _ _ =
137 error "checkMD5: No SSH endpoint"
132 error "checkMD5: No SSH endpoint"
distributed-process-azure/src/Control/Distributed/Process/Backend/Azure/CommandLine.hs+7−1
@@ -3,6 +3,7 @@ import System.Environment (getArgs)
3import System.Exit (exitSuccess, exitFailure)
3import System.Exit (exitSuccess, exitFailure)
4import System.IO (hFlush, stdout)
4import System.IO (hFlush, stdout)
5import Control.Monad (unless, forM, forM_)
5import Control.Monad (unless, forM, forM_)
6+import Control.Arrow (returnA)
6import Control.Distributed.Process.Backend.Azure
7import Control.Distributed.Process.Backend.Azure
7 ( AzureParameters(azureSshUserName)
8 ( AzureParameters(azureSshUserName)
8 , defaultAzureParameters
9 , defaultAzureParameters
@@ -12,7 +13,10 @@ import Control.Distributed.Process.Backend.Azure
12 , VirtualMachine(vmName)
13 , VirtualMachine(vmName)
13 , Backend(copyToVM, checkMD5)
14 , Backend(copyToVM, checkMD5)
14 )
15 )
15−import Control.Arrow (returnA)
16+import qualified Network.SSH.Client.LibSSH2.Foreign as SSH
17+ ( initialize
18+ , exit
19+ )
16import Control.Applicative ((<$>), (<*>), (<|>))
20import Control.Applicative ((<$>), (<*>), (<|>))
17import Options.Applicative
21import Options.Applicative
18 ( Parser
22 ( Parser
@@ -141,6 +145,7 @@ commandParser = subparser
141
145
142main :: IO ()
146main :: IO ()
143main = do
147main = do
148+ _ <- SSH.initialize True
144 cmd <- execParser opts
149 cmd <- execParser opts
145 case cmd of
150 case cmd of
146 List {} -> do
151 List {} -> do
@@ -168,6 +173,7 @@ main = do
168 if and matches
173 if and matches
169 then exitSuccess
174 then exitSuccess
170 else exitFailure
175 else exitFailure
176+ SSH.exit
171 where
177 where
172 opts = info (helper <*> commandParser)
178 opts = info (helper <*> commandParser)
173 ( fullDesc
179 ( fullDesc