From c57f84e1b1e380cbe58fc8dbae049fa56063bdae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8C=BF=E4=BA=BA=E6=98=93?= Date: Wed, 4 Dec 2024 11:15:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=20MyStarClient=20=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E4=BF=A1=E6=81=AF=EF=BC=8C=E4=BC=98=E5=8C=96=20MyServ?= =?UTF-8?q?ice=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 `MyStarClient.cs` 文件中,删除了注释 `// 重新拉起进程`,并调整了日志信息的内容。 在 `Program.cs` 文件中,增加了 `using NewLife.Agent.Models;` 和 `using ServiceModel = NewLife.Agent.Models.ServiceModel;` 的引用。 在 `Program.cs` 文件中,修改了 `MyService` 类的代码,将 `Host.Install` 方法的参数从多个独立参数改为一个 `ServiceModel` 对象。 --- StarAgent/MyStarClient.cs | 1 - StarAgent/Program.cs | 13 ++++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/StarAgent/MyStarClient.cs b/StarAgent/MyStarClient.cs index b1f34c7..5d86d2b 100644 --- a/StarAgent/MyStarClient.cs +++ b/StarAgent/MyStarClient.cs @@ -108,7 +108,6 @@ protected override void Restart(Upgrade upgrade) } else { - // 重新拉起进程 this.WriteInfoEvent("Upgrade", "强制更新完成,准备拉起新进程!PID=" + pid); // 重新拉起进程,重启服务,否则采取拉起进程的方式 diff --git a/StarAgent/Program.cs b/StarAgent/Program.cs index 7367a57..1048e2a 100644 --- a/StarAgent/Program.cs +++ b/StarAgent/Program.cs @@ -2,6 +2,7 @@ using System.Reflection; using NewLife; using NewLife.Agent; +using NewLife.Agent.Models; using NewLife.Log; using NewLife.Model; using NewLife.Reflection; @@ -14,6 +15,7 @@ using Stardust.Models; using Stardust.Plugins; using IHost = NewLife.Agent.IHost; +using ServiceModel = NewLife.Agent.Models.ServiceModel; namespace StarAgent; @@ -180,7 +182,16 @@ private void FixKillMode(SystemdSetting set) exe = dll; } - Host.Install(ServiceName, DisplayName, exe, "-s", Description); + var service = new ServiceModel + { + ServiceName = ServiceName, + DisplayName = DisplayName, + Description = Description, + FileName = exe, + Arguments = "-s", + }; + + Host.Install(service); } } }