[fix] 精确设置每个进程的StarAppId,避免不同进程重启时使用错误AppId。每次获取到的AppId,都保存到配置,避免下次本地重启时没能使用最新的AppId

This commit is contained in:
智能大石头 2025-05-14 08:00:15 +08:00
parent fbdb3a7038
commit 6a3f6c1378
4 changed files with 28 additions and 5 deletions

View File

@ -12,6 +12,9 @@ public class ZipDeploy
/// <summary>应用名称</summary>
public String Name { get; set; } = null!;
/// <summary>应用编码</summary>
public String? AppId { get; set; }
/// <summary>文件名</summary>
public String? FileName { get; set; }
@ -114,7 +117,7 @@ public class ZipDeploy
// }
// WriteLog("参数路径补全 {0}", args[i]);
//}
// 其它参数全要,支持 urls=http://*:8000
gs[i] = args[i];
}
@ -260,6 +263,9 @@ public class ZipDeploy
};
si.EnvironmentVariables["BasePath"] = rundir.FullName;
if (!AppId.IsNullOrEmpty())
si.EnvironmentVariables["StarAppId"] = AppId;
if (runfile.Extension.EqualIgnoreCase(".dll"))
{
si.FileName = "dotnet";

View File

@ -26,6 +26,9 @@ public class ServiceController : DisposeBase
/// <summary>服务名</summary>
public String Name { get; set; } = null!;
/// <summary>应用编码</summary>
public String? AppId { get; set; }
/// <summary>进程ID</summary>
public Int32 ProcessId { get; set; }
@ -143,8 +146,8 @@ public class ServiceController : DisposeBase
// 在环境变量中设置BasePath不用担心影响当前进程因为PathHelper仅读取一次
//Environment.SetEnvironmentVariable("BasePath", workDir);
if (DeployInfo != null && !DeployInfo.Name.IsNullOrEmpty())
Environment.SetEnvironmentVariable("StarAppId", DeployInfo.Name);
//if (DeployInfo != null && !DeployInfo.Name.IsNullOrEmpty())
// Environment.SetEnvironmentVariable("StarAppId", DeployInfo.Name);
// 工作模式
switch (service.Mode)
@ -235,6 +238,7 @@ public class ServiceController : DisposeBase
var deploy = new ZipDeploy
{
Name = Name,
AppId = AppId,
FileName = file,
WorkingDirectory = workDir,
@ -286,6 +290,7 @@ public class ServiceController : DisposeBase
var deploy = new ZipDeploy
{
Name = Name,
AppId = AppId,
FileName = file,
WorkingDirectory = workDir,
UserName = service.UserName,
@ -355,6 +360,9 @@ public class ServiceController : DisposeBase
};
si.EnvironmentVariables["BasePath"] = workDir;
if (!AppId.IsNullOrEmpty())
si.EnvironmentVariables["StarAppId"] = AppId;
// 环境变量。不能用于ShellExecute
if (service.Environments.IsNullOrEmpty() && !si.UseShellExecute)
{

View File

@ -269,7 +269,11 @@ public class ServiceManager : DisposeBase
controller.EventProvider = _client;
controller.SetInfo(service);
if (deploy != null) controller.DeployInfo = deploy;
if (deploy != null)
{
controller.DeployInfo = deploy;
controller.AppId = deploy.Name;
}
return controller.Check();
}
@ -277,6 +281,7 @@ public class ServiceManager : DisposeBase
controller = new ServiceController
{
Name = service.Name,
AppId = deploy?.Name,
//Info = service,
DeployInfo = deploy,

View File

@ -217,7 +217,11 @@ public class StarFactory : DisposeBase
if (AppId.IsNullOrEmpty()) AppId = set.AppKey;
if (Secret.IsNullOrEmpty()) Secret = set.Secret;
if (flag) set.Save();
// 重新写回配置文件
set.Server = Server;
set.AppKey = AppId;
set.Secret = Secret;
set.Save();
// 生成ClientId用于唯一标识当前实例默认IP@pid
try