添加 重启命令
This commit is contained in:
parent
a449913039
commit
d1f07c80c7
46
app/Console/Commands/Cluster/Restart.php
Normal file
46
app/Console/Commands/Cluster/Restart.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands\Cluster;
|
||||||
|
|
||||||
|
use App\Support\Cluster;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Symfony\Component\Console\Command\Command as CommandAlias;
|
||||||
|
|
||||||
|
class Restart extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'cluster:restart {service}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = '重启集群服务,支持的 service 有 web 和 all。';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function handle(): int
|
||||||
|
{
|
||||||
|
// 检测 service 参数
|
||||||
|
$service = $this->argument('service');
|
||||||
|
|
||||||
|
if (!in_array($service, ['web', 'all'])) {
|
||||||
|
$this->error('service 参数错误,只能是 web 或 all。');
|
||||||
|
return CommandAlias::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Cluster::publish('cluster.restart.' . $service);
|
||||||
|
|
||||||
|
$this->info('已经向集群广播重启命令,等待集群响应。');
|
||||||
|
|
||||||
|
return CommandAlias::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
@ -172,7 +172,21 @@ private function dispatchEvent($event, $message = []): void
|
|||||||
|
|
||||||
$this->info('配置文件更新完成。');
|
$this->info('配置文件更新完成。');
|
||||||
|
|
||||||
}
|
},
|
||||||
|
'cluster.restart.web' => function () {
|
||||||
|
$this->info('正在重启 Web。');
|
||||||
|
|
||||||
|
exec('supervisorctl restart lae-web:*');
|
||||||
|
|
||||||
|
$this->info('Web 重启完成。');
|
||||||
|
},
|
||||||
|
'cluster.restart.all' => function () {
|
||||||
|
$this->info('正在重启整个莱云。');
|
||||||
|
|
||||||
|
exec('supervisorctl restart all');
|
||||||
|
|
||||||
|
$this->info('整个莱云 重启完成。');
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (isset($events[$event])) {
|
if (isset($events[$event])) {
|
||||||
|
Loading…
Reference in New Issue
Block a user