feat: dev.py 新增 --stop 并支持安装完成后自动切换到开发模式
- 本地 dev 保持前台模型、不引入 PM2;--stop 复用 kill_project_servers 一键停止 - 无 .env 时监听根 .env 出现作为安装成功信号,自动停安装 API 并以正式模式重启 api/client,避开安装中重启 - 安装 API 在 dev 模式下不再退出、迁移失败透传真实原因;前端提交后统一轮询就绪再进后台
This commit is contained in:
@@ -20,8 +20,12 @@ const ENCRYPTED_PREFIX = 'enc:v1:';
|
||||
export class InstallService {
|
||||
status() {
|
||||
const prefillSecrets = process.env.INSTALL_PREFILL_SECRETS === '1';
|
||||
const envPath = envFilePath();
|
||||
const envReady = existsSync(envPath);
|
||||
return {
|
||||
installed: !isInstallMode(),
|
||||
// 本地 --install-mode 调试:.env 已写入但当前进程仍是 InstallAppModule,需重启 dev.py
|
||||
needsDevRestart: process.env.ARTVERIS_INSTALL_MODE === '1' && envReady,
|
||||
defaults: {
|
||||
mysqlHost: process.env.INSTALL_MYSQL_HOST || '127.0.0.1',
|
||||
mysqlPort: Number(process.env.INSTALL_MYSQL_PORT || 3306),
|
||||
@@ -48,7 +52,11 @@ export class InstallService {
|
||||
this.runPrismaMigrate(databaseUrl);
|
||||
await this.seedInstallData(databaseUrl, dto, traceCodeSalt, settingsEncryptionKey);
|
||||
this.writeEnvFile(dto, databaseUrl, traceCodeSalt, settingsEncryptionKey);
|
||||
setTimeout(() => process.exit(0), 600);
|
||||
// 本地安装向导调试(ARTVERIS_INSTALL_MODE=1)不主动退出,避免响应未返回连接被掐断;
|
||||
// 生产环境由 PM2/Docker restart policy 重启以加载新 .env。
|
||||
if (process.env.ARTVERIS_INSTALL_MODE !== '1') {
|
||||
setTimeout(() => process.exit(0), 2500);
|
||||
}
|
||||
return { installed: true, restartRequired: true };
|
||||
}
|
||||
|
||||
@@ -298,10 +306,14 @@ export class InstallService {
|
||||
|
||||
private runPrismaMigrate(databaseUrl: string): void {
|
||||
const prismaBin = require.resolve('prisma/build/index.js');
|
||||
execFileSync(process.execPath, [prismaBin, 'migrate', 'deploy', '--schema', this.prismaSchemaPath()], {
|
||||
stdio: 'inherit',
|
||||
env: { ...process.env, DATABASE_URL: databaseUrl },
|
||||
});
|
||||
try {
|
||||
execFileSync(process.execPath, [prismaBin, 'migrate', 'deploy', '--schema', this.prismaSchemaPath()], {
|
||||
stdio: 'inherit',
|
||||
env: { ...process.env, DATABASE_URL: databaseUrl },
|
||||
});
|
||||
} catch (e) {
|
||||
throw new BusinessException(ErrorCode.BAD_REQUEST, `数据库迁移失败:${this.errorMessage(e)}`);
|
||||
}
|
||||
}
|
||||
|
||||
private prismaSchemaPath(): string {
|
||||
|
||||
Reference in New Issue
Block a user