From 70c482358164a61be7f6ef82d7e97ca3a24b5077 Mon Sep 17 00:00:00 2001 From: Alexander Miehe Date: Fri, 9 Jan 2015 14:05:37 +0100 Subject: [PATCH] Add config option to set ConnectTimeout for ssh connections --- Mage/Config.php | 10 ++++++++++ Mage/Task/AbstractTask.php | 1 + Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Mage/Config.php b/Mage/Config.php index e839c22..dd78593 100644 --- a/Mage/Config.php +++ b/Mage/Config.php @@ -391,6 +391,16 @@ class Config return $this->deployment('identity-file') ? ('-i ' . $this->deployment('identity-file') . ' ') : ''; } + /** + * Get the ConnectTimeout option + * + * @return string + */ + public function getConnectTimeoutOption() + { + return $this->environmentConfig('connect-timeout') ? ('-o ConnectTimeout=' . $this->environmentConfig('connect-timeout') . ' ') : ''; + } + /** * Get the current Host * diff --git a/Mage/Task/AbstractTask.php b/Mage/Task/AbstractTask.php index 663b387..491adfb 100644 --- a/Mage/Task/AbstractTask.php +++ b/Mage/Task/AbstractTask.php @@ -201,6 +201,7 @@ abstract class AbstractTask $localCommand = 'ssh ' . $this->getConfig()->getHostIdentityFileOption() . $needs_tty . ' -p ' . $this->getConfig()->getHostPort() . ' ' . '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ' + . $this->getConfig()->getConnectTimeoutOption() . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName(); $remoteCommand = str_replace('"', '\"', $command); diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php index d45ea17..9bb1b25 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php @@ -89,7 +89,7 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware } // Copy Tar Gz to Remote Host - $command = 'scp ' . $strategyFlags . ' ' . $this->getConfig()->getHostIdentityFileOption() . '-P ' . $this->getConfig()->getHostPort() . ' ' . $localTarGz . '.tar.gz ' + $command = 'scp ' . $strategyFlags . ' ' . $this->getConfig()->getHostIdentityFileOption() . $this->getConfig()->getConnectTimeoutOption() . '-P ' . $this->getConfig()->getHostPort() . ' ' . $localTarGz . '.tar.gz ' . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ':' . $deployToDirectory; $result = $this->runCommandLocal($command) && $result;