Skip to content

Commit 369d24f

Browse files
committed
IApplicationLifetime stopped
1 parent c3cd536 commit 369d24f

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/Surging.Core/Surging.Core.ServiceHosting.Extensions/ServiceHostModule.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Surging.Core.CPlatform.Runtime.Server;
77
using Surging.Core.ServiceHosting.Extensions.Runtime;
88
using Surging.Core.ServiceHosting.Extensions.Runtime.Implementation;
9+
using Surging.Core.ServiceHosting.Internal;
910
using System;
1011
using System.Threading;
1112
using System.Threading.Tasks;
@@ -36,6 +37,10 @@ public override void Initialize(AppModuleContext context)
3637
entry.Behavior.StopAsync(cts.Token);
3738
}
3839
});
40+
serviceProvider.GetInstances<IApplicationLifetime>().ApplicationStopped.Register(async () =>
41+
{
42+
await entry.Behavior.StopAsync(cts.Token);
43+
});
3944
}
4045
});
4146
}

src/Surging.Core/Surging.Core.ServiceHosting/Internal/Implementation/ConsoleLifetime.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,20 @@ public Task WaitForStartAsync(CancellationToken cancellationToken)
2323
{
2424
Console.WriteLine("服务已启动。 按下Ctrl + C关闭。");
2525
});
26-
26+
27+
AppDomain.CurrentDomain.ProcessExit += (sender, eventArgs) =>
28+
{
29+
ApplicationLifetime.StopApplication();
30+
//阻止程序主线程自动退出,等待退出信号
31+
_shutdownBlock.WaitOne();
32+
};
33+
//按下Ctrl+C退出程序
34+
Console.CancelKeyPress += (sender, e) =>
35+
{
36+
e.Cancel = true;
37+
_shutdownBlock.Set();
38+
ApplicationLifetime.StopApplication();
39+
};
2740
return Task.CompletedTask;
2841
}
2942

src/Surging.Tools/Surging.Tools.Cli2/Commands/RunCommand.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class RunCommand
4949
[Option("-p|--path", "Multiple business module paths", CommandOptionType.MultipleValue)]
5050
public string[] Path { get; }
5151

52+
[Option("--rootpath", "scan root path", CommandOptionType.SingleValue)]
53+
public string RootPath { get; }
54+
5255
[Option("-a|--address", "registry center address default 127.0.0.1:8500", CommandOptionType.SingleValue)]
5356
public string Address { get; set; }
5457

@@ -136,6 +139,8 @@ private void ConfigureEnvironment()
136139
{
137140
if (!Address.IsNullOrEmpty())
138141
Environment.SetEnvironmentVariable("Register_Conn", Address);
142+
if(Path !=null)
143+
Environment.SetEnvironmentVariable("ModulePaths", string.Join('|', Path));
139144
}
140145

141146
private void Configure()
@@ -151,7 +156,9 @@ private void Configure()
151156
AppConfig.ServerOptions.Ports.WSPort = WSPort.Value;
152157
if (GrpcPort != null)
153158
AppConfig.ServerOptions.Ports.GrpcPort = GrpcPort.Value;
154-
159+
if(RootPath != null)
160+
AppConfig.ServerOptions.RootPath = RootPath;
161+
155162
foreach (var item in AppConfig.ServerOptions.Packages)
156163
{
157164
if (item.TypeName == "EnginePartModule")

src/Surging.Tools/Surging.Tools.Cli2/SurgingServiceEngine.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.IO;
66
using System.Text;
7+
using static System.Runtime.InteropServices.JavaScript.JSType;
78

89
namespace Surging.Tools.Cli2
910
{
@@ -18,6 +19,8 @@ public SurgingServiceEngine()
1819
ComponentServiceLocationFormats = new[] {
1920
EnvironmentHelper.GetEnvironmentVariable("${ComponentPath1}|Components"),
2021
};
22+
ModulePaths= EnvironmentHelper.GetEnvironmentVariable("${ModulePaths}|").Split( "|");
23+
ComponentPaths = EnvironmentHelper.GetEnvironmentVariable("${ComponentPaths}|").Split("|");
2124
//ModuleServiceLocationFormats = new[] {
2225
// ""
2326
//};

0 commit comments

Comments
 (0)