Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native ssh tty option feature #953

Merged
merged 1 commit into from
Jan 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Builder/BuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,12 @@ public function stage($stages);
* @return BuilderInterface
*/
public function set($name, $value);

/**
* Use pty connection
*
* @param $pty
* @return BuilderInterface
*/
public function pty($pty);
}
11 changes: 11 additions & 0 deletions src/Cluster/ClusterBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,15 @@ public function stage($stages)
}
return $this;
}

/**
* {@inheritdoc}
*/
public function pty($stages)
{
foreach ($this->nodes as $node) {
$node->builder->pty($stages);
}
return $this;
}
}
3 changes: 2 additions & 1 deletion src/Initializer/Template/FrameworkTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ protected function getTemplateContent()
server('production', 'domain.com')
->user('username')
->identityFile()
->set('deploy_path', '/var/www/domain.com');
->set('deploy_path', '/var/www/domain.com')
->pty(true);


// Tasks
Expand Down
14 changes: 14 additions & 0 deletions src/Server/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,24 @@ private function checkPassword($password)
));
}

/**
* Use pty connection
*
* @param $pty
* @return BuilderInterface
*/
public function pty($pty)
{
$this->config->setPty($pty);

return $this;
}

/**
* Use pty in ssh2 connection
*
* @param $ssh2Pty
* @deprecated
* @return BuilderInterface
*/
public function ssh2Pty($ssh2Pty)
Expand Down
34 changes: 28 additions & 6 deletions src/Server/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ class Configuration
private $pemFile;

/**
* Pty configuration for ssh2 connection
* Pty configuration
*
* @var mixed
*/
private $ssh2Pty = null;
private $pty = null;


/**
Expand Down Expand Up @@ -422,22 +422,44 @@ private function getRealPassword($password)
}

/**
* Set pty for ssh2 connection
* Set pty
*
* @param $pty
*/
public function setPty($pty)
{
$this->pty = $pty;
}

/**
* Get pty option
*
* @return mixed
*/
public function getPty()
{
return $this->pty;
}

/**
* Set pty for ssh2 connection. For retro compatibility
*
* @param $ssh2Pty
* @deprecated
*/
public function setSsh2Pty($ssh2Pty)
{
$this->ssh2Pty = $ssh2Pty;
$this->setPty($ssh2Pty);
}

/**
* Get pty option for ssh2 connection
* Get pty option for ssh2 connection. For retro compatibility
*
* @deprecated
* @return mixed
*/
public function getSsh2Pty()
{
return $this->ssh2Pty;
return $this->getPty();
}
}
5 changes: 5 additions & 0 deletions src/Server/Remote/NativeSsh.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@ public function run($command)
$sshOptions[] = '-i ' . escapeshellarg($serverConfig->getPrivateKey());
}

if ($serverConfig->getPty()) {
$sshOptions[] = '-t';
}

$sshCommand = 'ssh ' . implode(' ', $sshOptions) . ' ' . escapeshellarg($username . $hostname) . ' ' . escapeshellarg($command);

$process = new Process($sshCommand);
$process
->setPty($serverConfig->getPty())
->setTimeout(null)
->setIdleTimeout(null)
->mustRun();
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Remote/SshExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function run($command)
{
$this->checkConnection();

$pty = $this->getConfiguration()->getSsh2Pty();
$pty = $this->getConfiguration()->getPty();
return $this->session->getExec()->run($command, $pty);
}

Expand Down