@cryptotaxi247 / netdata-1 / commits / e80fdfdc2

fix MSI installer (#19962)

* allow users to install any version; stop netdata before installing the update * fix compatibility with wix 4 * fix-msi: Remove conflict between options (https://docs.firegiant.com/wix3/xsd/wix/majorupgrade/) * fix-msi: Comment not allowed code. We cannot have more than one primary key listed (FileInUse) * fix-msi: Add Power Shell script to be called after installation * fix-msi: Copy power shell script to installer. * fix-msi: Add option to do download and move PS file * fix-msi: First try run at the end * iis_ad: Fix wrong execution order and call to powershell * fix-msi: Add messages and test to Power Shell script --------- Co-authored-by: thiagoftsm <thiagoftsm@gmail.com>

Costa Tsaousis committed Mar 27, 2025 at 21:14 UTC e80fdfdc209fccda554fc255d1c01f6a57514b57
3 files changed +76 -8
packaging/windows/copy_files.ps1 new
+42
@@ -0,0 +1,42 @@
1 +
2 +Function NetdataCopyConfig {
3 + param ($dst, $src, $file)
4 +
5 + Write-Host "Creating $file if it does not exist!"
6 +
7 + $testDST = "$dst\$file"
8 + $testSRC = "$src\$file"
9 + if (-Not (Test-Path $testDST)) {
10 + if (Test-Path $testSRC) {
11 + robocopy /xc /xn /xo $src $dst $file
12 + }
13 + }
14 +}
15 +
16 +Function NetdataDownloadNetdataConfig {
17 + param ($path)
18 +
19 + Write-Host "Creating netdata.conf if it does not exist!"
20 +
21 + $netdataConfPATH = "$path\netdata.conf"
22 + $netdataConfURL = "http://localhost:19999/netdata.conf"
23 + if (Test-Path $netdataConfPATH) {
24 + exit 0
25 + }
26 +
27 + try {
28 + Invoke-WebRequest $netdataConfURL -OutFile $netdataConfPATH
29 + }
30 + catch {
31 + New-Item -Path "$netdataConfPATH" -ItemType File
32 + }
33 +}
34 +
35 +$confPath = "C:\Program Files\Netdata\etc\netdata";
36 +$stockStreamPath = "C:\Program Files\Netdata\usr\lib\netdata\conf.d";
37 +
38 +NetdataCopyConfig $confPath $stockStreamPath "stream.conf"
39 +
40 +NetdataDownloadNetdataConfig $confPath
41 +
42 +exit 0;
packaging/windows/netdata.wxs.in
+33 -8
@@ -12,7 +12,8 @@
12
13 <Media Id="1" Cabinet="netdata" EmbedCab="yes" />
14
15 - <MajorUpgrade Schedule="afterInstallInitialize" DowngradeErrorMessage="A newer version of [ProductName] is already installed." AllowSameVersionUpgrades="yes" />
15 + <!-- Modified: Changed schedule to handle service shutdown more gracefully and allow downgrades -->
16 + <MajorUpgrade Schedule="afterInstallValidate" AllowDowngrades="yes" />
17 <Icon Id="NetdataIcon.ico" SourceFile="NetdataWhite.ico"/>
18 <Property Id="ARPPRODUCTICON" Value="NetdataIcon.ico" />
19
@@ -27,6 +28,9 @@
28
29 <Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
30
31 + <!-- Added to handle FilesInUse dialog -->
32 + <Property Id="MSIRESTARTMANAGERCONTROL" Value="DisableShutdown" />
33 +
34 <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Access Netdata dashboard" />
35 <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOX" Value="1" />
36 <Property Id="WixShellExecTarget" Value="http://localhost:19999" />
@@ -50,6 +54,9 @@
54 <Directory Id="INSTALLFOLDER" Name="Netdata">
55 <Directory Id="USRDIR" Name="usr">
56 <Directory Id="USRBINDIR" Name="bin" />
57 + <Directory Id="USRLIBEXECDIR" Name="libexec">
58 + <Directory Id="USRLIBEXECNETDATADIR" Name="netdata" />
59 + </Directory>
60 </Directory>
61 <Directory Id="VARDIR" Name="var">
62 <Directory Id="VARCACHEDIR" Name="cache" />
@@ -133,6 +140,12 @@
140 <Custom Action="ClaimAgent" After="InstallFiles" />
141 </InstallExecuteSequence>
142
143 + <!-- Add new files (stream.conf and netdata.conf) -->
144 + <CustomAction Id="NDCreateNewFiles" Directory="USRLIBEXECNETDATADIR" ExeCommand='powershell.exe -ExecutionPolicy Bypass -NonInteractive -File &quot;[USRLIBEXECNETDATADIR]\copy_files.ps1&quot;' Execute="deferred" Return="ignore" Impersonate="no"/>
145 + <InstallExecuteSequence>
146 + <Custom Action="NDCreateNewFiles" Before="InstallFinalize" />
147 + </InstallExecuteSequence>
148 +
149 <!-- Install wevt manifest/dll files -->
150 <ComponentGroup Id="WevtComponents" Directory="System64Folder">
151 <File Id="WevtDll" Name="wevt_netdata.dll" Source="C:\msys64\opt\netdata\usr\bin\wevt_netdata.dll">
@@ -152,6 +165,12 @@
165 <Custom Action="InstallManifest" After="InstallFiles" />
166 </InstallExecuteSequence>
167
168 + <!-- Added StopNetdataService custom action to ensure service is stopped before file operations -->
169 + <CustomAction Id="StopNetdataService" Directory="System64Folder" ExeCommand='net stop Netdata' Execute="immediate" Return="ignore" />
170 + <InstallExecuteSequence>
171 + <Custom Action="StopNetdataService" Before="InstallValidate" Condition="Installed AND NOT REMOVE" />
172 + </InstallExecuteSequence>
173 +
174 <Component Id="NetdataService" Directory="USRBINDIR">
175 <File Id="netdata.exe" Source="C:\msys64\opt\netdata\usr\bin\netdata.exe" KeyPath="yes" />
176
@@ -163,11 +182,12 @@
182 Start="auto"
183 ErrorControl="normal" />
184
185 + <!-- Modified to ensure proper service handling during update -->
186 <ServiceControl Id="ControlService"
167 - Start="install"
187 + Name="Netdata"
188 Stop="both"
189 + Start="install"
190 Remove="uninstall"
170 - Name="Netdata"
191 Wait="yes" />
192
193 <RegistryValue Root="HKLM"
@@ -227,6 +247,12 @@
247 <Publish Dialog="MaintenanceTypeDlg" Control="RemoveButton" Event="NewDialog" Value="VerifyReadyDlg" />
248 <Publish Dialog="MaintenanceTypeDlg" Control="Back" Event="NewDialog" Value="MaintenanceWelcomeDlg" />
249
250 + <!-- Next lines have Primary Key dupplication avoiding binary to be generated -->
251 + <!-- Handle files in use dialog elegantly>
252 + <Publish Dialog="FilesInUse" Control="Retry" Event="EndDialog" Value="Retry" Order="1" />
253 + <Publish Dialog="FilesInUse" Control="Ignore" Event="EndDialog" Value="Ignore" Order="2" />
254 + <Publish Dialog="FilesInUse" Control="Exit" Event="EndDialog" Value="Exit" Order="3" / -->
255 +
256 </UI>
257
258 <UIRef Id="WixUI_Common" />
@@ -297,18 +323,18 @@
323
324 <Control Id="TokenLabel" Type="Text" X="10" Y="100" Width="55" Height="15" Text="Claim Token:" HideCondition="OS_HAS_FILE" />
325 <Control Id="Token" Type="Edit" X="65" Y="100" Width="290" Height="18" Property="TOKEN" Text="{135}" HideCondition="OS_HAS_FILE" />
300 -
326 +
327 <Control Id="RoomsLabel" Type="Text" X="10" Y="115" Width="55" Height="15" Text="Rooms ID(s):" HideCondition="OS_HAS_FILE" />
328 <Control Id="Rooms" Type="Edit" X="65" Y="115" Width="290" Height="18" Property="ROOMS" HideCondition="OS_HAS_FILE" />
303 -
329 +
330 <Control Id="ProxyLabel" Type="Text" X="10" Y="130" Width="55" Height="15" Text="Proxy URL:" HideCondition="OS_HAS_FILE" />
331 <Control Id="Proxy" Type="Edit" X="65" Y="130" Width="290" Height="18" Property="PROXY" HideCondition="OS_HAS_FILE" />
306 -
332 +
333 <Control Id="URLLabel" Type="Text" X="10" Y="145" Width="55" Height="15" Text="Cloud URL:" HideCondition="OS_HAS_FILE" />
334 <Control Id="URL" Type="Edit" X="65" Y="145" Width="290" Height="18" Property="URL" HideCondition="OS_HAS_FILE" />
335
336 <Control Id="InsecureCheckbox" Type="CheckBox" X="10" Y="160" Width="290" Height="15" Property="INSECURE" CheckBoxValue="0" Text="Insecure" HideCondition="OS_HAS_FILE" />
311 -
337 +
338 <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="!(loc.WixUIBack)" />
339 <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="!(loc.WixUINext)" />
340 <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="!(loc.WixUICancel)">
@@ -318,4 +344,3 @@
344 </UI>
345 </Fragment>
346 </Wix>
321 -
packaging/windows/package-windows.sh
+1
@@ -40,6 +40,7 @@ ${GITHUB_ACTIONS+echo "::endgroup::"}
40 ${GITHUB_ACTIONS+echo "::group::Copy Files"}
41 tar -xf /msys2-latest.tar.zst -C /opt/netdata/ || exit 1
42 cp -R /opt/netdata/msys64/* /opt/netdata/ || exit 1
43 +cp packaging/windows/copy_files.ps1 /opt/netdata/usr/libexec/netdata/ || exit 1
44 rm -rf /opt/netdata/msys64/
45 ${GITHUB_ACTIONS+echo "::endgroup::"}
46