diff --git a/tools/windows/DatadogAgentInstaller/WixSetup/Datadog/AgentInstaller.cs b/tools/windows/DatadogAgentInstaller/WixSetup/Datadog/AgentInstaller.cs index 77cce0e5231ea..d796af3d9c378 100644 --- a/tools/windows/DatadogAgentInstaller/WixSetup/Datadog/AgentInstaller.cs +++ b/tools/windows/DatadogAgentInstaller/WixSetup/Datadog/AgentInstaller.cs @@ -129,6 +129,14 @@ public Project ConfigureProject() } ); + // Ensures that the "change" dialog also reinstall the product. + project.AddAction(new SetPropertyAction("REINSTALL", "ALL") + { + Condition = Conditions.Maintenance, + When = When.After, + Step = Step.FindRelatedProducts + }); + // Conditionally include the PROCMON MSM while it is in active development to make it easier // to build/ship without it. if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WINDOWS_DDPROCMON_DRIVER"))) @@ -310,6 +318,15 @@ public Project ConfigureProject() .First(x => x.HasAttribute("Id", value => value == "MainApplication")) .AddElement("MergeRef", "Id=ddprocmoninstall"); } + + // Configure the service when the parent Component is reinstalled + // This doesn't concerns the service permissions but the DelayedAutoStart, PreShutdownDelay etc... + document.FindAll("ServiceConfig") + .Where(sc => sc.HasAttribute("OnReinstall")) + .ForEach(sc => sc.SetAttributeValue("OnReinstall", "yes")); + + // Always remove service, this will reset the service permissions. + document.FindSingle("DeleteServices").SetValue(Condition.Always); }; project.WixSourceFormated += (ref string content) => WixSourceFormated?.Invoke(content); project.WixSourceSaved += name => WixSourceSaved?.Invoke(name); @@ -402,7 +419,9 @@ private static ServiceInstaller GenerateServiceInstaller(string name, string dis StopOn = null, Start = SvcStartType.auto, DelayedAutoStart = true, - RemoveOn = SvcEvent.Uninstall_Wait, + // Specifies that the service should be removed by the DeleteServices action on both install and uninstall. + // This ensures that if there is a (perhaps orphaned) service with the same name we remove it first. + RemoveOn = SvcEvent.InstallUninstall_Wait, ServiceSid = ServiceSid.none, FirstFailureActionType = FailureActionType.restart, SecondFailureActionType = FailureActionType.restart, @@ -437,7 +456,9 @@ private static ServiceInstaller GenerateDependentServiceInstaller( // Tell MSI not to stop the services. We handle service stop manually in StopDDServices custom action. StopOn = null, Start = SvcStartType.demand, - RemoveOn = SvcEvent.Uninstall_Wait, + // Specifies that the service should be removed by the DeleteServices action on both install and uninstall. + // This ensures that if there is a (perhaps orphaned) service with the same name we remove it first. + RemoveOn = SvcEvent.InstallUninstall_Wait, ServiceSid = ServiceSid.none, FirstFailureActionType = FailureActionType.restart, SecondFailureActionType = FailureActionType.restart,