Skip to content

Commit 23fa2c1

Browse files
add systemd extension
1 parent ee7e3d6 commit 23fa2c1

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

src/Microstack.Daemon.WindowsService/Microstack.Daemon.WindowsService.csproj renamed to src/Microstack.Daemon.WindowsService/Microstack.Daemon.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
<ItemGroup>
99
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.8" />
10+
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="3.1.8" />
1011
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="3.1.8" />
1112
<PackageReference Include="Microsoft.Windows.Compatibility" Version="3.1.1" />
1213
<PackageReference Include="protobuf-net" Version="3.0.29" />
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Runtime.InteropServices;
45
using System.Threading;
56
using System.Threading.Tasks;
67
using Microsoft.Extensions.DependencyInjection;
78
using Microsoft.Extensions.Hosting;
89

910
namespace Microstack.Daemon.WindowsService
1011
{
11-
public class Program
12+
public static class Program
1213
{
1314
public static void Main(string[] args)
1415
{
@@ -18,11 +19,21 @@ public static void Main(string[] args)
1819

1920
public static IHostBuilder CreateHostBuilder(string[] args) =>
2021
Host.CreateDefaultBuilder(args)
21-
.UseWindowsService()
22+
.UsePlatformSpecificHostService()
2223
.ConfigureServices((hostContext, services) =>
2324
{
2425
services.AddHostedService<MicroStackListner>();
2526
services.AddSingleton<ProcessStateManager>();
2627
});
28+
29+
public static IHostBuilder UsePlatformSpecificHostService(this IHostBuilder builder)
30+
{
31+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
32+
return builder.UseWindowsService();
33+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
34+
return builder.UseSystemd();
35+
36+
return builder;
37+
}
2738
}
2839
}

src/Microstack.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microstack.CLI", "Microstac
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microstack.Configuration", "Microstack.Configuration\Microstack.Configuration.csproj", "{19427CFF-BBC6-4BC1-A4EF-208C48E1FC27}"
99
EndProject
10-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microstack.Daemon.WindowsService", "Microstack.Daemon.WindowsService\Microstack.Daemon.WindowsService.csproj", "{EB09900D-1E87-42C4-936E-84CBF8BBB3EC}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microstack.Daemon", "Microstack.Daemon.WindowsService\Microstack.Daemon.csproj", "{EB09900D-1E87-42C4-936E-84CBF8BBB3EC}"
1111
EndProject
1212
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microstack.Git", "Microstack.git\Microstack.Git.csproj", "{1B30B3D7-901E-4C80-9B92-7342760DD448}"
1313
EndProject
@@ -17,7 +17,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microstack.API", "Microstac
1717
EndProject
1818
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microstack.Tests", "..\tests\Microstack.Tests.csproj", "{4C7DE51C-7748-44D8-A7C6-8196949900C3}"
1919
EndProject
20-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microstack.Common", "Microstack.Common\Microstack.Common.csproj", "{A8957924-FCB4-46A5-8489-39F878CD032A}"
20+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microstack.Common", "Microstack.Common\Microstack.Common.csproj", "{A8957924-FCB4-46A5-8489-39F878CD032A}"
2121
EndProject
2222
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "testapp", "testapp", "{18E368A5-9AA6-437E-A60D-3AD94A758D3D}"
2323
EndProject

tests/CommandLineTests/ProgramTest.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ public Task StartHost(string[] args, CancellationTokenSource cts)
2323

2424
public Task StartDaemon()
2525
{
26-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
27-
{
28-
return Microstack.Daemon.WindowsService.Program.CreateHostBuilder(new string[] { }).Build().RunAsync();
29-
}
30-
return Task.CompletedTask;
26+
return Microstack.Daemon.WindowsService.Program.CreateHostBuilder(new string[] { }).Build().RunAsync();
3127
}
3228
}
3329
}

tests/microstack.tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<PackageReference Include="FluentAssertions" Version="5.10.3" />
1717
<PackageReference Include="Moq" Version="4.14.5" />
1818
<ProjectReference Include="..\src\Microstack.API\Microstack.API.csproj" />
19-
<ProjectReference Include="..\src\Microstack.Daemon.WindowsService\Microstack.Daemon.WindowsService.csproj" />
19+
<ProjectReference Include="..\src\Microstack.Daemon.WindowsService\Microstack.Daemon.csproj" />
2020

2121
<ProjectReference Include="..\src\Microstack.Git\Microstack.Git.csproj" />
2222
<ProjectReference Include="..\src\Microstack.Configuration\Microstack.Configuration.csproj" />

0 commit comments

Comments
 (0)