Add Windows Service support and version update
Updated project version to 2.2.0-beta. Added support for running the application as a Windows Service using `Microsoft.Extensions.Hosting.WindowsServices`. Introduced `WindowsServiceHostingOptions` for configuration, including `Enabled` and `ServiceName` properties. Added a new configuration section in `appsettings.json` for Windows Service settings. Integrated service management logic in `Program.cs`. Included a batch script `manage-service.bat` for installing, uninstalling, and managing the Windows Service.
This commit is contained in:
@@ -10,9 +10,9 @@
|
|||||||
<Authors>Digital Data GmbH</Authors>
|
<Authors>Digital Data GmbH</Authors>
|
||||||
<Company>Digital Data GmbH</Company>
|
<Company>Digital Data GmbH</Company>
|
||||||
<Product>EnvelopeGenerator.Server</Product>
|
<Product>EnvelopeGenerator.Server</Product>
|
||||||
<Version>2.1.0-beta</Version>
|
<Version>2.2.0-beta</Version>
|
||||||
<FileVersion>2.1.0.0</FileVersion>
|
<FileVersion>2.2.0.0</FileVersion>
|
||||||
<AssemblyVersion>2.1.0.0</AssemblyVersion>
|
<AssemblyVersion>2.2.0.0</AssemblyVersion>
|
||||||
<Copyright>Copyright © 2026 Digital Data GmbH. All rights reserved.</Copyright>
|
<Copyright>Copyright © 2026 Digital Data GmbH. All rights reserved.</Copyright>
|
||||||
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
|
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
<!-- API Packages from EnvelopeGenerator.Server -->
|
<!-- API Packages from EnvelopeGenerator.Server -->
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.11" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.11" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.1" />
|
||||||
<PackageReference Include="AspNetCore.Scalar" Version="1.1.8" />
|
<PackageReference Include="AspNetCore.Scalar" Version="1.1.8" />
|
||||||
<PackageReference Include="DigitalData.Auth.Claims" Version="1.0.3" />
|
<PackageReference Include="DigitalData.Auth.Claims" Version="1.0.3" />
|
||||||
<PackageReference Include="DigitalData.Auth.Client" Version="1.3.7" />
|
<PackageReference Include="DigitalData.Auth.Client" Version="1.3.7" />
|
||||||
@@ -64,6 +65,10 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Update="scripts\windows-service\manage-service.bat">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||||
|
</None>
|
||||||
<Content Update="wwwroot\docs\privacy-policy.en-US.html">
|
<Content Update="wwwroot\docs\privacy-policy.en-US.html">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
namespace EnvelopeGenerator.Server.Options;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public sealed class WindowsServiceHostingOptions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public const string SectionName = "WindowsServiceHosting";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public bool Enabled { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string ServiceName { get; set; } = "Digital Data Envelope Generator Server";
|
||||||
|
}
|
||||||
@@ -85,6 +85,19 @@ try
|
|||||||
.WriteTo.SQLite(sqliteDbPath, storeTimestampInUtc: true));
|
.WriteTo.SQLite(sqliteDbPath, storeTimestampInUtc: true));
|
||||||
|
|
||||||
var config = builder.Configuration;
|
var config = builder.Configuration;
|
||||||
|
var windowsServiceOptions = config
|
||||||
|
.GetSection(WindowsServiceHostingOptions.SectionName)
|
||||||
|
.Get<WindowsServiceHostingOptions>() ?? new WindowsServiceHostingOptions();
|
||||||
|
|
||||||
|
if (windowsServiceOptions.Enabled)
|
||||||
|
{
|
||||||
|
builder.Services.AddWindowsService(options =>
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(windowsServiceOptions.ServiceName))
|
||||||
|
options.ServiceName = windowsServiceOptions.ServiceName;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var backgroundServicesOptions = config
|
var backgroundServicesOptions = config
|
||||||
.GetSection(BackgroundServicesOptions.SectionName)
|
.GetSection(BackgroundServicesOptions.SectionName)
|
||||||
.Get<BackgroundServicesOptions>() ?? new BackgroundServicesOptions();
|
.Get<BackgroundServicesOptions>() ?? new BackgroundServicesOptions();
|
||||||
@@ -358,6 +371,7 @@ try
|
|||||||
builder.Services.Configure<SenderFeatureAccessOptions>(config.GetSection(SenderFeatureAccessOptions.SectionName));
|
builder.Services.Configure<SenderFeatureAccessOptions>(config.GetSection(SenderFeatureAccessOptions.SectionName));
|
||||||
builder.Services.Configure<SerilogUiAccessOptions>(config.GetSection(SerilogUiAccessOptions.SectionName));
|
builder.Services.Configure<SerilogUiAccessOptions>(config.GetSection(SerilogUiAccessOptions.SectionName));
|
||||||
builder.Services.Configure<BackgroundServicesOptions>(config.GetSection(BackgroundServicesOptions.SectionName));
|
builder.Services.Configure<BackgroundServicesOptions>(config.GetSection(BackgroundServicesOptions.SectionName));
|
||||||
|
builder.Services.Configure<WindowsServiceHostingOptions>(config.GetSection(WindowsServiceHostingOptions.SectionName));
|
||||||
|
|
||||||
// Distributed Cache - SQL Server
|
// Distributed Cache - SQL Server
|
||||||
builder.Services.AddDistributedSqlServerCache(options =>
|
builder.Services.AddDistributedSqlServerCache(options =>
|
||||||
|
|||||||
@@ -21,6 +21,10 @@
|
|||||||
"Application": {
|
"Application": {
|
||||||
"LogDirectory": "E:\\LogFiles\\Digital Data\\signFlow"
|
"LogDirectory": "E:\\LogFiles\\Digital Data\\signFlow"
|
||||||
},
|
},
|
||||||
|
"WindowsServiceHosting": {
|
||||||
|
"Enabled": false,
|
||||||
|
"ServiceName": "Digital Data Envelope Generator Server"
|
||||||
|
},
|
||||||
"Serilog": {
|
"Serilog": {
|
||||||
"MinimumLevel": {
|
"MinimumLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
@echo off
|
||||||
|
setlocal
|
||||||
|
|
||||||
|
set "DEFAULT_SERVICE_NAME=Digital Data Envelope Generator Server"
|
||||||
|
set "SERVICE_NAME=%~2"
|
||||||
|
if "%SERVICE_NAME%"=="" set "SERVICE_NAME=%DEFAULT_SERVICE_NAME%"
|
||||||
|
|
||||||
|
set "SCRIPT_DIR=%~dp0"
|
||||||
|
for %%i in ("%SCRIPT_DIR%..\..") do set "APP_DIR=%%~fi"
|
||||||
|
set "EXE_PATH=%APP_DIR%\EnvelopeGenerator.Server.exe"
|
||||||
|
|
||||||
|
if "%~1"=="" goto :usage
|
||||||
|
|
||||||
|
if /I "%~1"=="install" goto :install
|
||||||
|
if /I "%~1"=="uninstall" goto :uninstall
|
||||||
|
if /I "%~1"=="start" goto :start
|
||||||
|
if /I "%~1"=="stop" goto :stop
|
||||||
|
if /I "%~1"=="status" goto :status
|
||||||
|
|
||||||
|
goto :usage
|
||||||
|
|
||||||
|
:install
|
||||||
|
if not exist "%EXE_PATH%" (
|
||||||
|
echo [ERROR] Executable not found: "%EXE_PATH%"
|
||||||
|
echo Run this script from the publish output folder.
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
sc.exe query "%SERVICE_NAME%" >nul 2>&1
|
||||||
|
if %ERRORLEVEL% EQU 0 (
|
||||||
|
echo [INFO] Service "%SERVICE_NAME%" already exists.
|
||||||
|
exit /b 0
|
||||||
|
)
|
||||||
|
|
||||||
|
sc.exe create "%SERVICE_NAME%" binPath= "\"%EXE_PATH%\"" start= auto
|
||||||
|
if %ERRORLEVEL% NEQ 0 (
|
||||||
|
echo [ERROR] Failed to create service "%SERVICE_NAME%".
|
||||||
|
exit /b %ERRORLEVEL%
|
||||||
|
)
|
||||||
|
|
||||||
|
sc.exe description "%SERVICE_NAME%" "EnvelopeGenerator.Server (Blazor + API host)"
|
||||||
|
echo [OK] Service "%SERVICE_NAME%" created.
|
||||||
|
echo [INFO] Start with: %~nx0 start "%SERVICE_NAME%"
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:uninstall
|
||||||
|
sc.exe query "%SERVICE_NAME%" >nul 2>&1
|
||||||
|
if %ERRORLEVEL% NEQ 0 (
|
||||||
|
echo [INFO] Service "%SERVICE_NAME%" not found.
|
||||||
|
exit /b 0
|
||||||
|
)
|
||||||
|
|
||||||
|
sc.exe stop "%SERVICE_NAME%" >nul 2>&1
|
||||||
|
sc.exe delete "%SERVICE_NAME%"
|
||||||
|
if %ERRORLEVEL% NEQ 0 (
|
||||||
|
echo [ERROR] Failed to delete service "%SERVICE_NAME%".
|
||||||
|
exit /b %ERRORLEVEL%
|
||||||
|
)
|
||||||
|
|
||||||
|
echo [OK] Service "%SERVICE_NAME%" deleted.
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:start
|
||||||
|
sc.exe start "%SERVICE_NAME%"
|
||||||
|
exit /b %ERRORLEVEL%
|
||||||
|
|
||||||
|
:stop
|
||||||
|
sc.exe stop "%SERVICE_NAME%"
|
||||||
|
exit /b %ERRORLEVEL%
|
||||||
|
|
||||||
|
:status
|
||||||
|
sc.exe query "%SERVICE_NAME%"
|
||||||
|
exit /b %ERRORLEVEL%
|
||||||
|
|
||||||
|
:usage
|
||||||
|
echo Usage:
|
||||||
|
echo %~nx0 install [ServiceName]
|
||||||
|
echo %~nx0 uninstall [ServiceName]
|
||||||
|
echo %~nx0 start [ServiceName]
|
||||||
|
echo %~nx0 stop [ServiceName]
|
||||||
|
echo %~nx0 status [ServiceName]
|
||||||
|
echo.
|
||||||
|
echo Default ServiceName: %DEFAULT_SERVICE_NAME%
|
||||||
|
exit /b 1
|
||||||
Reference in New Issue
Block a user