Skip to content

Commit 6561509

Browse files
authored
Add upgrade support and improve windows installer (#447)
* Add upgrade support and improve windows installer The installer can now also upgrade existing sidcar installations. It detects this by the presence of an existing sidecar.yml config. In upgrade mode it skip the configuration page. Additionally the installer will now also register the sidecar service automatically. Making this extra command line step obsolete. For debugging purposes, we write a installerlog.txt file now. Improve welcome message test to also show the version and mention the autmatic upgrade mode. Only replace the winlogbeat and filebeat collector binaries AFTER we stopped the sidecar. Otherwise the files might still be locked and the upgrade fails. * Suppport -NODEID param for silent installer Also fix default node-id file location for 32-bit installs * Fix service start after installation We need to start the service AFTER we've written the final sidecar.yml Also using nsExec allows us to see the output of the service command. * Add console logging support
1 parent adfc83a commit 6561509

File tree

2 files changed

+90
-14
lines changed

2 files changed

+90
-14
lines changed

dist/recipe.nsi

+89-13
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
!searchreplace SUFFIX '${VERSION_SUFFIX}' "-" "."
3232
OutFile "pkg/graylog_sidecar_installer_${VERSION}-${REVISION}${SUFFIX}.exe"
3333
RequestExecutionLevel admin ;Require admin rights
34-
ShowInstDetails "nevershow"
35-
ShowUninstDetails "nevershow"
34+
ShowInstDetails "show"
35+
ShowUninstDetails "show"
3636

3737
; Variables
3838
Var Params
@@ -50,16 +50,26 @@
5050
Var TlsSkipVerify
5151
Var ParamSendStatus
5252
Var ParamApiToken
53+
Var ParamNodeId
54+
Var NodeId
5355
Var SendStatus
5456
Var Dialog
5557
Var Label
5658
Var GraylogDir
59+
Var IsUpgrade
60+
Var LogFile
61+
Var LogMsgText
5762

5863

5964
;--------------------------------
6065
;Modern UI Configuration
6166

6267
!define MUI_ICON "graylog.ico"
68+
!define MUI_WELCOMEPAGE_TITLE "Graylog Sidecar ${VERSION}-${REVISION}${SUFFIX} Installation / Upgrade"
69+
!define MUI_WELCOMEPAGE_TEXT "This setup is gonna guide you through the installation / upgrade of the Graylog Sidecar.\r\n\r\n \
70+
If an already configured Sidecar is detected ('sidecar.yml' present), it will perform an upgrade.\r\n \r\n\
71+
Click Next to continue."
72+
6373
!insertmacro MUI_PAGE_WELCOME
6474
!insertmacro MUI_PAGE_LICENSE "../LICENSE"
6575
!insertmacro MUI_UNPAGE_WELCOME
@@ -82,6 +92,18 @@
8292
!insertmacro MUI_LANGUAGE "English"
8393
!insertmacro WordFind
8494
!insertmacro WordFind2X
95+
!insertmacro GetTime
96+
97+
!macro _LogWrite text
98+
StrCpy $LogMsgText "${text}"
99+
${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
100+
FileWrite $LogFile '$2$1$0$4$5$6: $LogMsgText$\r$\n'
101+
System::Call 'kernel32::GetStdHandle(i -11)i.r9'
102+
System::Call 'kernel32::AttachConsole(i -1)'
103+
FileWrite $9 "$LogMsgText$\r$\n"
104+
!macroend
105+
!define LogWrite "!insertmacro _LogWrite"
106+
85107

86108
!macro Check_X64
87109
${If} ${RunningX64}
@@ -92,8 +114,20 @@
92114
Strcpy $GraylogDir "$PROGRAMFILES32\Graylog"
93115
${EndIf}
94116
Strcpy $INSTDIR "$GraylogDir\sidecar"
117+
CreateDirectory $INSTDIR
95118
!macroend
96119

120+
!macro Check_Upgrade
121+
${If} ${FileExists} "$INSTDIR\sidecar.yml"
122+
Strcpy $IsUpgrade "true"
123+
${LogWrite} "Existing installation detected. Performing upgrade."
124+
${Else}
125+
Strcpy $IsUpgrade "false"
126+
${LogWrite} "No previous installation detected. Running installation mode."
127+
${EndIf}
128+
!macroend
129+
130+
97131
;--------------------------------
98132
;Data
99133

@@ -109,14 +143,6 @@ Section "Install"
109143
CreateDirectory "$INSTDIR\module"
110144
SetOutPath "$INSTDIR"
111145

112-
${If} ${RunningX64}
113-
File "collectors/winlogbeat/windows/x86_64/winlogbeat.exe"
114-
File "collectors/filebeat/windows/x86_64/filebeat.exe"
115-
${Else}
116-
File "collectors/winlogbeat/windows/x86/winlogbeat.exe"
117-
File "collectors/filebeat/windows/x86/filebeat.exe"
118-
${EndIf}
119-
120146
SetOverwrite off
121147
File /oname=sidecar.yml "../sidecar-windows-example.yml"
122148
SetOverwrite on
@@ -128,7 +154,10 @@ Section "Install"
128154
!insertmacro _IfKeyExists HKLM "SYSTEM\CurrentControlSet\Services" "graylog-sidecar"
129155
Pop $R0
130156
${If} $R0 = 1
131-
ExecWait '"$INSTDIR\graylog-sidecar.exe" -service stop'
157+
nsExec::ExecToStack '"$INSTDIR\graylog-sidecar.exe" -service stop'
158+
Pop $0
159+
Pop $1
160+
${LogWrite} "Stopping existing Sidecar Service: [exit $0] Stdout: $1"
132161
${EndIf}
133162

134163
${If} ${RunningX64}
@@ -137,9 +166,21 @@ Section "Install"
137166
File /oname=graylog-sidecar.exe "../build/${VERSION}/windows/386/graylog-sidecar.exe"
138167
${EndIf}
139168

169+
; Install beats collectors
170+
${If} ${RunningX64}
171+
File "collectors/winlogbeat/windows/x86_64/winlogbeat.exe"
172+
File "collectors/filebeat/windows/x86_64/filebeat.exe"
173+
${Else}
174+
File "collectors/winlogbeat/windows/x86/winlogbeat.exe"
175+
File "collectors/filebeat/windows/x86/filebeat.exe"
176+
${EndIf}
177+
140178
;When we stop the Sidecar service we also turn it on again
141179
${If} $R0 = 1
142-
ExecWait '"$INSTDIR\graylog-sidecar.exe" -service start'
180+
nsExec::ExecToStack '"$INSTDIR\graylog-sidecar.exe" -service start'
181+
Pop $0
182+
Pop $1
183+
${LogWrite} "Restarting existing Sidecar Service: [exit $0] Stdout: $1"
143184
${EndIf}
144185

145186
WriteUninstaller "$INSTDIR\uninstall.exe"
@@ -185,6 +226,7 @@ Section "Post"
185226
${GetOptions} $Params " -TLS_SKIP_VERIFY=" $ParamTlsSkipVerify
186227
${GetOptions} $Params " -SEND_STATUS=" $ParamSendStatus
187228
${GetOptions} $Params " -APITOKEN=" $ParamApiToken
229+
${GetOptions} $Params " -NODEID=" $ParamNodeId
188230

189231
${If} $ParamServerUrl != ""
190232
StrCpy $ServerUrl $ParamServerUrl
@@ -204,6 +246,9 @@ Section "Post"
204246
${If} $ParamApiToken != ""
205247
StrCpy $ApiToken $ParamApiToken
206248
${EndIf}
249+
${If} $ParamNodeId != ""
250+
StrCpy $NodeId $ParamNodeId
251+
${EndIf}
207252

208253
; set defaults
209254
${If} $ServerUrl == ""
@@ -218,14 +263,34 @@ Section "Post"
218263
${If} $SendStatus == ""
219264
StrCpy $SendStatus "true"
220265
${EndIf}
266+
${If} $NodeId == ""
267+
;sidecar.yml needs double escapes
268+
${WordReplace} "file:$INSTDIR\node-id" "\" "\\" "+" $NodeId
269+
${EndIf}
221270

222271
!insertmacro _ReplaceInFile "$INSTDIR\sidecar.yml" "<SERVERURL>" $ServerUrl
223272
!insertmacro _ReplaceInFile "$INSTDIR\sidecar.yml" "<NODENAME>" $NodeName
224273
!insertmacro _ReplaceInFile "$INSTDIR\sidecar.yml" "<UPDATEINTERVAL>" $UpdateInterval
225274
!insertmacro _ReplaceInFile "$INSTDIR\sidecar.yml" "<TLSSKIPVERIFY>" $TlsSkipVerify
226275
!insertmacro _ReplaceInFile "$INSTDIR\sidecar.yml" "<SENDSTATUS>" $SendStatus
227276
!insertmacro _ReplaceInFile "$INSTDIR\sidecar.yml" "<APITOKEN>" $ApiToken
277+
!insertmacro _ReplaceInFile "$INSTDIR\sidecar.yml" "<NODEID>" $NodeId
278+
279+
;Install sidecar service
280+
${If} $IsUpgrade == 'false'
281+
nsExec::ExecToStack '"$INSTDIR\graylog-sidecar.exe" -service install'
282+
Pop $0
283+
Pop $1
284+
${LogWrite} "Installing new Sidecar Service: [exit $0] Stdout: $1"
285+
286+
nsExec::ExecToStack '"$INSTDIR\graylog-sidecar.exe" -service start'
287+
Pop $0
288+
Pop $1
289+
${LogWrite} "Starting new Sidecar Service: [exit $0] Stdout: $1"
290+
${EndIf}
228291

292+
${LogWrite} "Installer/Upgrader finished."
293+
FileClose $LogFile
229294
SectionEnd
230295

231296
;--------------------------------
@@ -254,13 +319,20 @@ SectionEnd
254319
;Functions
255320

256321
Function .onInit
322+
!insertmacro Check_X64
323+
324+
FileOpen $LogFile "$INSTDIR\installerlog.txt" w
325+
326+
${LogWrite} "$\r$\n" ;Powershell seems to swallow the first line
327+
${LogWrite} "Starting Sidecar ${VERSION}-${REVISION}${SUFFIX} installer/upgrader."
328+
257329
; check admin rights
258330
Call CheckAdmin
259331

260332
; check concurrent un/installations
261333
Call CheckConcurrent
262334

263-
!insertmacro Check_X64
335+
!insertmacro Check_Upgrade
264336
FunctionEnd
265337

266338
Function un.oninit
@@ -276,6 +348,10 @@ FunctionEnd
276348

277349

278350
Function nsDialogsPage
351+
${If} $IsUpgrade == 'true'
352+
Abort
353+
${EndIf}
354+
279355
nsDialogs::Create 1018
280356

281357

sidecar-windows-example.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ server_api_token: "<APITOKEN>"
1616
# ATTENTION: Every sidecar instance needs a unique ID!
1717
#
1818
# Default: "file:C:\\Program Files\\Graylog\\sidecar\\node-id"
19-
node_id: "file:C:\\Program Files\\Graylog\\sidecar\\node-id"
19+
node_id: "<NODEID>"
2020

2121
# The node name of the sidecar. If this is empty, the sidecar will use the
2222
# hostname of the host it is running on.

0 commit comments

Comments
 (0)