From ac7d963258327edfb86eeaa70ffa80ecb2d4b568 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Tue, 19 Dec 2023 10:55:52 +0100 Subject: [PATCH 01/45] remove keyring & double quote in execStart --- .../Extensions/DataProtectionExtensions.cs | 11 +---------- .../ServiceInstallation/LinuxSystemD.cs | 2 +- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs index de0f389a..8ad9eef1 100644 --- a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs @@ -200,16 +200,7 @@ public static IDataProtectionBuilder ProtectKeysCustom(this IDataProtectionBuild } else if (OperatingSystem.IsLinux()) { - try - { - Marshal.PrelinkAll(typeof(KeyUtils)); - builder.Services.Configure(options => options.XmlEncryptor = new KeyringXmlEncryptor()); - return builder; - } - catch (Exception e) - { - Log.Warning(e, "Fallback config encryption mechanism used."); - } + Log.Warning("Fallback config encryption mechanism used."); } else if (OperatingSystem.IsMacOS()) { diff --git a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs index 8aa61fe3..70cc1bdf 100644 --- a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs +++ b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs @@ -72,7 +72,7 @@ private string[] GetServiceFileContent(string serviceDescription, string command "", "[Service]", "Type=simple", - $"ExecStart=\"{command}\"", + $"ExecStart={command}", "", "[Install]", "WantedBy = multi-user.target" From e48df3097ef4ba6553a8d308e227f8cd73546adf Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 21 Dec 2023 06:27:40 +0100 Subject: [PATCH 02/45] add sudo --- src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs index 70cc1bdf..a62caa58 100644 --- a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs +++ b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs @@ -64,7 +64,7 @@ private string[] GetServiceFileContent(string serviceDescription, string command { var processPath = _launcherExecutablePath.Path; - var command = $"{processPath} {commandArgs}"; + var command = $"sudo {processPath} {commandArgs}"; return new[] { "[Unit]", From 6ac66e65073723cb4974716bdba886c3658cedbe Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 21 Dec 2023 08:03:23 +0100 Subject: [PATCH 03/45] increase debug --- src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs index 8ad9eef1..b87f500a 100644 --- a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs @@ -176,6 +176,7 @@ public static IDataProtectionProvider Create(string? accessToken = null, string? public static IDataProtectionBuilder ProtectKeysCustom(this IDataProtectionBuilder builder, string? accessToken = null, bool useFallback = false) { Log.Verbose("Called IDataProtectionProvider.ProtectKeysCustom"); + Log.Verbose($"accessToken: {accessToken}"); if (accessToken is not null) { From b0b218c806ab9958b4536474982d25940428b368 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 21 Dec 2023 09:16:21 +0100 Subject: [PATCH 04/45] further increase logging --- src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs index b87f500a..0127f94c 100644 --- a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs @@ -118,6 +118,7 @@ public LegacyXmlEncryptor(IServiceCollection services) { Log.Verbose("Called LegacyXmlEncryptor constructor"); accessToken = services.BuildServiceProvider().GetRequiredService(); + Log.Verbose("Found AccessTokenServicd"); } public EncryptedXmlInfo Encrypt(XElement plaintextElement) @@ -176,7 +177,6 @@ public static IDataProtectionProvider Create(string? accessToken = null, string? public static IDataProtectionBuilder ProtectKeysCustom(this IDataProtectionBuilder builder, string? accessToken = null, bool useFallback = false) { Log.Verbose("Called IDataProtectionProvider.ProtectKeysCustom"); - Log.Verbose($"accessToken: {accessToken}"); if (accessToken is not null) { From 3eaf35943b4435c7b9469405d1614e41b1cae3a7 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 21 Dec 2023 10:32:48 +0100 Subject: [PATCH 05/45] logging --- src/fiskaltrust.Launcher/Commands/Common.cs | 3 ++- .../Extensions/DataProtectionExtensions.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/fiskaltrust.Launcher/Commands/Common.cs b/src/fiskaltrust.Launcher/Commands/Common.cs index 1fa6bf90..9a673ce3 100644 --- a/src/fiskaltrust.Launcher/Commands/Common.cs +++ b/src/fiskaltrust.Launcher/Commands/Common.cs @@ -216,7 +216,7 @@ public static async Task HandleAsync( var dataProtectionProvider = DataProtectionExtensions.Create(launcherConfiguration.AccessToken, useFallback: launcherConfiguration.UseLegacyDataProtection!.Value); - + Log.Verbose($"dataProtectionProvider is null: {dataProtectionProvider == null}"); try { launcherConfiguration.Decrypt(dataProtectionProvider.CreateProtector(LauncherConfiguration.DATA_PROTECTION_DATA_PURPOSE)); @@ -225,6 +225,7 @@ public static async Task HandleAsync( { Log.Warning(e, "Error decrypring launcher configuration file."); } + Log.Verbose($"finished handler"); return await handler(options, new CommonProperties(launcherConfiguration, cashboxConfiguration, clientEcdh, dataProtectionProvider), specificOptions, host.Services.GetRequiredService()); } diff --git a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs index 0127f94c..5255d8ec 100644 --- a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs @@ -118,7 +118,6 @@ public LegacyXmlEncryptor(IServiceCollection services) { Log.Verbose("Called LegacyXmlEncryptor constructor"); accessToken = services.BuildServiceProvider().GetRequiredService(); - Log.Verbose("Found AccessTokenServicd"); } public EncryptedXmlInfo Encrypt(XElement plaintextElement) @@ -211,6 +210,7 @@ public static IDataProtectionBuilder ProtectKeysCustom(this IDataProtectionBuild Log.Debug("Fallback config encryption mechanism used."); builder.Services.Configure(options => options.XmlEncryptor = new LegacyXmlEncryptor(builder.Services)); + Log.Verbose("config KeyManagementOptions"); return builder; } } From 81a6f15b33a987d66f8d9207ff3ddce6a905426f Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Fri, 22 Dec 2023 08:33:48 +0100 Subject: [PATCH 06/45] dont use Protector on fallback --- src/fiskaltrust.Launcher/Commands/Common.cs | 5 ++++- src/fiskaltrust.Launcher/Commands/DoctorCommand.cs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/fiskaltrust.Launcher/Commands/Common.cs b/src/fiskaltrust.Launcher/Commands/Common.cs index 9a673ce3..27ae7d18 100644 --- a/src/fiskaltrust.Launcher/Commands/Common.cs +++ b/src/fiskaltrust.Launcher/Commands/Common.cs @@ -219,7 +219,10 @@ public static async Task HandleAsync( Log.Verbose($"dataProtectionProvider is null: {dataProtectionProvider == null}"); try { - launcherConfiguration.Decrypt(dataProtectionProvider.CreateProtector(LauncherConfiguration.DATA_PROTECTION_DATA_PURPOSE)); + if (!launcherConfiguration.UseLegacyDataProtection!.Value) + { + launcherConfiguration.Decrypt(dataProtectionProvider.CreateProtector(LauncherConfiguration.DATA_PROTECTION_DATA_PURPOSE)); + } } catch (Exception e) { diff --git a/src/fiskaltrust.Launcher/Commands/DoctorCommand.cs b/src/fiskaltrust.Launcher/Commands/DoctorCommand.cs index 9007e414..230cb224 100644 --- a/src/fiskaltrust.Launcher/Commands/DoctorCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/DoctorCommand.cs @@ -124,7 +124,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro } var dataProtectionProvider = checkUp.Check("Setup data protection", () => DataProtectionExtensions.Create(launcherConfiguration.AccessToken, useFallback: launcherConfiguration.UseLegacyDataProtection!.Value)); - if (dataProtectionProvider is not null) + if (dataProtectionProvider is not null && !launcherConfiguration.UseLegacyDataProtection!.Value) { checkUp.Check("Decrypt launcher configuration", () => launcherConfiguration.Decrypt(dataProtectionProvider.CreateProtector(LauncherConfiguration.DATA_PROTECTION_DATA_PURPOSE))); } From 24e5036576c28f12c35b1850705a7fd3dc0c2aab Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 28 Dec 2023 08:43:26 +0100 Subject: [PATCH 07/45] increase logging --- .../Extensions/DataProtectionExtensions.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs index 5255d8ec..e85e6066 100644 --- a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs @@ -138,7 +138,10 @@ class LegacyXmlDecryptor : IXmlDecryptor public LegacyXmlDecryptor(IServiceCollection? services) { Log.Verbose("Called LegacyXmlDecryptor constructor"); + var service = services?.BuildServiceProvider()?.GetService(); + Log.Verbose($"AccessTokenForEncryption == null: {service == null}"); accessToken = services?.BuildServiceProvider()?.GetService() ?? DataProtectionExtensions.AccessTokenForEncryption!; + Log.Verbose($"accessToken == null: {accessToken == null}"); } public LegacyXmlDecryptor() From b7665c5c099f6df1453d049eba663e916b414c6c Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 28 Dec 2023 09:19:05 +0100 Subject: [PATCH 08/45] .. --- .../Extensions/DataProtectionExtensions.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs index e85e6066..e9594e45 100644 --- a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs @@ -118,6 +118,7 @@ public LegacyXmlEncryptor(IServiceCollection services) { Log.Verbose("Called LegacyXmlEncryptor constructor"); accessToken = services.BuildServiceProvider().GetRequiredService(); + Log.Verbose($"accessToken == null: {accessToken == null}"); } public EncryptedXmlInfo Encrypt(XElement plaintextElement) @@ -138,10 +139,7 @@ class LegacyXmlDecryptor : IXmlDecryptor public LegacyXmlDecryptor(IServiceCollection? services) { Log.Verbose("Called LegacyXmlDecryptor constructor"); - var service = services?.BuildServiceProvider()?.GetService(); - Log.Verbose($"AccessTokenForEncryption == null: {service == null}"); accessToken = services?.BuildServiceProvider()?.GetService() ?? DataProtectionExtensions.AccessTokenForEncryption!; - Log.Verbose($"accessToken == null: {accessToken == null}"); } public LegacyXmlDecryptor() From 0a36b28f2237d502937c8a5fee20b27e0959b572 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 28 Dec 2023 11:17:14 +0100 Subject: [PATCH 09/45] .. --- src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs index e9594e45..f83a4b04 100644 --- a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs @@ -118,7 +118,7 @@ public LegacyXmlEncryptor(IServiceCollection services) { Log.Verbose("Called LegacyXmlEncryptor constructor"); accessToken = services.BuildServiceProvider().GetRequiredService(); - Log.Verbose($"accessToken == null: {accessToken == null}"); + Log.Verbose($"accessToken: {accessToken.AccessToken}"); } public EncryptedXmlInfo Encrypt(XElement plaintextElement) From 876b31c57f2af5cd996cec9848412ee34cb7eaf1 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 28 Dec 2023 11:46:43 +0100 Subject: [PATCH 10/45] .. --- src/fiskaltrust.Launcher/Commands/Common.cs | 3 +++ .../Extensions/DataProtectionExtensions.cs | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fiskaltrust.Launcher/Commands/Common.cs b/src/fiskaltrust.Launcher/Commands/Common.cs index 27ae7d18..1814c76c 100644 --- a/src/fiskaltrust.Launcher/Commands/Common.cs +++ b/src/fiskaltrust.Launcher/Commands/Common.cs @@ -82,10 +82,13 @@ public static async Task HandleAsync( IHost host, Func> handler) where S : notnull { + Log.Verbose("call CommonHandler HandleAsync"); + /* var collectionSink = new CollectionSink(); Log.Logger = new LoggerConfiguration() .WriteTo.Sink(collectionSink) .CreateLogger(); + */ var launcherConfiguration = new LauncherConfiguration(); diff --git a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs index f83a4b04..5255d8ec 100644 --- a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs @@ -118,7 +118,6 @@ public LegacyXmlEncryptor(IServiceCollection services) { Log.Verbose("Called LegacyXmlEncryptor constructor"); accessToken = services.BuildServiceProvider().GetRequiredService(); - Log.Verbose($"accessToken: {accessToken.AccessToken}"); } public EncryptedXmlInfo Encrypt(XElement plaintextElement) From da3383f74d89dc20c81c6534d414ad987cd46282 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 28 Dec 2023 12:02:45 +0100 Subject: [PATCH 11/45] .. --- src/fiskaltrust.Launcher/Commands/Common.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fiskaltrust.Launcher/Commands/Common.cs b/src/fiskaltrust.Launcher/Commands/Common.cs index 1814c76c..7bc41d10 100644 --- a/src/fiskaltrust.Launcher/Commands/Common.cs +++ b/src/fiskaltrust.Launcher/Commands/Common.cs @@ -203,6 +203,7 @@ public static async Task HandleAsync( .Enrich.FromLogContext() .CreateLogger(); + /* foreach (var logEvent in collectionSink.Events) { Log.Write(logEvent); @@ -211,7 +212,7 @@ public static async Task HandleAsync( if (collectionSink.Events.Where(e => e.Level == LogEventLevel.Fatal).Any()) { return 1; - } + }*/ Log.Debug("Launcher Configuration File: {LauncherConfigurationFile}", options.LauncherConfigurationFile); Log.Debug("Cashbox Configuration File: {CashboxConfigurationFile}", launcherConfiguration.CashboxConfigurationFile); From 467355b271d42533359efbeae25f25bf1afbc191 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 28 Dec 2023 13:43:10 +0100 Subject: [PATCH 12/45] .. --- src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs index a62caa58..70cc1bdf 100644 --- a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs +++ b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs @@ -64,7 +64,7 @@ private string[] GetServiceFileContent(string serviceDescription, string command { var processPath = _launcherExecutablePath.Path; - var command = $"sudo {processPath} {commandArgs}"; + var command = $"{processPath} {commandArgs}"; return new[] { "[Unit]", From d380cc5657f653567a17db7ac52ed3f971290b2a Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 28 Dec 2023 14:05:27 +0100 Subject: [PATCH 13/45] .. --- src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs index 70cc1bdf..8aa61fe3 100644 --- a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs +++ b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs @@ -72,7 +72,7 @@ private string[] GetServiceFileContent(string serviceDescription, string command "", "[Service]", "Type=simple", - $"ExecStart={command}", + $"ExecStart=\"{command}\"", "", "[Install]", "WantedBy = multi-user.target" From 87ffafbf20b1ae4e509d705d73d6d0552134954d Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Fri, 29 Dec 2023 07:43:30 +0100 Subject: [PATCH 14/45] check if run command is called --- src/fiskaltrust.Launcher/Commands/RunCommand.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fiskaltrust.Launcher/Commands/RunCommand.cs b/src/fiskaltrust.Launcher/Commands/RunCommand.cs index ddbff447..24de1701 100644 --- a/src/fiskaltrust.Launcher/Commands/RunCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/RunCommand.cs @@ -66,6 +66,7 @@ public static class RunHandler { public static async Task HandleAsync(CommonOptions commonOptions, CommonProperties commonProperties, RunOptions _, RunServices runServices) { + Log.Verbose($"RunHandler call"); var builder = WebApplication.CreateBuilder(); builder.Host From 3ae0c76cf521ce4a31d4122491a6ac41f1cb8f25 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Fri, 29 Dec 2023 08:15:23 +0100 Subject: [PATCH 15/45] .. --- src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs index 8aa61fe3..a62caa58 100644 --- a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs +++ b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs @@ -64,7 +64,7 @@ private string[] GetServiceFileContent(string serviceDescription, string command { var processPath = _launcherExecutablePath.Path; - var command = $"{processPath} {commandArgs}"; + var command = $"sudo {processPath} {commandArgs}"; return new[] { "[Unit]", @@ -72,7 +72,7 @@ private string[] GetServiceFileContent(string serviceDescription, string command "", "[Service]", "Type=simple", - $"ExecStart=\"{command}\"", + $"ExecStart={command}", "", "[Install]", "WantedBy = multi-user.target" From 70fb19401cc86b35e9eb2065be878aa48b20940d Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Fri, 29 Dec 2023 09:34:11 +0100 Subject: [PATCH 16/45] logging run command --- src/fiskaltrust.Launcher/Commands/RunCommand.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/fiskaltrust.Launcher/Commands/RunCommand.cs b/src/fiskaltrust.Launcher/Commands/RunCommand.cs index 24de1701..ee56e503 100644 --- a/src/fiskaltrust.Launcher/Commands/RunCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/RunCommand.cs @@ -84,19 +84,22 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro services.AddSingleton(_ => runServices.LauncherExecutablePath); }); + Log.Verbose($"RunHandler builder.Host"); builder.WebHost.ConfigureBinding(new Uri($"http://[::1]:{commonProperties.LauncherConfiguration.LauncherPort}"), protocols: HttpProtocols.Http2); builder.Services.AddCodeFirstGrpc(); var app = builder.Build(); - + Log.Verbose($"RunHandler builder.Build"); app.UseRouting(); #pragma warning disable ASP0014 app.UseEndpoints(endpoints => endpoints.MapGrpcService()); #pragma warning restore ASP0014 - - await runServices.SelfUpdater.PrepareSelfUpdate(Log.Logger, commonProperties.LauncherConfiguration, app.Services.GetRequiredService()); - + Log.Verbose($"RunHandler PrepareSelfUpdate.call"); + try { + await runServices.SelfUpdater.PrepareSelfUpdate(Log.Logger, commonProperties.LauncherConfiguration, app.Services.GetRequiredService()); + } catch (Exception e) { Log.Error(e, "An unhandled exception occured."); return 1;} + Log.Verbose($"RunHandler PrepareSelfUpdate.end"); try { await app.RunAsync(runServices.Lifetime.ApplicationLifetime.ApplicationStopping); @@ -112,7 +115,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro { Log.CloseAndFlush(); } - + Log.Verbose($"RunHandler end"); return 0; } } From cd8b832a4de79980ad09e4662507db9dfc0dfc37 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Fri, 29 Dec 2023 09:58:43 +0100 Subject: [PATCH 17/45] .. --- src/fiskaltrust.Launcher/Commands/RunCommand.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fiskaltrust.Launcher/Commands/RunCommand.cs b/src/fiskaltrust.Launcher/Commands/RunCommand.cs index ee56e503..5841f8b0 100644 --- a/src/fiskaltrust.Launcher/Commands/RunCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/RunCommand.cs @@ -68,14 +68,14 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro { Log.Verbose($"RunHandler call"); var builder = WebApplication.CreateBuilder(); - + Log.Verbose($"RunHandler CreateBuilder"); builder.Host .UseSerilog() .ConfigureServices((_, services) => { services.Configure(opts => opts.ShutdownTimeout = TimeSpan.FromSeconds(30)); services.AddSingleton(_ => commonProperties.LauncherConfiguration); - services.AddSingleton(_ => runServices.Lifetime); + //services.AddSingleton(_ => runServices.Lifetime); services.AddSingleton(_ => commonProperties.CashboxConfiguration); services.AddSingleton(_ => new Dictionary()); services.AddSingleton(); From 4aa12abdaf22ed7b4a860c86fe28ba71ee9a1084 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Fri, 29 Dec 2023 10:20:23 +0100 Subject: [PATCH 18/45] exclude lifetime --- src/fiskaltrust.Launcher/Commands/HostCommand.cs | 2 +- src/fiskaltrust.Launcher/Commands/RunCommand.cs | 2 +- src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fiskaltrust.Launcher/Commands/HostCommand.cs b/src/fiskaltrust.Launcher/Commands/HostCommand.cs index d50a079a..95cf8110 100644 --- a/src/fiskaltrust.Launcher/Commands/HostCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/HostCommand.cs @@ -55,7 +55,7 @@ public class HostServices { public HostServices(LauncherExecutablePath launcherExecutablePath, IHostApplicationLifetime lifetime) { - CancellationToken = lifetime.ApplicationStopping; + CancellationToken = new CancellationToken(); LauncherExecutablePath = launcherExecutablePath; } diff --git a/src/fiskaltrust.Launcher/Commands/RunCommand.cs b/src/fiskaltrust.Launcher/Commands/RunCommand.cs index 5841f8b0..66ab59a8 100644 --- a/src/fiskaltrust.Launcher/Commands/RunCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/RunCommand.cs @@ -102,7 +102,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro Log.Verbose($"RunHandler PrepareSelfUpdate.end"); try { - await app.RunAsync(runServices.Lifetime.ApplicationLifetime.ApplicationStopping); + await app.RunAsync(); await runServices.SelfUpdater.StartSelfUpdate(Log.Logger, commonProperties.LauncherConfiguration, commonOptions.LauncherConfigurationFile); } diff --git a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs index 2ae00daa..25d4e74b 100644 --- a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs @@ -31,8 +31,8 @@ public static IHostBuilder UseCustomHostLifetime(this IHostBuilder builder) else { Console.OutputEncoding = Encoding.UTF8; - builder.ConfigureServices(services => services.AddSingleton()); - builder.UseConsoleLifetime(); + //builder.ConfigureServices(services => services.AddSingleton()); + //builder.UseConsoleLifetime(); return builder; } } From bbd9e30c7668107e23683322a90191cee73aa6a5 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Fri, 29 Dec 2023 10:53:30 +0100 Subject: [PATCH 19/45] .. --- src/fiskaltrust.Launcher/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fiskaltrust.Launcher/Program.cs b/src/fiskaltrust.Launcher/Program.cs index 7efbafff..0deaaa49 100644 --- a/src/fiskaltrust.Launcher/Program.cs +++ b/src/fiskaltrust.Launcher/Program.cs @@ -52,7 +52,7 @@ host.UseCustomHostLifetime(); host.ConfigureServices(services => services - .Configure(opts => opts.ShutdownTimeout = TimeSpan.FromSeconds(45)) + //.Configure(opts => opts.ShutdownTimeout = TimeSpan.FromSeconds(45)) .AddSingleton(_ => subArguments) .AddSingleton(_ => new LauncherProcessId(Environment.ProcessId)) .AddSingleton(_ => new LauncherExecutablePath From 298e9e1f52c5a5c416f7c9e859d3adb8ebac4068 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Tue, 2 Jan 2024 09:52:23 +0100 Subject: [PATCH 20/45] use systd extension --- .../Configuration/Configuration.cs | 4 ++++ src/fiskaltrust.Launcher/Commands/HostCommand.cs | 2 +- src/fiskaltrust.Launcher/Commands/RunCommand.cs | 5 +++-- .../Extensions/LifetimeExtensions.cs | 14 +++++++++++--- src/fiskaltrust.Launcher/Program.cs | 4 ++-- .../ServiceInstallation/LinuxSystemD.cs | 3 ++- .../fiskaltrust.Launcher.csproj | 3 ++- 7 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/fiskaltrust.Launcher.Common/Configuration/Configuration.cs b/src/fiskaltrust.Launcher.Common/Configuration/Configuration.cs index 6f6f7232..cea77163 100644 --- a/src/fiskaltrust.Launcher.Common/Configuration/Configuration.cs +++ b/src/fiskaltrust.Launcher.Common/Configuration/Configuration.cs @@ -163,6 +163,10 @@ private T WithDefault(T value, Func defaultValue) [JsonPropertyName("useLegacyDataProtection")] public bool? UseLegacyDataProtection { get => WithDefault(_useLegacyDataProtection, false); set => _useLegacyDataProtection = value; } + private bool? _isSystemdService; + [JsonPropertyName("isSystemdService")] + public bool? IsSystemdService { get => WithDefault(_useLegacyDataProtection, false); set => _useLegacyDataProtection = value; } + private SemanticVersioning.Range? _launcherVersion = null; [JsonPropertyName("launcherVersion")] [JsonConverter(typeof(SemVersionConverter))] diff --git a/src/fiskaltrust.Launcher/Commands/HostCommand.cs b/src/fiskaltrust.Launcher/Commands/HostCommand.cs index 95cf8110..d50a079a 100644 --- a/src/fiskaltrust.Launcher/Commands/HostCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/HostCommand.cs @@ -55,7 +55,7 @@ public class HostServices { public HostServices(LauncherExecutablePath launcherExecutablePath, IHostApplicationLifetime lifetime) { - CancellationToken = new CancellationToken(); + CancellationToken = lifetime.ApplicationStopping; LauncherExecutablePath = launcherExecutablePath; } diff --git a/src/fiskaltrust.Launcher/Commands/RunCommand.cs b/src/fiskaltrust.Launcher/Commands/RunCommand.cs index 66ab59a8..29664f89 100644 --- a/src/fiskaltrust.Launcher/Commands/RunCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/RunCommand.cs @@ -40,6 +40,7 @@ public RunCommand(string name = "run", bool addCliOnlyParameters = true) : base( AddOption(new Option("--tls-certificate-password")); AddOption(new Option("--use-http-sys-binding")); AddOption(new Option("--use-legacy-data-protection")); + AddOption(new Option("--is-systemd-service")); } } @@ -75,7 +76,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro { services.Configure(opts => opts.ShutdownTimeout = TimeSpan.FromSeconds(30)); services.AddSingleton(_ => commonProperties.LauncherConfiguration); - //services.AddSingleton(_ => runServices.Lifetime); + services.AddSingleton(_ => runServices.Lifetime); services.AddSingleton(_ => commonProperties.CashboxConfiguration); services.AddSingleton(_ => new Dictionary()); services.AddSingleton(); @@ -102,7 +103,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro Log.Verbose($"RunHandler PrepareSelfUpdate.end"); try { - await app.RunAsync(); + await app.RunAsync(runServices.Lifetime.ApplicationLifetime.ApplicationStopping); await runServices.SelfUpdater.StartSelfUpdate(Log.Logger, commonProperties.LauncherConfiguration, commonOptions.LauncherConfigurationFile); } diff --git a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs index 25d4e74b..41c99742 100644 --- a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs @@ -7,8 +7,10 @@ namespace fiskaltrust.Launcher.Extensions { static class LifetimeExtensions { - public static IHostBuilder UseCustomHostLifetime(this IHostBuilder builder) + public static IHostBuilder UseCustomHostLifetime(this IHostBuilder builder, string[] args) { + var isSystemd = args.Contains("--is-systemd-service true"); + if (WindowsServiceHelpers.IsWindowsService()) { builder.UseWindowsService(); @@ -27,12 +29,18 @@ public static IHostBuilder UseCustomHostLifetime(this IHostBuilder builder) services.AddSingleton(sp => sp.GetRequiredService()); #pragma warning restore CA1416 }); + }else if (isSystemd) + { + Console.OutputEncoding = Encoding.UTF8; + builder.ConfigureServices(services => services.AddSingleton()); + builder.UseSystemd(); + return builder; } else { Console.OutputEncoding = Encoding.UTF8; - //builder.ConfigureServices(services => services.AddSingleton()); - //builder.UseConsoleLifetime(); + builder.ConfigureServices(services => services.AddSingleton()); + builder.UseConsoleLifetime(); return builder; } } diff --git a/src/fiskaltrust.Launcher/Program.cs b/src/fiskaltrust.Launcher/Program.cs index 0deaaa49..87009bad 100644 --- a/src/fiskaltrust.Launcher/Program.cs +++ b/src/fiskaltrust.Launcher/Program.cs @@ -49,10 +49,10 @@ .UseHost( host => { - host.UseCustomHostLifetime(); + host.UseCustomHostLifetime(args); host.ConfigureServices(services => services - //.Configure(opts => opts.ShutdownTimeout = TimeSpan.FromSeconds(45)) + .Configure(opts => opts.ShutdownTimeout = TimeSpan.FromSeconds(45)) .AddSingleton(_ => subArguments) .AddSingleton(_ => new LauncherProcessId(Environment.ProcessId)) .AddSingleton(_ => new LauncherExecutablePath diff --git a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs index a62caa58..2d74bf6c 100644 --- a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs +++ b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs @@ -19,6 +19,7 @@ public override async Task InstallService(string commandArgs, string? displ { return -1; } + commandArgs += " --is-systemd-service true"; Log.Information("Installing service via systemd."); var serviceFileContent = GetServiceFileContent(displayName ?? "Service installation of fiskaltrust launcher.", commandArgs); var serviceFilePath = Path.Combine(_servicePath, $"{_serviceName}.service"); @@ -71,7 +72,7 @@ private string[] GetServiceFileContent(string serviceDescription, string command $"Description=\"{serviceDescription}\"", "", "[Service]", - "Type=simple", + "Type=notify ", $"ExecStart={command}", "", "[Install]", diff --git a/src/fiskaltrust.Launcher/fiskaltrust.Launcher.csproj b/src/fiskaltrust.Launcher/fiskaltrust.Launcher.csproj index 3aa66c0a..7d35a0b2 100644 --- a/src/fiskaltrust.Launcher/fiskaltrust.Launcher.csproj +++ b/src/fiskaltrust.Launcher/fiskaltrust.Launcher.csproj @@ -22,6 +22,7 @@ + @@ -31,7 +32,7 @@ - + From 33f68ce0b6a3d0db0cd00d62d15b7556782a9648 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Tue, 2 Jan 2024 12:08:58 +0100 Subject: [PATCH 21/45] remove ilifetime for test --- src/fiskaltrust.Launcher/Commands/DoctorCommand.cs | 14 +++++++------- src/fiskaltrust.Launcher/Commands/RunCommand.cs | 10 +++++----- .../Extensions/LifetimeExtensions.cs | 4 ++-- .../ProcessHost/ProcessHostMonarcStartup.cs | 14 +++++++------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/fiskaltrust.Launcher/Commands/DoctorCommand.cs b/src/fiskaltrust.Launcher/Commands/DoctorCommand.cs index 230cb224..f4d32b46 100644 --- a/src/fiskaltrust.Launcher/Commands/DoctorCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/DoctorCommand.cs @@ -46,13 +46,13 @@ public DoctorOptions(LauncherConfiguration argsLauncherConfiguration, string lau public class DoctorServices { - public DoctorServices(ILifetime lifetime, LauncherExecutablePath launcherExecutablePath) + public DoctorServices( LauncherExecutablePath launcherExecutablePath) { - Lifetime = lifetime; + //Lifetime = lifetime; LauncherExecutablePath = launcherExecutablePath; } - public readonly ILifetime Lifetime; + //public readonly ILifetime Lifetime; public readonly LauncherExecutablePath LauncherExecutablePath; } @@ -141,7 +141,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro { services.Configure(opts => opts.ShutdownTimeout = TimeSpan.FromSeconds(30)); services.AddSingleton(_ => launcherConfiguration); - services.AddSingleton(_ => doctorServices.Lifetime); + //services.AddSingleton(_ => doctorServices.Lifetime); services.AddSingleton(_ => cashboxConfiguration); services.AddSingleton(_ => new Dictionary() { { @@ -168,7 +168,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro monarchApp.UseEndpoints(endpoints => endpoints.MapGrpcService()); #pragma warning restore ASP0014 - await checkUp.CheckAwait("Start monarch WebApplication", async () => await WithTimeout(async () => await monarchApp.StartAsync(doctorServices.Lifetime.ApplicationLifetime.ApplicationStopping), TimeSpan.FromSeconds(5)), throws: true); + await checkUp.CheckAwait("Start monarch WebApplication", async () => await WithTimeout(async () => await monarchApp.StartAsync(), TimeSpan.FromSeconds(5)), throws: true); var plebeianConfiguration = new PlebeianConfiguration { @@ -226,13 +226,13 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro var plebeianApp = checkUp.Check("Build plebeian Host", plebeianBuilder.Build, throws: true)!; - await checkUp.CheckAwait("Start plebeian Host", async () => await WithTimeout(async () => await plebeianApp.StartAsync(doctorServices.Lifetime.ApplicationLifetime.ApplicationStopping), TimeSpan.FromSeconds(5))); + await checkUp.CheckAwait("Start plebeian Host", async () => await WithTimeout(async () => await plebeianApp.StartAsync(), TimeSpan.FromSeconds(5))); await doctorProcessHostMonarch.IsStarted.Task; await checkUp.CheckAwait("Shutdown launcher gracefully", async () => await WithTimeout(async () => { - await doctorServices.Lifetime.StopAsync(new CancellationToken()); + //await doctorServices.Lifetime.StopAsync(new CancellationToken()); await monarchApp.StopAsync(); await monarchApp.WaitForShutdownAsync(); diff --git a/src/fiskaltrust.Launcher/Commands/RunCommand.cs b/src/fiskaltrust.Launcher/Commands/RunCommand.cs index 29664f89..cf686ad0 100644 --- a/src/fiskaltrust.Launcher/Commands/RunCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/RunCommand.cs @@ -51,14 +51,14 @@ public class RunOptions public class RunServices { - public RunServices(ILifetime lifetime, SelfUpdater selfUpdater, LauncherExecutablePath launcherExecutablePath) + public RunServices(SelfUpdater selfUpdater, LauncherExecutablePath launcherExecutablePath) { - Lifetime = lifetime; + //Lifetime = lifetime; SelfUpdater = selfUpdater; LauncherExecutablePath = launcherExecutablePath; } - public readonly ILifetime Lifetime; + //public readonly ILifetime Lifetime; public readonly SelfUpdater SelfUpdater; public readonly LauncherExecutablePath LauncherExecutablePath; } @@ -76,7 +76,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro { services.Configure(opts => opts.ShutdownTimeout = TimeSpan.FromSeconds(30)); services.AddSingleton(_ => commonProperties.LauncherConfiguration); - services.AddSingleton(_ => runServices.Lifetime); + //services.AddSingleton(_ => runServices.Lifetime); services.AddSingleton(_ => commonProperties.CashboxConfiguration); services.AddSingleton(_ => new Dictionary()); services.AddSingleton(); @@ -103,7 +103,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro Log.Verbose($"RunHandler PrepareSelfUpdate.end"); try { - await app.RunAsync(runServices.Lifetime.ApplicationLifetime.ApplicationStopping); + await app.RunAsync(); await runServices.SelfUpdater.StartSelfUpdate(Log.Logger, commonProperties.LauncherConfiguration, commonOptions.LauncherConfigurationFile); } diff --git a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs index 41c99742..91d110b2 100644 --- a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs @@ -32,7 +32,7 @@ public static IHostBuilder UseCustomHostLifetime(this IHostBuilder builder, stri }else if (isSystemd) { Console.OutputEncoding = Encoding.UTF8; - builder.ConfigureServices(services => services.AddSingleton()); + //builder.ConfigureServices(services => services.AddSingleton()); builder.UseSystemd(); return builder; } @@ -50,7 +50,7 @@ public interface ILifetime : IHostLifetime { public IHostApplicationLifetime ApplicationLifetime { get; init; } - public void ServiceStartupCompleted(); + //public void ServiceStartupCompleted(); } diff --git a/src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarcStartup.cs b/src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarcStartup.cs index 8efcd720..9e6a9afb 100644 --- a/src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarcStartup.cs +++ b/src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarcStartup.cs @@ -23,11 +23,11 @@ public class AlreadyLoggedException : Exception { } private readonly PackageDownloader _downloader; private readonly ILogger _logger; private readonly ILoggerFactory _loggerFactory; - private readonly ILifetime _lifetime; + //private readonly ILifetime _lifetime; private readonly LauncherExecutablePath _launcherExecutablePath; private readonly TaskCompletionSource _kestrelReady; - public ProcessHostMonarcStartup(ILoggerFactory loggerFactory, ILogger logger, Dictionary hosts, LauncherConfiguration launcherConfiguration, ftCashBoxConfiguration cashBoxConfiguration, PackageDownloader downloader, ILifetime lifetime, LauncherExecutablePath launcherExecutablePath, IHostApplicationLifetime hostApplicationLifetime, IServer server) + public ProcessHostMonarcStartup(ILoggerFactory loggerFactory, ILogger logger, Dictionary hosts, LauncherConfiguration launcherConfiguration, ftCashBoxConfiguration cashBoxConfiguration, PackageDownloader downloader, LauncherExecutablePath launcherExecutablePath, IHostApplicationLifetime hostApplicationLifetime, IServer server) { _loggerFactory = loggerFactory; _logger = logger; @@ -35,7 +35,7 @@ public ProcessHostMonarcStartup(ILoggerFactory loggerFactory, ILogger(); @@ -55,7 +55,7 @@ public ProcessHostMonarcStartup(ILoggerFactory loggerFactory, ILogger _logger.LogInformation("Shutting down launcher.")); + //_lifetime.ApplicationLifetime.ApplicationStopping.Register(() => _logger.LogInformation("Shutting down launcher.")); cancellationToken.Register(() => _kestrelReady.TrySetCanceled()); StartupLogging(); @@ -98,7 +98,7 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken) catch (Exception e) { if (e is not AlreadyLoggedException) { _logger.LogError(e, "Error Starting Monarchs"); } - _lifetime.ApplicationLifetime.StopApplication(); + //_lifetime.ApplicationLifetime.StopApplication(); return; } @@ -109,7 +109,7 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken) { _logger.LogInformation("Press CTRL+C to exit."); } - _lifetime.ServiceStartupCompleted(); + //_lifetime.ServiceStartupCompleted(); } if (_hosts.Count == 0) @@ -135,7 +135,7 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken) _logger.LogWarning(failed.Exception, "ProcessHost {Id} had crashed.", failed.Key); } } - _lifetime.ApplicationLifetime.StopApplication(); + //_lifetime.ApplicationLifetime.StopApplication(); } private async Task StartProcessHostMonarch(PackageConfiguration configuration, PackageType packageType, CancellationToken cancellationToken) From 176fff6fae830bceded38a8d59a0840f1bfbae50 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Tue, 2 Jan 2024 13:21:06 +0100 Subject: [PATCH 22/45] call startAsync --- src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarcStartup.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarcStartup.cs b/src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarcStartup.cs index 9e6a9afb..ad9eeb11 100644 --- a/src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarcStartup.cs +++ b/src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarcStartup.cs @@ -55,6 +55,7 @@ public ProcessHostMonarcStartup(ILoggerFactory loggerFactory, ILogger _logger.LogInformation("Shutting down launcher.")); cancellationToken.Register(() => _kestrelReady.TrySetCanceled()); From 42824c7ceb5f209969e7b53a73602ce9907ef029 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Tue, 2 Jan 2024 14:31:56 +0100 Subject: [PATCH 23/45] customized systemd lifetime --- .../Commands/DoctorCommand.cs | 14 ++--- .../Commands/RunCommand.cs | 10 ++-- .../Extensions/LifetimeExtensions.cs | 58 +++++++++++++++++-- .../ProcessHost/ProcessHostMonarcStartup.cs | 15 +++-- .../ServiceInstallation/LinuxSystemD.cs | 2 +- 5 files changed, 73 insertions(+), 26 deletions(-) diff --git a/src/fiskaltrust.Launcher/Commands/DoctorCommand.cs b/src/fiskaltrust.Launcher/Commands/DoctorCommand.cs index f4d32b46..230cb224 100644 --- a/src/fiskaltrust.Launcher/Commands/DoctorCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/DoctorCommand.cs @@ -46,13 +46,13 @@ public DoctorOptions(LauncherConfiguration argsLauncherConfiguration, string lau public class DoctorServices { - public DoctorServices( LauncherExecutablePath launcherExecutablePath) + public DoctorServices(ILifetime lifetime, LauncherExecutablePath launcherExecutablePath) { - //Lifetime = lifetime; + Lifetime = lifetime; LauncherExecutablePath = launcherExecutablePath; } - //public readonly ILifetime Lifetime; + public readonly ILifetime Lifetime; public readonly LauncherExecutablePath LauncherExecutablePath; } @@ -141,7 +141,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro { services.Configure(opts => opts.ShutdownTimeout = TimeSpan.FromSeconds(30)); services.AddSingleton(_ => launcherConfiguration); - //services.AddSingleton(_ => doctorServices.Lifetime); + services.AddSingleton(_ => doctorServices.Lifetime); services.AddSingleton(_ => cashboxConfiguration); services.AddSingleton(_ => new Dictionary() { { @@ -168,7 +168,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro monarchApp.UseEndpoints(endpoints => endpoints.MapGrpcService()); #pragma warning restore ASP0014 - await checkUp.CheckAwait("Start monarch WebApplication", async () => await WithTimeout(async () => await monarchApp.StartAsync(), TimeSpan.FromSeconds(5)), throws: true); + await checkUp.CheckAwait("Start monarch WebApplication", async () => await WithTimeout(async () => await monarchApp.StartAsync(doctorServices.Lifetime.ApplicationLifetime.ApplicationStopping), TimeSpan.FromSeconds(5)), throws: true); var plebeianConfiguration = new PlebeianConfiguration { @@ -226,13 +226,13 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro var plebeianApp = checkUp.Check("Build plebeian Host", plebeianBuilder.Build, throws: true)!; - await checkUp.CheckAwait("Start plebeian Host", async () => await WithTimeout(async () => await plebeianApp.StartAsync(), TimeSpan.FromSeconds(5))); + await checkUp.CheckAwait("Start plebeian Host", async () => await WithTimeout(async () => await plebeianApp.StartAsync(doctorServices.Lifetime.ApplicationLifetime.ApplicationStopping), TimeSpan.FromSeconds(5))); await doctorProcessHostMonarch.IsStarted.Task; await checkUp.CheckAwait("Shutdown launcher gracefully", async () => await WithTimeout(async () => { - //await doctorServices.Lifetime.StopAsync(new CancellationToken()); + await doctorServices.Lifetime.StopAsync(new CancellationToken()); await monarchApp.StopAsync(); await monarchApp.WaitForShutdownAsync(); diff --git a/src/fiskaltrust.Launcher/Commands/RunCommand.cs b/src/fiskaltrust.Launcher/Commands/RunCommand.cs index cf686ad0..29664f89 100644 --- a/src/fiskaltrust.Launcher/Commands/RunCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/RunCommand.cs @@ -51,14 +51,14 @@ public class RunOptions public class RunServices { - public RunServices(SelfUpdater selfUpdater, LauncherExecutablePath launcherExecutablePath) + public RunServices(ILifetime lifetime, SelfUpdater selfUpdater, LauncherExecutablePath launcherExecutablePath) { - //Lifetime = lifetime; + Lifetime = lifetime; SelfUpdater = selfUpdater; LauncherExecutablePath = launcherExecutablePath; } - //public readonly ILifetime Lifetime; + public readonly ILifetime Lifetime; public readonly SelfUpdater SelfUpdater; public readonly LauncherExecutablePath LauncherExecutablePath; } @@ -76,7 +76,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro { services.Configure(opts => opts.ShutdownTimeout = TimeSpan.FromSeconds(30)); services.AddSingleton(_ => commonProperties.LauncherConfiguration); - //services.AddSingleton(_ => runServices.Lifetime); + services.AddSingleton(_ => runServices.Lifetime); services.AddSingleton(_ => commonProperties.CashboxConfiguration); services.AddSingleton(_ => new Dictionary()); services.AddSingleton(); @@ -103,7 +103,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro Log.Verbose($"RunHandler PrepareSelfUpdate.end"); try { - await app.RunAsync(); + await app.RunAsync(runServices.Lifetime.ApplicationLifetime.ApplicationStopping); await runServices.SelfUpdater.StartSelfUpdate(Log.Logger, commonProperties.LauncherConfiguration, commonOptions.LauncherConfigurationFile); } diff --git a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs index 91d110b2..a967bf8b 100644 --- a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs @@ -1,5 +1,7 @@ using System.Runtime.Versioning; using System.Text; +using System.Web.Services.Description; +using Microsoft.Extensions.Hosting.Systemd; using Microsoft.Extensions.Hosting.WindowsServices; using Microsoft.Extensions.Options; @@ -29,12 +31,24 @@ public static IHostBuilder UseCustomHostLifetime(this IHostBuilder builder, stri services.AddSingleton(sp => sp.GetRequiredService()); #pragma warning restore CA1416 }); - }else if (isSystemd) + } + else if (isSystemd) { Console.OutputEncoding = Encoding.UTF8; - //builder.ConfigureServices(services => services.AddSingleton()); - builder.UseSystemd(); - return builder; + return builder.ConfigureServices(services => + { + var lifetime = services.FirstOrDefault(s => s.ImplementationType == typeof(SystemdLifetime)); + + if (lifetime != null) + { + services.Remove(lifetime); + } + +#pragma warning disable CA1416 + services.AddSingleton(); + services.AddSingleton(sp => sp.GetRequiredService()); +#pragma warning restore CA1416 + }); } else { @@ -50,7 +64,7 @@ public interface ILifetime : IHostLifetime { public IHostApplicationLifetime ApplicationLifetime { get; init; } - //public void ServiceStartupCompleted(); + public void ServiceStartupCompleted(); } @@ -141,4 +155,38 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); } } + + [SupportedOSPlatform("linux")] + public class CustomSystemdServiceLifetime : SystemdLifetime, ILifetime + { + private readonly CancellationTokenSource _starting = new(); + private readonly ManualResetEventSlim _started = new(); + + public IHostApplicationLifetime ApplicationLifetime { get; init; } + + public CustomSystemdServiceLifetime( + IHostEnvironment environment, + IHostApplicationLifetime applicationLifetime, + ILoggerFactory loggerFactory) + : base(environment, applicationLifetime, new SystemdNotifier(), loggerFactory) + { + ApplicationLifetime = applicationLifetime; + } + + public void ServiceStartupCompleted() + { + ApplicationLifetime.ApplicationStarted.Register(() => _started.Set()); + } + + public new async Task WaitForStartAsync(CancellationToken cancellationToken) + { + try + { + using var cts = CancellationTokenSource.CreateLinkedTokenSource(_starting.Token, cancellationToken); + await base.WaitForStartAsync(cts.Token); + } + catch (OperationCanceledException) when (_starting.IsCancellationRequested) { } + } + + } } \ No newline at end of file diff --git a/src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarcStartup.cs b/src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarcStartup.cs index ad9eeb11..8efcd720 100644 --- a/src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarcStartup.cs +++ b/src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarcStartup.cs @@ -23,11 +23,11 @@ public class AlreadyLoggedException : Exception { } private readonly PackageDownloader _downloader; private readonly ILogger _logger; private readonly ILoggerFactory _loggerFactory; - //private readonly ILifetime _lifetime; + private readonly ILifetime _lifetime; private readonly LauncherExecutablePath _launcherExecutablePath; private readonly TaskCompletionSource _kestrelReady; - public ProcessHostMonarcStartup(ILoggerFactory loggerFactory, ILogger logger, Dictionary hosts, LauncherConfiguration launcherConfiguration, ftCashBoxConfiguration cashBoxConfiguration, PackageDownloader downloader, LauncherExecutablePath launcherExecutablePath, IHostApplicationLifetime hostApplicationLifetime, IServer server) + public ProcessHostMonarcStartup(ILoggerFactory loggerFactory, ILogger logger, Dictionary hosts, LauncherConfiguration launcherConfiguration, ftCashBoxConfiguration cashBoxConfiguration, PackageDownloader downloader, ILifetime lifetime, LauncherExecutablePath launcherExecutablePath, IHostApplicationLifetime hostApplicationLifetime, IServer server) { _loggerFactory = loggerFactory; _logger = logger; @@ -35,7 +35,7 @@ public ProcessHostMonarcStartup(ILoggerFactory loggerFactory, ILogger(); @@ -55,8 +55,7 @@ public ProcessHostMonarcStartup(ILoggerFactory loggerFactory, ILogger _logger.LogInformation("Shutting down launcher.")); + _lifetime.ApplicationLifetime.ApplicationStopping.Register(() => _logger.LogInformation("Shutting down launcher.")); cancellationToken.Register(() => _kestrelReady.TrySetCanceled()); StartupLogging(); @@ -99,7 +98,7 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken) catch (Exception e) { if (e is not AlreadyLoggedException) { _logger.LogError(e, "Error Starting Monarchs"); } - //_lifetime.ApplicationLifetime.StopApplication(); + _lifetime.ApplicationLifetime.StopApplication(); return; } @@ -110,7 +109,7 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken) { _logger.LogInformation("Press CTRL+C to exit."); } - //_lifetime.ServiceStartupCompleted(); + _lifetime.ServiceStartupCompleted(); } if (_hosts.Count == 0) @@ -136,7 +135,7 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken) _logger.LogWarning(failed.Exception, "ProcessHost {Id} had crashed.", failed.Key); } } - //_lifetime.ApplicationLifetime.StopApplication(); + _lifetime.ApplicationLifetime.StopApplication(); } private async Task StartProcessHostMonarch(PackageConfiguration configuration, PackageType packageType, CancellationToken cancellationToken) diff --git a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs index 2d74bf6c..d5efae44 100644 --- a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs +++ b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs @@ -72,7 +72,7 @@ private string[] GetServiceFileContent(string serviceDescription, string command $"Description=\"{serviceDescription}\"", "", "[Service]", - "Type=notify ", + "Type=notify", $"ExecStart={command}", "", "[Install]", From dc28cc2f912f4d1143be4ef68ebe66d2e7b5f030 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Wed, 3 Jan 2024 13:03:14 +0100 Subject: [PATCH 24/45] .. --- src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs index a967bf8b..46f46cb1 100644 --- a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs @@ -35,6 +35,7 @@ public static IHostBuilder UseCustomHostLifetime(this IHostBuilder builder, stri else if (isSystemd) { Console.OutputEncoding = Encoding.UTF8; + builder.UseSystemd(); return builder.ConfigureServices(services => { var lifetime = services.FirstOrDefault(s => s.ImplementationType == typeof(SystemdLifetime)); From efbd5c9346680ff1c142d286fb37dd9e0fb33c90 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Wed, 3 Jan 2024 13:56:13 +0100 Subject: [PATCH 25/45] .. --- src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs index 46f46cb1..f06e092c 100644 --- a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs @@ -34,8 +34,10 @@ public static IHostBuilder UseCustomHostLifetime(this IHostBuilder builder, stri } else if (isSystemd) { - Console.OutputEncoding = Encoding.UTF8; builder.UseSystemd(); + builder.ConfigureServices(services => services.AddSingleton()); + return builder; + /* return builder.ConfigureServices(services => { var lifetime = services.FirstOrDefault(s => s.ImplementationType == typeof(SystemdLifetime)); @@ -49,7 +51,7 @@ public static IHostBuilder UseCustomHostLifetime(this IHostBuilder builder, stri services.AddSingleton(); services.AddSingleton(sp => sp.GetRequiredService()); #pragma warning restore CA1416 - }); + });*/ } else { From 02ab3822cd04dad6aa65b396817c7e78761569f3 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Wed, 3 Jan 2024 14:17:31 +0100 Subject: [PATCH 26/45] .. --- src/fiskaltrust.Launcher/Commands/RunCommand.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fiskaltrust.Launcher/Commands/RunCommand.cs b/src/fiskaltrust.Launcher/Commands/RunCommand.cs index 29664f89..8b25aa15 100644 --- a/src/fiskaltrust.Launcher/Commands/RunCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/RunCommand.cs @@ -69,6 +69,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro { Log.Verbose($"RunHandler call"); var builder = WebApplication.CreateBuilder(); + builder.Host.UseSystemd(); Log.Verbose($"RunHandler CreateBuilder"); builder.Host .UseSerilog() From cd220fc192be12d85a429fa4d1c48ac8339b8887 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Fri, 5 Jan 2024 08:30:41 +0100 Subject: [PATCH 27/45] use startApp instead o f run --- src/fiskaltrust.Launcher/Commands/RunCommand.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/fiskaltrust.Launcher/Commands/RunCommand.cs b/src/fiskaltrust.Launcher/Commands/RunCommand.cs index 8b25aa15..a1a0edea 100644 --- a/src/fiskaltrust.Launcher/Commands/RunCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/RunCommand.cs @@ -69,9 +69,8 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro { Log.Verbose($"RunHandler call"); var builder = WebApplication.CreateBuilder(); - builder.Host.UseSystemd(); - Log.Verbose($"RunHandler CreateBuilder"); builder.Host + .UseSystemd() .UseSerilog() .ConfigureServices((_, services) => { @@ -104,7 +103,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro Log.Verbose($"RunHandler PrepareSelfUpdate.end"); try { - await app.RunAsync(runServices.Lifetime.ApplicationLifetime.ApplicationStopping); + await app.StartAsync(runServices.Lifetime.ApplicationLifetime.ApplicationStopping); await runServices.SelfUpdater.StartSelfUpdate(Log.Logger, commonProperties.LauncherConfiguration, commonOptions.LauncherConfigurationFile); } From 24ca2b6335d854b6c0c336c31b80e85f69b074ca Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Tue, 9 Jan 2024 12:12:09 +0100 Subject: [PATCH 28/45] logging --- src/fiskaltrust.Launcher/Commands/RunCommand.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fiskaltrust.Launcher/Commands/RunCommand.cs b/src/fiskaltrust.Launcher/Commands/RunCommand.cs index a1a0edea..d21344e1 100644 --- a/src/fiskaltrust.Launcher/Commands/RunCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/RunCommand.cs @@ -68,6 +68,7 @@ public static class RunHandler public static async Task HandleAsync(CommonOptions commonOptions, CommonProperties commonProperties, RunOptions _, RunServices runServices) { Log.Verbose($"RunHandler call"); + Log.Verbose($"runServices.LauncherExecutablePath {runServices.LauncherExecutablePath.Path}"); var builder = WebApplication.CreateBuilder(); builder.Host .UseSystemd() From ce713fdd0081ca2f0939b1e506904b61dea0afcf Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Wed, 10 Jan 2024 07:59:29 +0100 Subject: [PATCH 29/45] further increase logging --- src/fiskaltrust.Launcher/Commands/RunCommand.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fiskaltrust.Launcher/Commands/RunCommand.cs b/src/fiskaltrust.Launcher/Commands/RunCommand.cs index d21344e1..0ef14d64 100644 --- a/src/fiskaltrust.Launcher/Commands/RunCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/RunCommand.cs @@ -70,6 +70,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro Log.Verbose($"RunHandler call"); Log.Verbose($"runServices.LauncherExecutablePath {runServices.LauncherExecutablePath.Path}"); var builder = WebApplication.CreateBuilder(); + Log.Verbose($"WebApplication.CreateBuilder()"); builder.Host .UseSystemd() .UseSerilog() From 96eba6bfa083422a73474cfd343c748d1c4687b6 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Wed, 10 Jan 2024 08:49:43 +0100 Subject: [PATCH 30/45] set start timeout --- src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs index d5efae44..401d13b6 100644 --- a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs +++ b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs @@ -74,6 +74,7 @@ private string[] GetServiceFileContent(string serviceDescription, string command "[Service]", "Type=notify", $"ExecStart={command}", + "TimeoutStartSec=180", "", "[Install]", "WantedBy = multi-user.target" From 75c85b84d153d3c215a07cf6fae0db5de61a3211 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:08:53 +0100 Subject: [PATCH 31/45] .. --- src/fiskaltrust.Launcher/Commands/RunCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fiskaltrust.Launcher/Commands/RunCommand.cs b/src/fiskaltrust.Launcher/Commands/RunCommand.cs index 0ef14d64..8ea0887e 100644 --- a/src/fiskaltrust.Launcher/Commands/RunCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/RunCommand.cs @@ -69,7 +69,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro { Log.Verbose($"RunHandler call"); Log.Verbose($"runServices.LauncherExecutablePath {runServices.LauncherExecutablePath.Path}"); - var builder = WebApplication.CreateBuilder(); + var builder = WebApplication.CreateBuilder(new string[0]); Log.Verbose($"WebApplication.CreateBuilder()"); builder.Host .UseSystemd() From b5dd0b9828038a51207b307b3060e3647c78f547 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:09:31 +0100 Subject: [PATCH 32/45] add working dir --- src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs index 401d13b6..d5b6cb7c 100644 --- a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs +++ b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs @@ -75,6 +75,7 @@ private string[] GetServiceFileContent(string serviceDescription, string command "Type=notify", $"ExecStart={command}", "TimeoutStartSec=180", + $"WorkingDirectory={Path.GetDirectoryName(_launcherExecutablePath.Path)}", "", "[Install]", "WantedBy = multi-user.target" From 5a80057821dcedb6a5a6103dd3ccb5c74cd2f832 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:48:11 +0100 Subject: [PATCH 33/45] further logging --- src/fiskaltrust.Launcher/Commands/RunCommand.cs | 2 +- src/fiskaltrust.Launcher/Download/PackageDownloader.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fiskaltrust.Launcher/Commands/RunCommand.cs b/src/fiskaltrust.Launcher/Commands/RunCommand.cs index 8ea0887e..0ef14d64 100644 --- a/src/fiskaltrust.Launcher/Commands/RunCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/RunCommand.cs @@ -69,7 +69,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro { Log.Verbose($"RunHandler call"); Log.Verbose($"runServices.LauncherExecutablePath {runServices.LauncherExecutablePath.Path}"); - var builder = WebApplication.CreateBuilder(new string[0]); + var builder = WebApplication.CreateBuilder(); Log.Verbose($"WebApplication.CreateBuilder()"); builder.Host .UseSystemd() diff --git a/src/fiskaltrust.Launcher/Download/PackageDownloader.cs b/src/fiskaltrust.Launcher/Download/PackageDownloader.cs index 5557e9b4..a2b35d1a 100644 --- a/src/fiskaltrust.Launcher/Download/PackageDownloader.cs +++ b/src/fiskaltrust.Launcher/Download/PackageDownloader.cs @@ -146,7 +146,7 @@ public async Task DownloadAsync(string name, string version, string platform, st return request; }); - + _logger?.LogInformation("response1"); response.EnsureSuccessStatusCode(); await using var fileStream = new FileStream(sourcePath, FileMode.Create, FileAccess.Write, FileShare.None); @@ -163,7 +163,7 @@ public async Task DownloadAsync(string name, string version, string platform, st return request; }); - + _logger?.LogInformation("response2"); response.EnsureSuccessStatusCode(); await File.WriteAllTextAsync($"{sourcePath}.hash", await response.Content.ReadAsStringAsync()); } From d242ce8868850e302fe39adfd9531472b264fabc Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Wed, 10 Jan 2024 12:37:07 +0100 Subject: [PATCH 34/45] set type forking --- src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs index d5b6cb7c..adeed8c6 100644 --- a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs +++ b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs @@ -72,7 +72,7 @@ private string[] GetServiceFileContent(string serviceDescription, string command $"Description=\"{serviceDescription}\"", "", "[Service]", - "Type=notify", + "Type=forking", $"ExecStart={command}", "TimeoutStartSec=180", $"WorkingDirectory={Path.GetDirectoryName(_launcherExecutablePath.Path)}", From 634aaa2bd320d0143b0dcfb18c27b590b80e2025 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Wed, 10 Jan 2024 13:04:22 +0100 Subject: [PATCH 35/45] use systemd in host --- src/fiskaltrust.Launcher/Commands/HostCommand.cs | 1 + src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fiskaltrust.Launcher/Commands/HostCommand.cs b/src/fiskaltrust.Launcher/Commands/HostCommand.cs index d50a079a..f6e80d98 100644 --- a/src/fiskaltrust.Launcher/Commands/HostCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/HostCommand.cs @@ -107,6 +107,7 @@ public static async Task HandleAsync(HostOptions hostOptions, HostServices System.Text.Encoding.RegisterProvider(new LauncherEncodingProvider()); var builder = Host.CreateDefaultBuilder() + .UseSystemd() .UseSerilog() .ConfigureServices(services => { diff --git a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs index adeed8c6..d5b6cb7c 100644 --- a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs +++ b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs @@ -72,7 +72,7 @@ private string[] GetServiceFileContent(string serviceDescription, string command $"Description=\"{serviceDescription}\"", "", "[Service]", - "Type=forking", + "Type=notify", $"ExecStart={command}", "TimeoutStartSec=180", $"WorkingDirectory={Path.GetDirectoryName(_launcherExecutablePath.Path)}", From 91f64e5ffd250a908b857e42852bda683b1d32a8 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Wed, 10 Jan 2024 13:31:54 +0100 Subject: [PATCH 36/45] .. --- src/fiskaltrust.Launcher/Commands/RunCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fiskaltrust.Launcher/Commands/RunCommand.cs b/src/fiskaltrust.Launcher/Commands/RunCommand.cs index 0ef14d64..74a362bc 100644 --- a/src/fiskaltrust.Launcher/Commands/RunCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/RunCommand.cs @@ -105,7 +105,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro Log.Verbose($"RunHandler PrepareSelfUpdate.end"); try { - await app.StartAsync(runServices.Lifetime.ApplicationLifetime.ApplicationStopping); + await app.RunAsync(runServices.Lifetime.ApplicationLifetime.ApplicationStopping); await runServices.SelfUpdater.StartSelfUpdate(Log.Logger, commonProperties.LauncherConfiguration, commonOptions.LauncherConfigurationFile); } From 8268885ff7958ff989afd03963fffc03f6890441 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Wed, 10 Jan 2024 14:10:45 +0100 Subject: [PATCH 37/45] set start timeout infinit --- src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs index d5b6cb7c..f432c3fd 100644 --- a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs +++ b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs @@ -76,6 +76,7 @@ private string[] GetServiceFileContent(string serviceDescription, string command $"ExecStart={command}", "TimeoutStartSec=180", $"WorkingDirectory={Path.GetDirectoryName(_launcherExecutablePath.Path)}", + "TimeoutStartUSec=infinity", "", "[Install]", "WantedBy = multi-user.target" From 23328cd43a41a9d7769db384fd82242b6e26b98b Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 11 Jan 2024 07:20:40 +0100 Subject: [PATCH 38/45] -- --- src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs index f432c3fd..3ec8c92e 100644 --- a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs +++ b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs @@ -74,7 +74,6 @@ private string[] GetServiceFileContent(string serviceDescription, string command "[Service]", "Type=notify", $"ExecStart={command}", - "TimeoutStartSec=180", $"WorkingDirectory={Path.GetDirectoryName(_launcherExecutablePath.Path)}", "TimeoutStartUSec=infinity", "", From 4237dc3e7f883e8e23f92482920d1f60f6e6cf07 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 11 Jan 2024 07:55:39 +0100 Subject: [PATCH 39/45] remove additional logging and tries --- src/fiskaltrust.Launcher/Commands/Common.cs | 13 +++---------- src/fiskaltrust.Launcher/Commands/DoctorCommand.cs | 2 +- src/fiskaltrust.Launcher/Commands/RunCommand.cs | 13 +++---------- .../Download/PackageDownloader.cs | 2 -- .../Extensions/DataProtectionExtensions.cs | 3 +-- 5 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/fiskaltrust.Launcher/Commands/Common.cs b/src/fiskaltrust.Launcher/Commands/Common.cs index 7bc41d10..74f0842f 100644 --- a/src/fiskaltrust.Launcher/Commands/Common.cs +++ b/src/fiskaltrust.Launcher/Commands/Common.cs @@ -83,12 +83,11 @@ public static async Task HandleAsync( Func> handler) where S : notnull { Log.Verbose("call CommonHandler HandleAsync"); - /* + var collectionSink = new CollectionSink(); Log.Logger = new LoggerConfiguration() .WriteTo.Sink(collectionSink) .CreateLogger(); - */ var launcherConfiguration = new LauncherConfiguration(); @@ -203,7 +202,6 @@ public static async Task HandleAsync( .Enrich.FromLogContext() .CreateLogger(); - /* foreach (var logEvent in collectionSink.Events) { Log.Write(logEvent); @@ -212,7 +210,7 @@ public static async Task HandleAsync( if (collectionSink.Events.Where(e => e.Level == LogEventLevel.Fatal).Any()) { return 1; - }*/ + } Log.Debug("Launcher Configuration File: {LauncherConfigurationFile}", options.LauncherConfigurationFile); Log.Debug("Cashbox Configuration File: {CashboxConfigurationFile}", launcherConfiguration.CashboxConfigurationFile); @@ -220,19 +218,14 @@ public static async Task HandleAsync( var dataProtectionProvider = DataProtectionExtensions.Create(launcherConfiguration.AccessToken, useFallback: launcherConfiguration.UseLegacyDataProtection!.Value); - Log.Verbose($"dataProtectionProvider is null: {dataProtectionProvider == null}"); try { - if (!launcherConfiguration.UseLegacyDataProtection!.Value) - { - launcherConfiguration.Decrypt(dataProtectionProvider.CreateProtector(LauncherConfiguration.DATA_PROTECTION_DATA_PURPOSE)); - } + launcherConfiguration.Decrypt(dataProtectionProvider.CreateProtector(LauncherConfiguration.DATA_PROTECTION_DATA_PURPOSE)); } catch (Exception e) { Log.Warning(e, "Error decrypring launcher configuration file."); } - Log.Verbose($"finished handler"); return await handler(options, new CommonProperties(launcherConfiguration, cashboxConfiguration, clientEcdh, dataProtectionProvider), specificOptions, host.Services.GetRequiredService()); } diff --git a/src/fiskaltrust.Launcher/Commands/DoctorCommand.cs b/src/fiskaltrust.Launcher/Commands/DoctorCommand.cs index 230cb224..9007e414 100644 --- a/src/fiskaltrust.Launcher/Commands/DoctorCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/DoctorCommand.cs @@ -124,7 +124,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro } var dataProtectionProvider = checkUp.Check("Setup data protection", () => DataProtectionExtensions.Create(launcherConfiguration.AccessToken, useFallback: launcherConfiguration.UseLegacyDataProtection!.Value)); - if (dataProtectionProvider is not null && !launcherConfiguration.UseLegacyDataProtection!.Value) + if (dataProtectionProvider is not null) { checkUp.Check("Decrypt launcher configuration", () => launcherConfiguration.Decrypt(dataProtectionProvider.CreateProtector(LauncherConfiguration.DATA_PROTECTION_DATA_PURPOSE))); } diff --git a/src/fiskaltrust.Launcher/Commands/RunCommand.cs b/src/fiskaltrust.Launcher/Commands/RunCommand.cs index 74a362bc..28db3b63 100644 --- a/src/fiskaltrust.Launcher/Commands/RunCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/RunCommand.cs @@ -67,10 +67,7 @@ public static class RunHandler { public static async Task HandleAsync(CommonOptions commonOptions, CommonProperties commonProperties, RunOptions _, RunServices runServices) { - Log.Verbose($"RunHandler call"); - Log.Verbose($"runServices.LauncherExecutablePath {runServices.LauncherExecutablePath.Path}"); var builder = WebApplication.CreateBuilder(); - Log.Verbose($"WebApplication.CreateBuilder()"); builder.Host .UseSystemd() .UseSerilog() @@ -87,7 +84,6 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro services.AddSingleton(_ => runServices.LauncherExecutablePath); }); - Log.Verbose($"RunHandler builder.Host"); builder.WebHost.ConfigureBinding(new Uri($"http://[::1]:{commonProperties.LauncherConfiguration.LauncherPort}"), protocols: HttpProtocols.Http2); builder.Services.AddCodeFirstGrpc(); @@ -98,11 +94,9 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro #pragma warning disable ASP0014 app.UseEndpoints(endpoints => endpoints.MapGrpcService()); #pragma warning restore ASP0014 - Log.Verbose($"RunHandler PrepareSelfUpdate.call"); - try { - await runServices.SelfUpdater.PrepareSelfUpdate(Log.Logger, commonProperties.LauncherConfiguration, app.Services.GetRequiredService()); - } catch (Exception e) { Log.Error(e, "An unhandled exception occured."); return 1;} - Log.Verbose($"RunHandler PrepareSelfUpdate.end"); + + await runServices.SelfUpdater.PrepareSelfUpdate(Log.Logger, commonProperties.LauncherConfiguration, app.Services.GetRequiredService()); + try { await app.RunAsync(runServices.Lifetime.ApplicationLifetime.ApplicationStopping); @@ -118,7 +112,6 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro { Log.CloseAndFlush(); } - Log.Verbose($"RunHandler end"); return 0; } } diff --git a/src/fiskaltrust.Launcher/Download/PackageDownloader.cs b/src/fiskaltrust.Launcher/Download/PackageDownloader.cs index a2b35d1a..89ee1958 100644 --- a/src/fiskaltrust.Launcher/Download/PackageDownloader.cs +++ b/src/fiskaltrust.Launcher/Download/PackageDownloader.cs @@ -146,7 +146,6 @@ public async Task DownloadAsync(string name, string version, string platform, st return request; }); - _logger?.LogInformation("response1"); response.EnsureSuccessStatusCode(); await using var fileStream = new FileStream(sourcePath, FileMode.Create, FileAccess.Write, FileShare.None); @@ -163,7 +162,6 @@ public async Task DownloadAsync(string name, string version, string platform, st return request; }); - _logger?.LogInformation("response2"); response.EnsureSuccessStatusCode(); await File.WriteAllTextAsync($"{sourcePath}.hash", await response.Content.ReadAsStringAsync()); } diff --git a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs index 5255d8ec..39f858a8 100644 --- a/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/DataProtectionExtensions.cs @@ -200,7 +200,7 @@ public static IDataProtectionBuilder ProtectKeysCustom(this IDataProtectionBuild } else if (OperatingSystem.IsLinux()) { - Log.Warning("Fallback config encryption mechanism used."); + Log.Warning("Fallback config encryption mechanism is used on linux."); } else if (OperatingSystem.IsMacOS()) { @@ -210,7 +210,6 @@ public static IDataProtectionBuilder ProtectKeysCustom(this IDataProtectionBuild Log.Debug("Fallback config encryption mechanism used."); builder.Services.Configure(options => options.XmlEncryptor = new LegacyXmlEncryptor(builder.Services)); - Log.Verbose("config KeyManagementOptions"); return builder; } } From bd3ddfd99fd0a9bbf7d3fb435d9cfeadfa1f5544 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 11 Jan 2024 09:20:48 +0100 Subject: [PATCH 40/45] set timoutstart and timeoutstartu --- src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs index 3ec8c92e..e2ff6a63 100644 --- a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs +++ b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs @@ -74,6 +74,7 @@ private string[] GetServiceFileContent(string serviceDescription, string command "[Service]", "Type=notify", $"ExecStart={command}", + "TimeoutStartSec=infinit", $"WorkingDirectory={Path.GetDirectoryName(_launcherExecutablePath.Path)}", "TimeoutStartUSec=infinity", "", From 475fcfd28ba0174d7cad59741cc922ae544cd659 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 11 Jan 2024 10:22:47 +0100 Subject: [PATCH 41/45] set timout --- src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs index e2ff6a63..ee495c47 100644 --- a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs +++ b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs @@ -74,9 +74,8 @@ private string[] GetServiceFileContent(string serviceDescription, string command "[Service]", "Type=notify", $"ExecStart={command}", - "TimeoutStartSec=infinit", + "TimeoutSec=0", $"WorkingDirectory={Path.GetDirectoryName(_launcherExecutablePath.Path)}", - "TimeoutStartUSec=infinity", "", "[Install]", "WantedBy = multi-user.target" From 40c3454076e7c7dd4bce7971ca886a85d5a93486 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 11 Jan 2024 11:18:40 +0100 Subject: [PATCH 42/45] use SystemdHelper and Customized Timeline --- src/fiskaltrust.Launcher/Commands/RunCommand.cs | 8 -------- .../Extensions/LifetimeExtensions.cs | 11 ++--------- .../ServiceInstallation/LinuxSystemD.cs | 16 +++------------- 3 files changed, 5 insertions(+), 30 deletions(-) diff --git a/src/fiskaltrust.Launcher/Commands/RunCommand.cs b/src/fiskaltrust.Launcher/Commands/RunCommand.cs index 28db3b63..dc242a5e 100644 --- a/src/fiskaltrust.Launcher/Commands/RunCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/RunCommand.cs @@ -1,5 +1,4 @@ using System.CommandLine; -using System.CommandLine.Invocation; using fiskaltrust.Launcher.ProcessHost; using fiskaltrust.Launcher.Services; using Serilog; @@ -8,12 +7,6 @@ using fiskaltrust.Launcher.Extensions; using fiskaltrust.Launcher.Helpers; using Microsoft.AspNetCore.Server.Kestrel.Core; -using fiskaltrust.Launcher.Common.Configuration; -using fiskaltrust.storage.serialization.V0; -using System.Security.Cryptography; -using Microsoft.AspNetCore.DataProtection; -using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.Hosting.Server.Features; namespace fiskaltrust.Launcher.Commands @@ -40,7 +33,6 @@ public RunCommand(string name = "run", bool addCliOnlyParameters = true) : base( AddOption(new Option("--tls-certificate-password")); AddOption(new Option("--use-http-sys-binding")); AddOption(new Option("--use-legacy-data-protection")); - AddOption(new Option("--is-systemd-service")); } } diff --git a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs index f06e092c..585fd2c7 100644 --- a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs @@ -1,6 +1,5 @@ using System.Runtime.Versioning; using System.Text; -using System.Web.Services.Description; using Microsoft.Extensions.Hosting.Systemd; using Microsoft.Extensions.Hosting.WindowsServices; using Microsoft.Extensions.Options; @@ -11,8 +10,6 @@ static class LifetimeExtensions { public static IHostBuilder UseCustomHostLifetime(this IHostBuilder builder, string[] args) { - var isSystemd = args.Contains("--is-systemd-service true"); - if (WindowsServiceHelpers.IsWindowsService()) { builder.UseWindowsService(); @@ -32,12 +29,8 @@ public static IHostBuilder UseCustomHostLifetime(this IHostBuilder builder, stri #pragma warning restore CA1416 }); } - else if (isSystemd) + else if (SystemdHelpers.IsSystemdService()) { - builder.UseSystemd(); - builder.ConfigureServices(services => services.AddSingleton()); - return builder; - /* return builder.ConfigureServices(services => { var lifetime = services.FirstOrDefault(s => s.ImplementationType == typeof(SystemdLifetime)); @@ -51,7 +44,7 @@ public static IHostBuilder UseCustomHostLifetime(this IHostBuilder builder, stri services.AddSingleton(); services.AddSingleton(sp => sp.GetRequiredService()); #pragma warning restore CA1416 - });*/ + }); } else { diff --git a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs index 5a6e8c32..8ebca94c 100644 --- a/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs +++ b/src/fiskaltrust.Launcher/ServiceInstallation/LinuxSystemD.cs @@ -1,4 +1,5 @@ using fiskaltrust.Launcher.Helpers; +using Microsoft.Extensions.Hosting.Systemd; using Serilog; namespace fiskaltrust.Launcher.ServiceInstallation @@ -15,11 +16,10 @@ public LinuxSystemD(string? serviceName, LauncherExecutablePath launcherExecutab public override async Task InstallService(string commandArgs, string? displayName, bool delayedStart = false) { - if (!await IsSystemd()) + if (!SystemdHelpers.IsSystemdService()) { return -1; } - commandArgs += " --is-systemd-service true"; Log.Information("Installing service via systemd."); var serviceFileContent = GetServiceFileContent(displayName ?? "Service installation of fiskaltrust launcher.", commandArgs); var serviceFilePath = Path.Combine(_servicePath, $"{_serviceName}.service"); @@ -33,7 +33,7 @@ public override async Task InstallService(string commandArgs, string? displ public override async Task UninstallService() { - if (!await IsSystemd()) + if (!SystemdHelpers.IsSystemdService()) { return -1; } @@ -50,16 +50,6 @@ public override async Task UninstallService() return (await ProcessHelper.RunProcess("systemctl", new[] { "reset-failed" })).exitCode; } - private static async Task IsSystemd() - { - var (exitCode, output) = await ProcessHelper.RunProcess("ps", new[] { "--no-headers", "-o", "comm", "1" }); - if (exitCode != 0 && output.Contains("systemd")) - { - Log.Error("Service installation works only for systemd setup."); - return false; - } - return true; - } private string[] GetServiceFileContent(string serviceDescription, string commandArgs) { From f04e29c20621eb3736fa8549f8a9901183414027 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 11 Jan 2024 11:24:16 +0100 Subject: [PATCH 43/45] :: --- .../Configuration/Configuration.cs | 4 ---- src/fiskaltrust.Launcher/Commands/RunCommand.cs | 2 +- src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs | 2 +- src/fiskaltrust.Launcher/Program.cs | 2 +- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/fiskaltrust.Launcher.Common/Configuration/Configuration.cs b/src/fiskaltrust.Launcher.Common/Configuration/Configuration.cs index cea77163..6f6f7232 100644 --- a/src/fiskaltrust.Launcher.Common/Configuration/Configuration.cs +++ b/src/fiskaltrust.Launcher.Common/Configuration/Configuration.cs @@ -163,10 +163,6 @@ private T WithDefault(T value, Func defaultValue) [JsonPropertyName("useLegacyDataProtection")] public bool? UseLegacyDataProtection { get => WithDefault(_useLegacyDataProtection, false); set => _useLegacyDataProtection = value; } - private bool? _isSystemdService; - [JsonPropertyName("isSystemdService")] - public bool? IsSystemdService { get => WithDefault(_useLegacyDataProtection, false); set => _useLegacyDataProtection = value; } - private SemanticVersioning.Range? _launcherVersion = null; [JsonPropertyName("launcherVersion")] [JsonConverter(typeof(SemVersionConverter))] diff --git a/src/fiskaltrust.Launcher/Commands/RunCommand.cs b/src/fiskaltrust.Launcher/Commands/RunCommand.cs index dc242a5e..4301f576 100644 --- a/src/fiskaltrust.Launcher/Commands/RunCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/RunCommand.cs @@ -87,7 +87,7 @@ public static async Task HandleAsync(CommonOptions commonOptions, CommonPro app.UseEndpoints(endpoints => endpoints.MapGrpcService()); #pragma warning restore ASP0014 - await runServices.SelfUpdater.PrepareSelfUpdate(Log.Logger, commonProperties.LauncherConfiguration, app.Services.GetRequiredService()); + await runServices.SelfUpdater.PrepareSelfUpdate(Log.Logger, commonProperties.LauncherConfiguration, app.Services.GetRequiredService()); try { diff --git a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs index 585fd2c7..820e4daa 100644 --- a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs @@ -8,7 +8,7 @@ namespace fiskaltrust.Launcher.Extensions { static class LifetimeExtensions { - public static IHostBuilder UseCustomHostLifetime(this IHostBuilder builder, string[] args) + public static IHostBuilder UseCustomHostLifetime(this IHostBuilder builder) { if (WindowsServiceHelpers.IsWindowsService()) { diff --git a/src/fiskaltrust.Launcher/Program.cs b/src/fiskaltrust.Launcher/Program.cs index 87009bad..7efbafff 100644 --- a/src/fiskaltrust.Launcher/Program.cs +++ b/src/fiskaltrust.Launcher/Program.cs @@ -49,7 +49,7 @@ .UseHost( host => { - host.UseCustomHostLifetime(args); + host.UseCustomHostLifetime(); host.ConfigureServices(services => services .Configure(opts => opts.ShutdownTimeout = TimeSpan.FromSeconds(45)) From 217a87a9c8113012350a83b26813e2df7e7a7991 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 11 Jan 2024 12:08:40 +0100 Subject: [PATCH 44/45] .. --- src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs index 820e4daa..e7f045e8 100644 --- a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs @@ -31,6 +31,7 @@ public static IHostBuilder UseCustomHostLifetime(this IHostBuilder builder) } else if (SystemdHelpers.IsSystemdService()) { + builder.UseSystemd(); return builder.ConfigureServices(services => { var lifetime = services.FirstOrDefault(s => s.ImplementationType == typeof(SystemdLifetime)); From 53dce297f64bddb7e6e153cda5f6a0c9107a927c Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Thu, 11 Jan 2024 12:25:21 +0100 Subject: [PATCH 45/45] .. --- .../Extensions/LifetimeExtensions.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs index e7f045e8..7230b118 100644 --- a/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs +++ b/src/fiskaltrust.Launcher/Extensions/LifetimeExtensions.cs @@ -32,20 +32,17 @@ public static IHostBuilder UseCustomHostLifetime(this IHostBuilder builder) else if (SystemdHelpers.IsSystemdService()) { builder.UseSystemd(); + builder.ConfigureServices(services => services.AddSingleton()); + return builder; + /* return builder.ConfigureServices(services => { var lifetime = services.FirstOrDefault(s => s.ImplementationType == typeof(SystemdLifetime)); - - if (lifetime != null) - { - services.Remove(lifetime); - } - -#pragma warning disable CA1416 +@@ -51,7 +44,7 @@ public static IHostBuilder UseCustomHostLifetime(this IHostBuilder builder, stri services.AddSingleton(); services.AddSingleton(sp => sp.GetRequiredService()); #pragma warning restore CA1416 - }); + });*/ } else {