@@ -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"