改进 init
This commit is contained in:
parent
f6dadf7e75
commit
e38d32692d
@ -107,3 +107,5 @@ DASHBOARD_BIRTHDAY_PATH=/birthdays
|
|||||||
TRUSTED_PROXIES=
|
TRUSTED_PROXIES=
|
||||||
|
|
||||||
NODE_TYPE=master
|
NODE_TYPE=master
|
||||||
|
NODE_ID=
|
||||||
|
NODE_IP=
|
||||||
|
@ -34,7 +34,7 @@ public function handle(): int
|
|||||||
{
|
{
|
||||||
$this->info('正在下载配置。');
|
$this->info('正在下载配置。');
|
||||||
|
|
||||||
$node_type = config('settings.node_type');
|
$node_type = config('settings.node.type');
|
||||||
|
|
||||||
if ($node_type === 'master') {
|
if ($node_type === 'master') {
|
||||||
$confirm = $this->ask('主节点同步将会恢复上一次数据,确定吗?', 'yes');
|
$confirm = $this->ask('主节点同步将会恢复上一次数据,确定吗?', 'yes');
|
||||||
|
@ -31,7 +31,7 @@ class Upload extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
$node_type = config('settings.node_type');
|
$node_type = config('settings.node.type');
|
||||||
|
|
||||||
if ($node_type === 'slave') {
|
if ($node_type === 'slave') {
|
||||||
$this->info('正在同步从节点配置文件。');
|
$this->info('正在同步从节点配置文件。');
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use Symfony\Component\Console\Command\Command as CommandAlias;
|
use Symfony\Component\Console\Command\Command as CommandAlias;
|
||||||
|
|
||||||
class Init extends Command
|
class Init extends Command
|
||||||
@ -29,20 +30,37 @@ class Init extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
$this->info('正在删除 bootstrap/cache 目录。');
|
// 重写 .env 文件中的 NODE_ID
|
||||||
$cache_path = base_path('bootstrap/cache');
|
$this->info('正在重写 .env 文件中的 NODE_ID。');
|
||||||
$files = glob($cache_path . '/*');
|
|
||||||
foreach ($files as $file) {
|
$node_id = Str::random(8);
|
||||||
if (is_file($file)) {
|
|
||||||
unlink($file);
|
if (config('settings.node.type') === 'master') {
|
||||||
}
|
$node_id = 'master';
|
||||||
}
|
}
|
||||||
|
|
||||||
Artisan::call('route:clear');
|
$env = file_get_contents(base_path('.env'));
|
||||||
Artisan::call('config:clear');
|
|
||||||
Artisan::call('view:clear');
|
|
||||||
|
|
||||||
Artisan::call('optimize');
|
$env = preg_replace('/^NODE_ID=.*$/m', 'NODE_ID=' . $node_id, $env);
|
||||||
|
|
||||||
|
file_put_contents(base_path('.env'), $env);
|
||||||
|
|
||||||
|
if (!config('settings.node.ip')) {
|
||||||
|
$this->error('请先配置节点 IP。');
|
||||||
|
return CommandAlias::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 刷新配置缓存
|
||||||
|
$this->info('正在刷新配置缓存。');
|
||||||
|
Artisan::call('config:cache');
|
||||||
|
|
||||||
|
// redis 创建一个 hash
|
||||||
|
$this->info('正在创建 Redis hash。');
|
||||||
|
$redis = app('redis')->connection();
|
||||||
|
$redis->hset('nodes', $node_id, [
|
||||||
|
'type' => config('settings.node.type'),
|
||||||
|
'id' => $node_id,
|
||||||
|
]);
|
||||||
|
|
||||||
return CommandAlias::SUCCESS;
|
return CommandAlias::SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -15,5 +15,9 @@
|
|||||||
'base_url' => env('DASHBOARD_BASE_URL', 'https://dash.laecloud.com'),
|
'base_url' => env('DASHBOARD_BASE_URL', 'https://dash.laecloud.com'),
|
||||||
'birthday_path' => env('DASHBOARD_BIRTHDAY_PATH', '/birthdays'),
|
'birthday_path' => env('DASHBOARD_BIRTHDAY_PATH', '/birthdays'),
|
||||||
],
|
],
|
||||||
'node_type' => env('NODE_TYPE', 'master')
|
'node' => [
|
||||||
|
'type' => env('NODE_TYPE', 'master'),
|
||||||
|
'id' => env('NODE_ID'),
|
||||||
|
'ip' => env('NODE_IP'),
|
||||||
|
]
|
||||||
];
|
];
|
||||||
|
Loading…
Reference in New Issue
Block a user