Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet Installer] Don't block uninstall if IIS isn't available #6676

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions tracer/src/Datadog.FleetInstaller/Commands/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Datadog.FleetInstaller.Commands;

/// <summary>
/// Remove all version of the .NET tracer. Should be called for each version to be removed.
/// Perform the final uninstall for the product
/// </summary>
internal class UninstallProductCommand : CommandBase
{
Expand All @@ -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
Expand Down
Loading