添加 重启命令

This commit is contained in:
iVampireSP.com 2023-01-05 03:38:46 +08:00
parent a449913039
commit d1f07c80c7
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 61 additions and 1 deletions

View 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;
}
}

View File

@ -172,7 +172,21 @@ private function dispatchEvent($event, $message = []): void
$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])) {