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

Backport(v5) msi: keep some registry values with update (#777) #779

Merged
merged 1 commit into from
Feb 3, 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
45 changes: 45 additions & 0 deletions fluent-package/msi/source.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<ComponentRef Id="FluentConf" />
<ComponentRef Id="FluentAcl" />
<ComponentRef Id="FluentdBat" />
<ComponentGroupRef Id="KeepUserRegistryConfiguration" />
</Feature>

<!-- UI Stuff -->
Expand All @@ -159,6 +160,50 @@
<WixVariable Id="WixUIExclamationIco" Value="assets\icon.ico" />
<WixVariable Id="WixUIInfoIco" Value="assets\icon.ico" />

<!-- Save old some registry values -->
<Property Id="REGISTRY_START_OLD">
<RegistrySearch Id="RegistrySearchStart" Root="HKLM" Key="System\CurrentControlSet\Services\fluentdwinsvc" Name="Start" Type="raw" />
</Property>
<Property Id="REGISTRY_DELAYEDAUTOSTART_OLD">
<RegistrySearch Id="RegistrySearchDelayedAutostart" Root="HKLM" Key="System\CurrentControlSet\Services\fluentdwinsvc" Name="DelayedAutostart" Type="raw" />
</Property>
<Property Id="REGISTRY_FLUENTDOPT_OLD">
<RegistrySearch Id="RegistrySearchFluentdopt" Root="HKLM" Key="System\CurrentControlSet\Services\fluentdwinsvc" Name="fluentdopt" Type="raw" />
</Property>

<!-- Restore some registry values -->
<ComponentGroup Id="KeepUserRegistryConfiguration" Directory="FLUENTPROJECTLOCATION">
<!--
CAUTION: We cannot use `integer` type for values being read by RegistrySearch. Use `string` instead.
DETAIL: RegistrySearch reads a raw value and the value could have a prefix according to the data type.
For example, integer (DWORD) value has a `#` prefix.
If writing such a value (e.g., `#2`) by `RegistryValue` with `integer` type, it is forced to be recognized as `REG_SZ` type after all, and it breaks the service.
We want to remove the prefix before `RegistryValue`, but it is hard to do with WiX.
However, using `string` type can handle such raw values.
For example, if writing `#2` by `RegistryValue` with `string` type, it is written as `2` with `REG_DWORD` type.
(Though this is undocumented... https://wixtoolset.org/docs/v3/xsd/wix/registryvalue/)
Thus, it is better to use `string` type to handle such raw values in this context because of no need to care about '#' prefix.
-->

<!-- Start -->
<Component Id="SetRegistryStart" Guid="5759ebf0-a248-4e78-82be-9334421100b2">
<Condition><![CDATA[REGISTRY_START_OLD<>""]]></Condition>
<RegistryValue Id="RegistryValueStart" Root="HKLM" Key="System\CurrentControlSet\Services\fluentdwinsvc" Name="Start" Value="[REGISTRY_START_OLD]" Type="string" KeyPath="yes" />
</Component>

<!-- DelayedAutostart -->
<Component Id="SetRegistryDelayedAutostart" Guid="8cb98306-8219-400f-b8b3-e5ffca828cd4">
<Condition><![CDATA[REGISTRY_DELAYEDAUTOSTART_OLD<>""]]></Condition>
<RegistryValue Id="RegistryValueDelayedAutostart" Root="HKLM" Key="System\CurrentControlSet\Services\fluentdwinsvc" Name="DelayedAutostart" Value="[REGISTRY_DELAYEDAUTOSTART_OLD]" Type="string" KeyPath="yes" />
</Component>

<!-- fluentdopt -->
<Component Id="SetRegistryFleuntdopt" Guid="c94bc7e4-9cf2-4b8c-925f-e015958a94e9">
<Condition><![CDATA[REGISTRY_FLUENTDOPT_OLD<>""]]></Condition>
<RegistryValue Id="RegistryValueFleuntdopt" Root="HKLM" Key="System\CurrentControlSet\Services\fluentdwinsvc" Name="fluentdopt" Value="[REGISTRY_FLUENTDOPT_OLD]" Type="string" KeyPath="yes" />
</Component>
</ComponentGroup>

<!-- Settle paths in executables generated by RubyGems -->
<Property Id="PostInstall" Value=" "/>
<CustomAction Id="SetPostInstallCommand"
Expand Down
14 changes: 13 additions & 1 deletion fluent-package/msi/update-from-v5-test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ $newConfig = @'
'@
Add-Content -Path "C:\\opt\\td-agent\\etc\\td-agent\\fluentd.conf" -Encoding UTF8 -Value $newConfig

# Edit fluentdopt and autostart
C:\opt\fluent\bin\fluentd.bat --reg-winsvc-fluentdopt "-c C:\opt\fluent\etc\fluent\fluentd.conf -o C:\opt\td-agent\td-agent.log"
sc.exe config fluentdwinsvc start=delayed-auto

# Update to the new package
Start-Process msiexec -ArgumentList "/i", $newPackage, "/quiet" -Wait
Start-Service fluentdwinsvc
Expand All @@ -50,4 +54,12 @@ if ($outputFilesAfterSleep.Count -le $outputFiles.Count) {
Write-Error ("The previous config does not work. Output file num: {0} to {1}." -f $outputFiles.Count, $outputFilesAfterSleep.Count)
}

# TODO: Add tests here when it becomes able to take over the fluentdopt and autostart configuration.
# Test: Take over fluentdopt and autostart config
REG QUERY HKLM\System\CurrentControlSet\Services\fluentdwinsvc | ?{$_ -match "^\s+fluentdopt\s+REG_SZ\s+(?<fluentdopt>.+)\s*$"}
if ($Matches.fluentdopt -ne "-c C:\opt\fluent\etc\fluent\fluentd.conf -o C:\opt\td-agent\td-agent.log") {
Write-Error "fluentdopt is not preserved: $($Matches.fluentdopt)"
}
$startType = (Get-Service fluentdwinsvc).StartType
if ($startType -ne "Automatic") {
Write-Error "StartType is not preserved: $startType"
}
Loading