改进 复制方便,每次启动都重置 NODE_ID

This commit is contained in:
iVampireSP.com 2023-01-05 02:42:58 +08:00
parent c9c65aaafe
commit 76acbaea49
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132

View File

@ -38,24 +38,22 @@ public function handle(): int
return CommandAlias::FAILURE; return CommandAlias::FAILURE;
} }
// if not node_id
if (!config('settings.node.id')) {
// 重写 .env 文件中的 NODE_ID
$this->info('正在重写 .env 文件中的 NODE_ID。');
$node_id = Str::random(8); // 重写 .env 文件中的 NODE_ID
$this->info('正在重写 .env 文件中的 NODE_ID。');
if (config('settings.node.type') === 'master') { $node_id = Str::random(8);
$node_id = 'master';
}
$env = file_get_contents(base_path('.env')); if (config('settings.node.type') === 'master') {
$node_id = 'master';
$env = preg_replace('/^NODE_ID=.*$/m', 'NODE_ID=' . $node_id, $env);
file_put_contents(base_path('.env'), $env);
} }
$env = file_get_contents(base_path('.env'));
$env = preg_replace('/^NODE_ID=.*$/m', 'NODE_ID=' . $node_id, $env);
file_put_contents(base_path('.env'), $env);
// 刷新配置缓存 // 刷新配置缓存
$this->info('正在刷新配置缓存。'); $this->info('正在刷新配置缓存。');