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

msi: set modified environment variable FLUENT_PACKAGE_TOPDIR #533

Closed
wants to merge 1 commit into from

Conversation

kenhys
Copy link
Contributor

@kenhys kenhys commented Jul 20, 2023

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
Copy link
Contributor Author

kenhys commented Jul 20, 2023

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
Copy link
Contributor

daipom commented Jul 21, 2023

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
Copy link
Contributor Author

kenhys commented Jul 21, 2023

I'll revert the previous commit.

@kenhys kenhys changed the title msi: export FLUENT_PACKAGE_TOPDIR,FLUENT_PACKAGE_VERSION msi: set modified environment variable FLUENT_PACKAGE_TOPDIR Jul 21, 2023
Comment on lines 234 to 246
<CustomAction Id="ModifyDirSepForFluentPackageTopdir"
Script="vbscript">
<![CDATA[
pathvalue = Session.Property("FLUENTPROJECTLOCATION")
newValue = Replace(pathvalue, "\\", "/")
Session.Property("FLUENTPROJECTLOCATION") = newValue
shellObject = CreateObject("WScript.Shell")
systemEnv = objShell.Environment("SYSTEM")
systemEnv("FLUENT_PACKAGE_TOPDIR") = newValue
]]>
</CustomAction>
<!-- Propagate changed environment variable -->
<CustomActionRef Id="WixBroadcastEnvironmentChange" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! I had no idea there was such a way!

I'm concerned about one point.
Don't we need to remove the environmental variable on uninstalling?

Copy link
Contributor Author

@kenhys kenhys Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just a PoC yet because now building msi... to verify.

If it works as expected, also add code for uninstalling.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed. 😭

MSI (s) (F8:7C) [16:28:25:209]: Note: 1: 2228 2:  3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 1720 
Error 1720. There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor.  Custom action ModifyDirSepForFluentPackageTopdir script error -2146827850, Microsoft VBScript 実行時エラー: オブジェクトでサポート
されていないプロパティまたはメソッドです。: 'shellObject' Line 4, Column 9,  
MSI (s) (F8:7C) [16:28:53:263]: Note: 1: 2205 2:  3: Error 
MSI (s) (F8:7C) [16:28:53:263]: Note: 1: 2228 2:  3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 1709 
MSI (s) (F8:7C) [16:28:53:263]: Product: Fluent Package v5.0.0 -- Error 1720. There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor.  Custom action ModifyDirSepForFluentPackageTopdir script error -2146827850, Microsoft VBScript 実行時エラー: オブジェクトでサポートされていないプロパティまたはメソッドです。: 'shellObject' Line 4, Column 9,  

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

investigating a workaround...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can choose inline snippet or external script.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebuilding msi...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should set Impersonate="no" explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two way to do it.

  • Kick inline script via CustomAction
  • Kick external script via CustomAction with JScriptCall and so on.

Both of them, it seems that Session.Property("...") is empty.
Additionally, setting Session.Property can't be overridden.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of them, it seems that Session.Property("...") is empty.

This is a blocker of this issue.

@kenhys kenhys force-pushed the fix-win-setenv branch 2 times, most recently from c3e3819 to a607e07 Compare July 21, 2023 06:20
@kenhys kenhys force-pushed the fix-win-setenv branch 3 times, most recently from 01766e4 to ad71507 Compare July 24, 2023 05:03
@daipom daipom mentioned this pull request Jul 24, 2023
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.

Signed-off-by: Kentaro Hayashi <hayashi@clear-code.com>
@kenhys
Copy link
Contributor Author

kenhys commented Jul 24, 2023

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)

@kenhys kenhys closed this Jul 24, 2023
@kenhys kenhys deleted the fix-win-setenv branch July 26, 2023 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants