From d2111214f2a93843638f1a3052b76c63c4497fdc Mon Sep 17 00:00:00 2001 From: James Rhodes Date: Tue, 12 Aug 2014 09:14:47 +1000 Subject: [PATCH] Allow timeouts to be specified on Drydock SSH connections Summary: This allows timeouts to be specified on SSH connections that Drydock makes. Used in the EC2 allocator to poll for the SSH server starting. Test Plan: Used in EC2 allocator diff. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D10225 --- .../command/DrydockSSHCommandInterface.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php b/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php index 70b023f2e2..10cc6b904e 100644 --- a/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php +++ b/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php @@ -3,6 +3,7 @@ final class DrydockSSHCommandInterface extends DrydockCommandInterface { private $passphraseSSHKey; + private $connectTimeout; private function openCredentialsIfNotOpen() { if ($this->passphraseSSHKey !== null) { @@ -25,6 +26,11 @@ final class DrydockSSHCommandInterface extends DrydockCommandInterface { PhabricatorUser::getOmnipotentUser()); } + public function setConnectTimeout($timeout) { + $this->connectTimeout = $timeout; + return $this; + } + public function getExecFuture($command) { $this->openCredentialsIfNotOpen(); @@ -44,8 +50,19 @@ final class DrydockSSHCommandInterface extends DrydockCommandInterface { $full_command = 'C:\\Windows\\system32\\cmd.exe /C '.$full_command; } + $command_timeout = ''; + if ($this->connectTimeout !== null) { + $command_timeout = csprintf( + '-o %s', + 'ConnectTimeout='.$this->connectTimeout); + } + return new ExecFuture( - 'ssh -o StrictHostKeyChecking=no -p %s -i %P %P@%s -- %s', + 'ssh '. + '-o StrictHostKeyChecking=no '. + '-o BatchMode=yes '. + '%C -p %s -i %P %P@%s -- %s', + $command_timeout, $this->getConfig('port'), $this->passphraseSSHKey->getKeyfileEnvelope(), $this->passphraseSSHKey->getUsernameEnvelope(),