Skip to content

Commit

Permalink
Add windows service support.
Browse files Browse the repository at this point in the history
  • Loading branch information
harrison314 committed Mar 12, 2023
1 parent dd27859 commit b6a3993
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ or during network calls.
* [Suports mechanisms](/Doc/SuportedAlgorithms.md)
* Same behavior and algorithm support across platforms and versions of Linux operating systems.
* Native PKCS#11 library without dependencies (no dependency hell, no permision configuration).
* _BouncyHsm_ runs on _Raspberry Pi Zero 2 W_.
* _BouncyHsm_ runs on _Raspberry Pi Zero 2 W_, or as [Windows service](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-6.0&tabs=netcore-cli).

## Contributing and issues
Pull requests are welcome. If you are not sure about the change, open an issue first.
Expand Down
1 change: 1 addition & 0 deletions src/Src/BouncyHsm/BouncyHsm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.1" />
<PackageReference Include="NSwag.AspNetCore" Version="13.18.2" />
<PackageReference Include="Serilog.Sinks.Seq" Version="5.2.2" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
Expand Down
11 changes: 10 additions & 1 deletion src/Src/BouncyHsm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using BouncyHsm.Infrastructure;
using BouncyHsm.Infrastructure.Application;
using BouncyHsm.Services.Configuration;
using Microsoft.Extensions.Hosting.WindowsServices;
using Serilog;
using System.Runtime.CompilerServices;
using System.Text.Json;
Expand All @@ -12,7 +13,14 @@ public class Program
{
public static void Main(string[] args)
{
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
WebApplicationOptions webApplicationOptions = new WebApplicationOptions()
{
Args = args,
ContentRootPath = WindowsServiceHelpers.IsWindowsService()
? AppContext.BaseDirectory : default
};

WebApplicationBuilder builder = WebApplication.CreateBuilder(webApplicationOptions);
#if DEBUG
builder.Host.UseDefaultServiceProvider((hotBuilder, options) =>
{
Expand Down Expand Up @@ -48,6 +56,7 @@ public static void Main(string[] args)
cfg.UseRouteNameAsOperationId = true;
});

builder.Host.UseWindowsService();

builder.Services.AddP11Handlers();
builder.Services.AddHostedService<Infrastructure.HostedServices.TcpHostedService>();
Expand Down

0 comments on commit b6a3993

Please sign in to comment.