From 3998e38411c2e71a89cddbabb6aa753088678e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Sun, 17 Nov 2024 20:01:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A5=E6=9C=8D=E5=8A=A1=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E6=97=B6=EF=BC=8C=E9=87=8D=E5=90=AF=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=EF=BC=8C=E5=90=A6=E5=88=99=E9=87=87=E5=8F=96=E6=8B=89?= =?UTF-8?q?=E8=B5=B7=E8=BF=9B=E7=A8=8B=E7=9A=84=E6=96=B9=E5=BC=8F=EF=BC=9B?= =?UTF-8?q?=E5=AE=89=E8=A3=85dotnet=E8=BF=90=E8=A1=8C=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=BC=BA=E8=A1=8C=E5=88=9B=E5=BB=BA=E8=BD=AF=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=EF=BC=8C=E5=8F=AF=E8=83=BDLinux=E6=9C=89=E5=BB=B6=E8=BF=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StarAgent/MyStarClient.cs | 23 ++++++++++++++++++++--- Stardust/Managers/NetRuntime.cs | 1 + 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/StarAgent/MyStarClient.cs b/StarAgent/MyStarClient.cs index 0c4b644f..5d86d2b6 100644 --- a/StarAgent/MyStarClient.cs +++ b/StarAgent/MyStarClient.cs @@ -86,8 +86,15 @@ protected override void Restart(Upgrade upgrade) { this.WriteInfoEvent("Upgrade", "强制更新完成,准备重启后台服务!PID=" + pid); - // 使用外部命令重启服务 - var rs = upgrade.Run("StarAgent", "-restart -upgrade"); + // 使用外部命令重启服务。执行重启,如果失败,延迟后再次尝试 + var rs = upgrade.Run("StarAgent", "-restart -upgrade", 3_000); + if (!rs) + { + var delay = 3_000; + this.WriteInfoEvent("Upgrade", $"拉起新进程失败,延迟{delay}ms后重试"); + Thread.Sleep(delay); + rs = upgrade.Run("StarAgent", "-restart -upgrade", 1_000); + } //!! 这里不需要自杀,外部命令重启服务会结束当前进程 if (rs) @@ -101,8 +108,18 @@ protected override void Restart(Upgrade upgrade) } else { - // 重新拉起进程 + this.WriteInfoEvent("Upgrade", "强制更新完成,准备拉起新进程!PID=" + pid); + + // 重新拉起进程,重启服务,否则采取拉起进程的方式 var rs = upgrade.Run("StarAgent", "-run -upgrade"); + if (!rs) + { + var delay = 3_000; + this.WriteInfoEvent("Upgrade", $"拉起新进程失败,延迟{delay}ms后重试"); + Thread.Sleep(delay); + rs = upgrade.Run("StarAgent", "-run -upgrade", 1_000); + } + if (rs) { Service.StopWork("Upgrade"); diff --git a/Stardust/Managers/NetRuntime.cs b/Stardust/Managers/NetRuntime.cs index 725de755..7942516e 100644 --- a/Stardust/Managers/NetRuntime.cs +++ b/Stardust/Managers/NetRuntime.cs @@ -156,6 +156,7 @@ Boolean InstallOnLinux(String fullFile, String? arg) // 建立链接 var link = "/usr/bin/dotnet"; + if (File.Exists(link)) File.Delete(link); if (Force && File.Exists(link)) File.Delete(link); if (!File.Exists(link))