From beb65630607d75668049e2612fd9fe82c3aec5e2 Mon Sep 17 00:00:00 2001 From: "zhaowei.huang" <228127304@qq.com> Date: Sat, 25 Jul 2026 18:45:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=20SimpleLite=20=E5=90=AF?= =?UTF-8?q?=E5=81=9C=E6=8E=A7=E5=88=B6=E4=B8=8E=E6=9C=8D=E5=8A=A1=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E9=A1=B5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 拆分 StopAll/Restart,运维代理透传确认头与用户信息,服务状态页可更稳地重启进程。 Co-authored-by: Cursor --- MiGu.Server/Controllers/OpsController.cs | 4 + MiGu.Server/Launcher/SimpleLiteLauncher.cs | 31 +++-- .../src/views/ServiceStatusView.vue | 118 ++++++++++++++---- 3 files changed, 123 insertions(+), 30 deletions(-) diff --git a/MiGu.Server/Controllers/OpsController.cs b/MiGu.Server/Controllers/OpsController.cs index 6d11299..8f2b2ed 100644 --- a/MiGu.Server/Controllers/OpsController.cs +++ b/MiGu.Server/Controllers/OpsController.cs @@ -133,6 +133,10 @@ public class OpsController : ControllerBase // 即使 SimpleLite 默认放行 loopback,也带上 internal token,兼容其严格模式(AllowLoopback=false)。 if (!string.IsNullOrEmpty(_internalToken.Token)) msg.Headers.TryAddWithoutValidation("X-Platform-Internal-Token", _internalToken.Token); + // 运维面板已对 needConfirm 动作做过二次确认;内核 RequiresPlatformConfirm 方法需此头。 + msg.Headers.TryAddWithoutValidation("X-Platform-Confirmed", "1"); + if (!string.IsNullOrWhiteSpace(user)) + msg.Headers.TryAddWithoutValidation("X-Platform-User", user); using var resp = await client.SendAsync(msg); var body = await resp.Content.ReadAsStringAsync(); var success = resp.IsSuccessStatusCode && ParseSuccess(body); diff --git a/MiGu.Server/Launcher/SimpleLiteLauncher.cs b/MiGu.Server/Launcher/SimpleLiteLauncher.cs index d9055c5..f8bac00 100644 --- a/MiGu.Server/Launcher/SimpleLiteLauncher.cs +++ b/MiGu.Server/Launcher/SimpleLiteLauncher.cs @@ -349,11 +349,10 @@ public sealed class SimpleLiteLauncher : IDisposable /// 写 active-scenes.json 的结果(供向导保存接口回显)。 public readonly record struct ActiveScenesWriteResult(bool Ok, string? Path, string? Error); - /// - /// 关闭所有 SimpleLite 进程、同步 obj→bin 最新 DLL,再按 launchMode 重新拉起。 - /// - public LaunchResult RestartForUpdate(string launchMode = "webonly") + /// 终止本机全部 SimpleLite 进程并清理 MiGu.Server 侧托管引用。 + public int StopAll() { + var killed = 0; foreach (var proc in Process.GetProcessesByName("SimpleLite")) { try @@ -361,12 +360,13 @@ public sealed class SimpleLiteLauncher : IDisposable if (!proc.HasExited) { proc.Kill(entireProcessTree: true); - _log.LogInformation("[SimpleLite] restart-for-update: killed pid={Pid}", proc.Id); + killed++; + _log.LogInformation("[SimpleLite] stop: killed pid={Pid}", proc.Id); } } catch (Exception ex) { - _log.LogWarning("[SimpleLite] restart-for-update: kill pid={Pid} failed: {Msg}", proc.Id, ex.Message); + _log.LogWarning("[SimpleLite] stop: kill pid={Pid} failed: {Msg}", proc.Id, ex.Message); } finally { @@ -374,7 +374,7 @@ public sealed class SimpleLiteLauncher : IDisposable } } - Thread.Sleep(1500); + if (killed > 0) Thread.Sleep(1500); lock (_sync) { @@ -382,6 +382,23 @@ public sealed class SimpleLiteLauncher : IDisposable _lastLaunchMode = null; } + return killed; + } + + /// 关闭全部 SimpleLite 后按 launchMode 重新拉起(不同步 DLL)。 + public LaunchResult Restart(string launchMode = "webonly") + { + StopAll(); + return MaybeStart(launchMode); + } + + /// + /// 关闭所有 SimpleLite 进程、同步 obj→bin 最新 DLL,再按 launchMode 重新拉起。 + /// + public LaunchResult RestartForUpdate(string launchMode = "webonly") + { + StopAll(); + var synced = SimpleLiteBuildSync.TrySyncFromObjToBin(_env.ContentRootPath, _log); var result = MaybeStart(launchMode); if (!synced && result.Warning == null) diff --git a/frontends/apps/simple-platform-vue/src/views/ServiceStatusView.vue b/frontends/apps/simple-platform-vue/src/views/ServiceStatusView.vue index ecaec03..03d57c1 100644 --- a/frontends/apps/simple-platform-vue/src/views/ServiceStatusView.vue +++ b/frontends/apps/simple-platform-vue/src/views/ServiceStatusView.vue @@ -43,6 +43,28 @@ +
+
SimpleLite 操作
+
+ + 重启 SimpleLite + + + 关闭 SimpleLite + +
+

将终止本机全部 SimpleLite 进程;重启后按当前启动模式重新拉起。

+
+
刷新 返回 @@ -54,34 +76,29 @@