From 20a3357b1c7c7cc7f2a591bbac75ce074e364d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=BA=E8=83=BD=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Wed, 25 Dec 2024 23:14:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=BC=95=E7=94=A8=E4=BA=86?= =?UTF-8?q?=E6=98=9F=E5=B0=98SDK=E7=9A=84APP=E3=80=82=E8=BF=99=E7=B1=BBAPP?= =?UTF-8?q?=E8=87=AA=E5=B8=A6=E6=80=A7=E8=83=BD=E4=B8=8A=E6=8A=A5=EF=BC=8C?= =?UTF-8?q?=E6=97=A0=E9=9C=80Deploy=E4=B8=8A=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Stardust/Deployment/ZipDeploy.cs | 1 - Stardust/Managers/ServiceController.cs | 62 ++++++++++++++++++-------- 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/Stardust/Deployment/ZipDeploy.cs b/Stardust/Deployment/ZipDeploy.cs index 1f490982..adc37553 100644 --- a/Stardust/Deployment/ZipDeploy.cs +++ b/Stardust/Deployment/ZipDeploy.cs @@ -1,5 +1,4 @@ using System.Diagnostics; -using System.Xml.Serialization; using NewLife; using NewLife.Log; using Stardust.Models; diff --git a/Stardust/Managers/ServiceController.cs b/Stardust/Managers/ServiceController.cs index 00ba08e9..715ab1a0 100644 --- a/Stardust/Managers/ServiceController.cs +++ b/Stardust/Managers/ServiceController.cs @@ -62,6 +62,9 @@ internal class ServiceController : DisposeBase /// 事件客户端 public IEventProvider? EventProvider { get; set; } + /// 是否引用了星尘SDK的APP。这类APP自带性能上报,无需Deploy上报 + public Boolean IsStarApp { get; set; } + private String? _fileName; private String? _workdir; private TimerX? _timer; @@ -148,24 +151,29 @@ public Boolean Start() case ServiceModes.Multiple: break; case ServiceModes.Extract: - WriteLog("解压后不运行,外部主机(如IIS)将托管应用"); - Extract(src, args, workDir, false); - Running = true; - return true; + { + WriteLog("解压后不运行,外部主机(如IIS)将托管应用"); + var deploy = Extract(src, args, workDir, false); + CheckStarApp(deploy.Shadow, workDir); + Running = true; + return true; + } case ServiceModes.ExtractAndRun: - WriteLog("解压后在工作目录运行"); - var deploy = Extract(src, args, workDir, false); - if (deploy == null) throw new Exception("解压缩失败"); - - //file ??= deploy.ExecuteFile; - var runfile = deploy.FindExeFile(workDir); - file = runfile?.FullName; - if (file.IsNullOrEmpty()) throw new Exception("无法找到启动文件"); - - args = deploy.Arguments; - //_fileName = deploy.ExecuteFile; - isZip = false; - break; + { + WriteLog("解压后在工作目录运行"); + var deploy = Extract(src, args, workDir, false); + if (deploy == null) throw new Exception("解压缩失败"); + + //file ??= deploy.ExecuteFile; + var runfile = deploy.FindExeFile(workDir); + file = runfile?.FullName; + if (file.IsNullOrEmpty()) throw new Exception("无法找到启动文件"); + + args = deploy.Arguments; + //_fileName = deploy.ExecuteFile; + isZip = false; + break; + } case ServiceModes.RunOnce: //service.Enable = false; break; @@ -181,6 +189,7 @@ public Boolean Start() if (p == null) return false; WriteLog("启动成功 PID={0}/{1}", p.Id, p.ProcessName); + CheckStarApp(Path.GetDirectoryName(_fileName), workDir); if (service.Mode == ServiceModes.RunOnce) { @@ -244,6 +253,7 @@ public Boolean Start() //deploy.Extract(workDir); // 要解压缩到影子目录,否则可能会把appsettings.json等配置文件覆盖。用完后删除 var shadow = deploy.CreateShadow($"{deploy.Name}-{DateTime.Now:yyyyMMddHHmmss}"); + deploy.Shadow = shadow; deploy.Extract(shadow, CopyModes.ClearBeforeCopy, CopyModes.SkipExists, CopyModes.Overwrite); try { @@ -437,6 +447,22 @@ public Boolean Start() return p; } + private void CheckStarApp(String exeDir, String workDir) + { + // 是否引用了星尘SDK的APP。这类APP自带性能上报,无需Deploy上报 + IsStarApp = false; + var starFile = exeDir.CombinePath("Stardust.dll").GetFullPath(); + if (File.Exists(starFile)) + { + IsStarApp = true; + } + else + { + starFile = workDir.CombinePath("Stardust.dll").GetFullPath(); + if (File.Exists(starFile)) IsStarApp = true; + } + } + /// 停止应用,等待一会确认进程已退出 /// public void Stop(String reason) @@ -602,7 +628,7 @@ public Boolean Check() // 检测并上报性能 p = Process; - if (p != null && EventProvider is StarClient client) + if (p != null && EventProvider is StarClient client && !IsStarApp) { if (_appInfo == null || _appInfo.Id != p.Id) _appInfo = new AppInfo(p) { AppName = inf.Name };