fluent / fluent-package-builder

td-agent (Fluentd) Building and Packaging System
Apache License 2.0
22 stars 25 forks source link

msi: set modified environment variable FLUENT_PACKAGE_TOPDIR #533

Closed kenhys closed 1 year ago

kenhys commented 1 year ago

FLUENT_PACKAGE_TOPDIR environment variable must be set for fluentdwinsvc service because winsvc.rb launches ruby process directly (doesn't use wrapper fluentd.bat)

If FLUENT_PACKAGE_TOPDIR contains backslash ('\') instead of slash ('/'), it is harmful to handle match pattern ('*') in fluentd.conf.

Instead of using WiX Environment element, we use CustomAction to modify directory separator.

NOTE: For string object, we can omit Dim and Set, but the other part, we need to use Set explicitly.

kenhys commented 1 year ago

Oops, unexpectedly failed.

MSI (s) (78:68) [18:10:14:441]: Executing op: CustomActionSchedule(Action=InstallFluentdWinSvc,ActionType=3073,Source=BinaryData,Target=WixQuietExec64,CustomActionData="c:\opt\fluent\fluentd.bat" --reg-winsvc i --reg-winsvc-delay-start --reg-winsvc-fluentdopt "-c c:\opt\fluent\etc\fluent\fluentd.conf -o c:\opt\fluent\fluentd.log")
MSI (s) (78:BC) [18:10:14:442]: Invoking remote custom action. DLL: C:\WINDOWS\Installer\MSI6924.tmp, Entrypoint: WixQuietExec64
MSI (s) (78:E4) [18:10:14:442]: Generating random cookie.
MSI (s) (78:E4) [18:10:14:443]: System Environment : Client has accepted UAC prompt
MSI (s) (78:E4) [18:10:14:443]: System Environment : Client has accepted UAC prompt
MSI (s) (78:E4) [18:10:14:447]: Created Custom Action Server with PID 2076 (0x81C).
MSI (s) (78:D0) [18:10:14:470]: Running as a service.
MSI (s) (78:D0) [18:10:14:473]: Hello, I'm your 32bit Elevated Non-remapped custom action server.
WixQuietExec64:  Error 0x80070001: Command line returned an error.
WixQuietExec64:  Error 0x80070001: QuietExec64 Failed
WixQuietExec64:  Error 0x80070001: Failed in ExecCommon method
CustomAction InstallFluentdWinSvc returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
daipom commented 1 year ago

I noticed that fluentd.bat of this package is not used for starting Fluentd as a Windows Service.

https://github.com/fluent/fluent-package-builder/blob/05087a41098489bd6abc0bd4cdd687d12b65e553/fluent-package/msi/assets/fluentd.bat

Instead, this winsvc.rb of Fluentd repository is used.

https://github.com/fluent/fluentd/blob/d5685ada81ac89a35a79965f1e94bbe5952a5d3a/lib/fluent/winsvc.rb#L43-L48 (https://github.com/fluent/fluentd/blob/d5685ada81ac89a35a79965f1e94bbe5952a5d3a/lib/fluent/command/fluentd.rb#L302-L313)

So, I think we need the system environmental variable.

This would be the reason why the backslash characters in FLUENT_PACKAGE_TOPDIR is not converted in the config.

kenhys commented 1 year ago

I'll revert the previous commit.

kenhys commented 1 year ago

NOTE: There is the one problem that Session.Property("FLUENTPROJECTLOCATION") returns empty value. It takes more time to investigate this issue, and it is not straightforward solution to fix it. (it maybe better to fix in fluend side)