我想运行SSH命令以在Linux上使用Laravel Envoy启动/停止服务器。但是SSH :: into()的语法出现错误。我不知道该怎么办完全卡住了。需要解决此问题并使之起作用的方法。使节设置,并可以使用“ php artisan”命令正常工作:
// Envoy.blade.php
@setup
$connection = ['web' => $user.'@'.$host.' -p '. '22'];
@endsetup
@servers($connection)
@task('foo', ['on' => 'web'])
php artisan
@endtask
命令:特使运行foo --user = root --host = 94.130.97.242
这就是SSH :: into()启动/停止服务器的工作。
// 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 run foo --user = root --host = 94.130.97.242 --password = password --server = 22运行后,会给出错误的语法错误错误的意外令牌“运行时”。我需要你的帮助。谢谢!
这是使用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-asynchronouslyly
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句