如何使用 Laravel Envoy 运行 SSH 命令
How to run SSH command using Laravel Envoy
我想 运行 SSH 命令到 start/stop 服务器 Laravel Envoy on Linux。但是 SSH::into() 的语法出现错误。完全卡住了不知道怎么办。需要解决此问题并使其有效的方法。
Envoy 设置并使用 "php artisan" 命令正常工作:
// Envoy.blade.php
@setup
$connection = ['web' => $user.'@'.$host.' -p '. '22'];
@endsetup
@servers($connection)
@task('foo', ['on' => 'web'])
php artisan
@endtask
命令: envoy 运行 foo --user=root --host=94.130.97.242
这就是 SSH::into() 到 start/stop 服务器所做的。
// Envoy.blade.php
@include('vendor/autoload.php')
$connection = ['web' => $user.'@'.$host.' -p '. '22'];
$target = [
'host' => $host,
'username' => $user,
'password' => $password,
'timeout' => 10,
];
Config::set('remote.connections.runtime.host', $target['host']);
Config::set('remote.connections.runtime.port', '22');
Config::set('remote.connections.runtime.username', $target['username']);
Config::set('remote.connections.runtime.password', $target['password']);
@endsetup
@servers($connection)
@task('foo', ['on' => 'web'])
SSH::into('runtime')->run(array(
'docker stop ' . $server
));
@endtask
命令: envoy 运行 foo --user=root --host=94.130.97.242 --password=password --server=22
在 运行ning 之后,它会给出错误语法错误意外标记'运行time'。
我需要你的帮助。谢谢!
这是一种使用 Symfony 进程的方法(在 Laravel 内可用)
use Symfony\Component\Process\Process;
function start(string $user, string $host)
{
$sshSetting = sprintf('ssh://%s@%s', $user, $host);
$process = new Process([
'docker', '-H', $sshSetting, 'start'
]);
$process->run(); //synchronous
$process->mustRun(); //synchronous, throw an exception whenever fail
$process->start(); //asynchronous
}
这里是官方文档https://symfony.com/doc/current/components/process.html#running-processes-asynchronously
我想 运行 SSH 命令到 start/stop 服务器 Laravel Envoy on Linux。但是 SSH::into() 的语法出现错误。完全卡住了不知道怎么办。需要解决此问题并使其有效的方法。 Envoy 设置并使用 "php artisan" 命令正常工作:
// Envoy.blade.php
@setup
$connection = ['web' => $user.'@'.$host.' -p '. '22'];
@endsetup
@servers($connection)
@task('foo', ['on' => 'web'])
php artisan
@endtask
命令: envoy 运行 foo --user=root --host=94.130.97.242
这就是 SSH::into() 到 start/stop 服务器所做的。
// Envoy.blade.php
@include('vendor/autoload.php')
$connection = ['web' => $user.'@'.$host.' -p '. '22'];
$target = [
'host' => $host,
'username' => $user,
'password' => $password,
'timeout' => 10,
];
Config::set('remote.connections.runtime.host', $target['host']);
Config::set('remote.connections.runtime.port', '22');
Config::set('remote.connections.runtime.username', $target['username']);
Config::set('remote.connections.runtime.password', $target['password']);
@endsetup
@servers($connection)
@task('foo', ['on' => 'web'])
SSH::into('runtime')->run(array(
'docker stop ' . $server
));
@endtask
命令: envoy 运行 foo --user=root --host=94.130.97.242 --password=password --server=22 在 运行ning 之后,它会给出错误语法错误意外标记'运行time'。 我需要你的帮助。谢谢!
这是一种使用 Symfony 进程的方法(在 Laravel 内可用)
use Symfony\Component\Process\Process;
function start(string $user, string $host)
{
$sshSetting = sprintf('ssh://%s@%s', $user, $host);
$process = new Process([
'docker', '-H', $sshSetting, 'start'
]);
$process->run(); //synchronous
$process->mustRun(); //synchronous, throw an exception whenever fail
$process->start(); //asynchronous
}
这里是官方文档https://symfony.com/doc/current/components/process.html#running-processes-asynchronously