git.iko.soy/distributed-process
on master help sign in
Use updated libssh2 bindings
commit4d26aadb599aea9a76ba74e0a444e99c761055c2 authorEdsko de Vries <edsko@well-typed.com> dateMon 30 Jul 2012, 13:25 (14 years ago) parent911bf29
3 files changed+21−17
azure-service-api/src/Network/Azure/ServiceManagement.hs+3−2 distributed-process-azure/distributed-process-azure.cabal+1 distributed-process-azure/src/Control/Distributed/Process/Backend/Azure.hs+17−15
azure-service-api/src/Network/Azure/ServiceManagement.hs+3−2
@@ -19,6 +19,7 @@ import Prelude hiding (id, (.))
1919import Control.Category (id, (>>>), (.))
2020import Control.Arrow (arr)
2121import Control.Monad (forM)
22+import Data.Maybe (listToMaybe)
2223import Data.ByteString.Char8 as BSC (pack)
2324import Data.ByteString.Lazy.Char8 as BSLC (unpack)
2425import Network.TLS (PrivateKey)
@@ -81,8 +82,8 @@ data Endpoint = Endpoint {
8182-- Pure operations --
8283--------------------------------------------------------------------------------
8384
84−vmSshEndpoint :: VirtualMachine -> Endpoint
85−vmSshEndpoint vm = head
85+vmSshEndpoint :: VirtualMachine -> Maybe Endpoint
86+vmSshEndpoint vm = listToMaybe
8687 [ ep
8788 | ep <- vmInputEndpoints vm
8889 , endpointName ep == "SSH"
distributed-process-azure/distributed-process-azure.cabal+1
@@ -25,6 +25,7 @@ Library
2525 executable-path >= 0.0.3 && < 0.1,
2626 libssh2 >= 0.2 && < 0.3
2727 Exposed-modules: Control.Distributed.Process.Backend.Azure
28+ Extensions: ViewPatterns
2829 ghc-options: -Wall
2930 HS-Source-Dirs: src
3031
distributed-process-azure/src/Control/Distributed/Process/Backend/Azure.hs+17−15
@@ -10,9 +10,8 @@ module Control.Distributed.Process.Backend.Azure
1010 ) where
1111
1212import System.Environment (getEnv)
13−import System.FilePath ((</>))
13+import System.FilePath ((</>), takeFileName)
1414import System.Environment.Executable (getExecutablePath)
15−import Control.Concurrent (threadDelay)
1615import Network.Azure.ServiceManagement
1716 ( CloudService(..)
1817 , VirtualMachine(..)
@@ -20,18 +19,16 @@ import Network.Azure.ServiceManagement
2019 )
2120import qualified Network.Azure.ServiceManagement as Azure
2221 ( cloudServices
23− , AzureSetup
2422 , azureSetup
2523 , vmSshEndpoint
2624 )
2725import qualified Network.SSH.Client.LibSSH2 as SSH
2826 ( withSSH2
29− , retryIfNeeded
27+ , execCommands
3028 )
3129import qualified Network.SSH.Client.LibSSH2.Foreign as SSH
3230 ( initialize
3331 , exit
34− , channelExecute
3532 )
3633
3734-- | Azure backend
@@ -48,7 +45,9 @@ data AzureParameters = AzureParameters {
4845 , azureSshUserName :: FilePath
4946 , azureSshPublicKey :: FilePath
5047 , azureSshPrivateKey :: FilePath
48+ , azureSshPassphrase :: String
5149 , azureSshKnownHosts :: FilePath
50+ , azureSshRemotePath :: FilePath
5251 }
5352
5453-- | Create default azure parameters
@@ -59,6 +58,7 @@ defaultAzureParameters :: String -- ^ Azure subscription ID
5958defaultAzureParameters sid x509 pkey = do
6059 home <- getEnv "HOME"
6160 user <- getEnv "USER"
61+ self <- getExecutablePath
6262 return AzureParameters
6363 { azureSubscriptionId = sid
6464 , azureAuthCertificate = x509
@@ -66,7 +66,9 @@ defaultAzureParameters sid x509 pkey = do
6666 , azureSshUserName = user
6767 , azureSshPublicKey = home </> ".ssh" </> "id_rsa.pub"
6868 , azureSshPrivateKey = home </> ".ssh" </> "id_rsa"
69+ , azureSshPassphrase = ""
6970 , azureSshKnownHosts = home </> ".ssh" </> "known_hosts"
71+ , azureSshRemotePath = "/home" </> user </> takeFileName self
7072 }
7173
7274-- | Initialize the backend
@@ -75,8 +77,6 @@ initializeBackend params = do
7577 setup <- Azure.azureSetup (azureSubscriptionId params)
7678 (azureAuthCertificate params)
7779 (azureAuthPrivateKey params)
78− exe <- getExecutablePath
79− print exe
8080 return Backend {
8181 cloudServices = Azure.cloudServices setup
8282 , startOnVM = apiStartOnVM params
@@ -84,14 +84,16 @@ initializeBackend params = do
8484
8585-- | Start a CH node on the given virtual machine
8686apiStartOnVM :: AzureParameters -> VirtualMachine -> IO ()
87−apiStartOnVM params vm = do
87+apiStartOnVM params (Azure.vmSshEndpoint -> Just ep) = do
8888 _ <- SSH.initialize True
89− let ep = Azure.vmSshEndpoint vm
9089 _ <- SSH.withSSH2 (azureSshKnownHosts params)
91− (azureSshPublicKey params)
92− (azureSshPrivateKey params)
93− (azureSshUserName params)
94− (endpointVip ep)
95− (read $ endpointPort ep) $ \fd s ch -> do
96− SSH.retryIfNeeded fd s $ SSH.channelExecute ch "nohup /home/edsko/testservice >/dev/null 2>&1 &"
90+ (azureSshPublicKey params)
91+ (azureSshPrivateKey params)
92+ (azureSshPassphrase params)
93+ (azureSshUserName params)
94+ (endpointVip ep)
95+ (read $ endpointPort ep) $ \fd s -> do
96+ SSH.execCommands fd s ["nohup /home/edsko/testservice >/dev/null 2>&1 &"]
9797 SSH.exit
98+apiStartOnVM _ _ =
99+ error "startOnVM: No SSH endpoint"