Skip to content

Commit

Permalink
Change output of errors for native ssh (deployphp#1012)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkuznetsov4xxi committed Feb 24, 2017
1 parent 6246c34 commit 36a4771
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

### Changed
- Autoload functions via Composer [#1015](https://github.com/deployphp/deployer/pull/1015)
- Add task queue:restart for Laravel recipe [#1007](https://github.com/deployphp/deployer/pull/1007)
- Changed output of errors for native ssh [#1012](https://github.com/deployphp/deployer/issues/1012)

### Fixed
- Fixed `Can not share same dirs` for shared folders having similar names [#995](https://github.com/deployphp/deployer/issues/995)
Expand All @@ -18,8 +20,6 @@
- Fixed possibility to use PEM files with Native SSH
- Fixed old releases not being cleaned up when keep_releases reduced by more than half.

### Changed
- Add task queue:restart for Laravel recipe [#1007](https://github.com/deployphp/deployer/pull/1007)

## v4.2.1
[v4.2.0...v4.2.1](https://github.com/deployphp/deployer/compare/v4.2.0...v4.2.1)
Expand Down
38 changes: 26 additions & 12 deletions src/Server/Remote/NativeSsh.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Deployer\Server\Configuration;
use Deployer\Server\ServerInterface;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

class NativeSsh implements ServerInterface
Expand Down Expand Up @@ -85,12 +86,17 @@ public function run($command)

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

$process = new Process($sshCommand);
$process
->setPty($serverConfig->getPty())
->setTimeout(null)
->setIdleTimeout(null)
->mustRun();
try {
$process = new Process($sshCommand);
$process
->setPty($serverConfig->getPty())
->setTimeout(null)
->setIdleTimeout(null)
->mustRun();
} catch (ProcessFailedException $exception) {
$errorMessage = \Deployer\isVerbose() ? $exception->getMessage() : $process->getErrorOutput();
throw new \RuntimeException($errorMessage);
}

return $process->getOutput();
}
Expand Down Expand Up @@ -159,11 +165,16 @@ public function scpCopy($target, $target2)

$scpCommand = 'scp ' . implode(' ', $scpOptions) . ' ' . escapeshellarg($target) . ' ' . escapeshellarg($target2);

$process = new Process($scpCommand);
$process
->setTimeout(null)
->setIdleTimeout(null)
->mustRun();
try {
$process = new Process($scpCommand);
$process
->setTimeout(null)
->setIdleTimeout(null)
->mustRun();
} catch (ProcessFailedException $exception) {
$errorMessage = \Deployer\isVerbose() ? $exception->getMessage() : $process->getErrorOutput();
throw new \RuntimeException($errorMessage);
}

return $process->getOutput();
}
Expand Down Expand Up @@ -269,7 +280,10 @@ public function initMultiplexing()
if (\Deployer\isVerbose()) {
\Deployer\writeln(' SSH multiplexing initialization');
}
exec('ssh ' . implode(' ', $sshOptions) . ' ' . escapeshellarg($username . $hostname) . " 'echo \"SSH multiplexing initialization\"' ");
exec('ssh ' . implode(' ', $sshOptions) . ' ' . escapeshellarg($username . $hostname) . " 'echo \"SSH multiplexing initialization\"' 2>&1", $output, $returnStatus);
if ($returnStatus !== 0) {
throw new \RuntimeException(implode("\n", $output));
}
}
}
}

0 comments on commit 36a4771

Please sign in to comment.