@cryptotaxi247 / netdata-1 / commits / c4481faeb

Update Installer Code (Services) (#18253)

* uninstall_netdata_service: Move content to function * uninstall_netdata_service: Add error check and show info for users * uninstall_netdata_service: Modify helper to manage service * uninstall_netdata_service: Stop agent before start installation

thiagoftsm committed Aug 5, 2024 at 12:42 UTC c4481faebb583e4708d3a697d14c91d38338392c
1 file changed +58 -28
packaging/windows/installer.nsi
+58 -28
@@ -1,4 +1,5 @@
1 !include "MUI2.nsh"
2 +!include "nsDialogs.nsh"
3 !include "FileFunc.nsh"
4
5 Name "Netdata"
@@ -25,29 +26,13 @@ RequestExecutionLevel admin
26
27 !insertmacro MUI_LANGUAGE "English"
28
28 -Section "Install Netdata"
29 - SetOutPath $INSTDIR
30 - SetCompress off
31 -
32 - File /r "C:\msys64\opt\netdata\*.*"
33 -
34 - ClearErrors
35 - ExecWait '"$SYSDIR\sc.exe" create Netdata binPath= "$INSTDIR\usr\bin\netdata.exe" start= delayed-auto'
36 - IfErrors 0 +2
37 - DetailPrint "Warning: Failed to create Netdata service."
38 -
39 - ClearErrors
40 - ExecWait '"$SYSDIR\sc.exe" description Netdata "Real-time system monitoring service"'
41 - IfErrors 0 +2
42 - DetailPrint "Warning: Failed to add Netdata service description."
43 -
44 - ClearErrors
45 - ExecWait '"$SYSDIR\sc.exe" start Netdata'
46 - IfErrors 0 +2
47 - DetailPrint "Warning: Failed to start Netdata service."
48 -
49 - WriteUninstaller "$INSTDIR\Uninstall.exe"
29 +Function .onInit
30 + nsExec::ExecToLog '$SYSDIR\sc.exe stop Netdata'
31 + pop $0
32 +FunctionEnd
33
34 +Function NetdataUninstallRegistry
35 + ClearErrors
36 WriteRegStr HKLM "${ND_UININSTALL_REG}" \
37 "DisplayName" "Netdata - Real-time system monitoring."
38 WriteRegStr HKLM "${ND_UININSTALL_REG}" \
@@ -71,23 +56,68 @@ Section "Install Netdata"
56 WriteRegStr HKLM "${ND_UININSTALL_REG}" \
57 "VersionMinor" "${MINORVERSION}"
58
59 + IfErrors 0 +2
60 + MessageBox MB_ICONEXCLAMATION|MB_OK "Unable to create an entry in the Control Panel!" IDOK end
61 +
62 + ClearErrors
63 ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
64 IntFmt $0 "0x%08X" $0
65 WriteRegDWORD HKLM "${ND_UININSTALL_REG}" "EstimatedSize" "$0"
66 +
67 + IfErrors 0 +2
68 + MessageBox MB_ICONEXCLAMATION|MB_OK "Cannot estimate the installation size." IDOK end
69 + end:
70 +FunctionEnd
71 +
72 +Section "Install Netdata"
73 + SetOutPath $INSTDIR
74 + SetCompress off
75 +
76 + File /r "C:\msys64\opt\netdata\*.*"
77 +
78 + ClearErrors
79 + nsExec::ExecToLog '$SYSDIR\sc.exe create Netdata binPath= "$INSTDIR\usr\bin\netdata.exe" start= delayed-auto'
80 + pop $0
81 + ${If} $0 != 0
82 + DetailPrint "Warning: Failed to create Netdata service."
83 + ${EndIf}
84 +
85 + ClearErrors
86 + nsExec::ExecToLog '$SYSDIR\sc.exe description Netdata "Real-time system monitoring service"'
87 + pop $0
88 + ${If} $0 != 0
89 + DetailPrint "Warning: Failed to add Netdata service description."
90 + ${EndIf}
91 +
92 + ClearErrors
93 + nsExec::ExecToLog '$SYSDIR\sc.exe start Netdata'
94 + pop $0
95 + ${If} $0 != 0
96 + DetailPrint "Warning: Failed to start Netdata service."
97 + ${EndIf}
98 +
99 + WriteUninstaller "$INSTDIR\Uninstall.exe"
100 +
101 + Call NetdataUninstallRegistry
102 SectionEnd
103
104 Section "Uninstall"
105 ClearErrors
81 - ExecWait '"$SYSDIR\sc.exe" stop Netdata'
82 - IfErrors 0 +2
83 - DetailPrint "Warning: Failed to stop Netdata service."
106 + nsExec::ExecToLog '$SYSDIR\sc.exe stop Netdata'
107 + pop $0
108 + ${If} $0 != 0
109 + DetailPrint "Warning: Failed to stop Netdata service."
110 + ${EndIf}
111
112 ClearErrors
86 - ExecWait '"$SYSDIR\sc.exe" delete Netdata'
87 - IfErrors 0 +2
88 - DetailPrint "Warning: Failed to delete Netdata service."
113 + nsExec::ExecToLog '$SYSDIR\sc.exe delete Netdata'
114 + pop $0
115 + ${If} $0 != 0
116 + DetailPrint "Warning: Failed to delete Netdata service."
117 + ${EndIf}
118
119 RMDir /r "$INSTDIR"
120
121 DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Netdata"
122 SectionEnd
123 +