diff --git a/tracer/src/Datadog.FleetInstaller/Commands/CommandBase.cs b/tracer/src/Datadog.FleetInstaller/Commands/CommandBase.cs index bf7882a3d1a2..79f4dc666e4a 100644 --- a/tracer/src/Datadog.FleetInstaller/Commands/CommandBase.cs +++ b/tracer/src/Datadog.FleetInstaller/Commands/CommandBase.cs @@ -6,6 +6,7 @@ using System.CommandLine; using System.CommandLine.Invocation; using System.CommandLine.Parsing; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using System.Security.Principal; using System.Threading.Tasks; @@ -35,18 +36,24 @@ protected bool IsValidEnvironment(CommandResult commandResult) return false; } + return true; + } + + protected bool HasValidIIsVersion(ILogger commandResult, [NotNullWhen(false)] out string? errorMessage) + { if (!RegistryHelper.TryGetIisVersion(Log.Instance, out var version)) { - commandResult.ErrorMessage = "This installer requires IIS 10.0 or later. Could not determine the IIS version; is the IIS feature enabled?"; + errorMessage = "This installer requires IIS 10.0 or later. Could not determine the IIS version; is the IIS feature enabled?"; return false; } if (version.Major < 10) { - commandResult.ErrorMessage = $"This installer requires IIS 10.0 or later. Detected IIS version {version.Major}.{version.Minor}"; + errorMessage = $"This installer requires IIS 10.0 or later. Detected IIS version {version.Major}.{version.Minor}"; return false; } + errorMessage = null; return true; } } diff --git a/tracer/src/Datadog.FleetInstaller/Commands/InstallCommand.cs b/tracer/src/Datadog.FleetInstaller/Commands/InstallCommand.cs index adaa27937b99..99e43df3d2fa 100644 --- a/tracer/src/Datadog.FleetInstaller/Commands/InstallCommand.cs +++ b/tracer/src/Datadog.FleetInstaller/Commands/InstallCommand.cs @@ -88,6 +88,12 @@ private void Validate(CommandResult commandResult) return; } + if (!HasValidIIsVersion(Log.Instance, out var errorMessage)) + { + commandResult.ErrorMessage = errorMessage; + return; + } + var path = commandResult.GetValueForOption(_versionedPathOption); if (path is not null && !FileHelper.TryVerifyFilesExist(Log.Instance, new TracerValues(path), out var err)) { diff --git a/tracer/src/Datadog.FleetInstaller/Commands/UninstallProductCommand.cs b/tracer/src/Datadog.FleetInstaller/Commands/UninstallProductCommand.cs index 36572e116253..9509cd0a8c59 100644 --- a/tracer/src/Datadog.FleetInstaller/Commands/UninstallProductCommand.cs +++ b/tracer/src/Datadog.FleetInstaller/Commands/UninstallProductCommand.cs @@ -11,7 +11,7 @@ namespace Datadog.FleetInstaller.Commands; /// -/// Remove all version of the .NET tracer. Should be called for each version to be removed. +/// Perform the final uninstall for the product /// internal class UninstallProductCommand : CommandBase { @@ -33,17 +33,27 @@ public Task ExecuteAsync(InvocationContext context) } // Internal for testing - internal static ReturnCode Execute(ILogger log) + internal ReturnCode Execute(ILogger log) { log.WriteInfo("Uninstalling .NET tracer product"); - // Remove the tracer references - if (!AppHostHelper.RemoveAllEnvironmentVariables(log)) + if (!HasValidIIsVersion(log, out var errorMessage)) { - // hard to be sure exactly of the state at this point, - // but probably don't want to do anything else if we couldn't remove the variables, - // as apps may fail - return ReturnCode.ErrorRemovingAppPoolVariables; + // IIS isn't available, weird because it means they removed it _after_ installing the product + // but whatever, there's no variables there if that's the case! + Log.Instance.WriteInfo(errorMessage); + Log.Instance.WriteInfo("Unable to uninstall from IIS, skipping IIS removal and continuing"); + } + else + { + // Remove the tracer references + if (!AppHostHelper.RemoveAllEnvironmentVariables(log)) + { + // hard to be sure exactly of the state at this point, + // but probably don't want to do anything else if we couldn't remove the variables, + // as apps may fail + return ReturnCode.ErrorRemovingAppPoolVariables; + } } // Should we clean up/delete the log folder? Probably not, as it may contain useful information