Lae/app/Console/Commands/Cluster/Restart.php

48 lines
1.1 KiB
PHP
Raw Normal View History

2023-01-04 19:38:46 +00:00
<?php
namespace App\Console\Commands\Cluster;
2023-01-14 17:21:12 +00:00
use App\Support\ClusterSupport;
2023-01-04 19:38:46 +00:00
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');
2023-02-07 09:04:11 +00:00
if (! in_array($service, ['web', 'all'])) {
2023-01-04 19:38:46 +00:00
$this->error('service 参数错误,只能是 web 或 all。');
2023-01-30 16:14:07 +00:00
2023-01-04 19:38:46 +00:00
return CommandAlias::FAILURE;
}
2023-02-07 09:04:11 +00:00
ClusterSupport::publish('cluster.restart.'.$service);
2023-01-04 19:38:46 +00:00
$this->info('已经向集群广播重启命令,等待集群响应。');
return CommandAlias::SUCCESS;
}
}