Skip to content

Commit

Permalink
msi: add migration batch sequence
Browse files Browse the repository at this point in the history
After:

* Move configuration files to c:\opt\fluent\etc\fluent\td-agent.conf
* Create symbolic link to c:\opt\fluent\etc\fluent.

Signed-off-by: Kentaro Hayashi <hayashi@clear-code.com>
Co-authored-by: Daijiro Fukuda <fukuda@clear-code.com>
  • Loading branch information
kenhys and daipom committed Jul 10, 2023
1 parent 10c525c commit 90550e3
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions fluent-package/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ class BuildTask
ensure_directory(staging_bindir)
cp("msi/assets/#{PACKAGE_NAME}-prompt.bat", td_agent_staging_dir)
cp("msi/assets/#{PACKAGE_NAME}-post-install.bat", staging_bindir)
cp("msi/assets/#{PACKAGE_NAME}-post-migration.bat", staging_bindir)
cp("msi/assets/#{SERVICE_NAME}.bat", td_agent_staging_dir)
cp("msi/assets/fluent-gem.bat", td_agent_staging_dir)
cp("msi/assets/#{PACKAGE_NAME}-version.rb", staging_bindir)
Expand Down
51 changes: 51 additions & 0 deletions fluent-package/msi/assets/fluent-package-post-migration.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@echo on
title Fluent-package post migration script

if exist "%~dp0..\..\td-agent" (
setlocal enabledelayedexpansion
sc query state=inactive | findstr fluentdwinsvc
if !ERRORLEVEL! == 1 (
@rem NOTE: If the service is not stopped here, it is a BUG.
@rem This state can cause fatal problems with the installation, so we should cancel this process.
@rem (If trying to stop it by the command such as `$ net stop fluentdwinsvc`, it can fail as "The service is starting or stopping. Please try again later.".)
echo "WARN: Active fluentdwinsvc service is detected. This is unexpected. Migration process has been canceled."
exit /b 1
)
endlocal

if not exist "%~dp0..\etc\fluent" (
echo "Create c:\opt\fluent\etc\fluent directory"
mkdir "%~dp0..\etc\fluent"
)

if exist "%~dp0..\..\td-agent\etc\td-agent\td-agent.conf" (
echo "Migrate c:\opt\td-agent\etc\td-agent.conf"
move /Y "%~dp0..\..\td-agent\etc\td-agent\td-agent.conf" "%~dp0..\etc\fluent\td-agent.conf"
echo "Migrate td-agent.conf to c:\opt\fluent\etc\fluent\fluentd.conf"
copy /Y "%~dp0..\etc\fluent\td-agent.conf" "%~dp0..\etc\fluent\fluentd.conf"
)

@rem NOTE: do not migrate log files not to lose log accidentally

echo "Migrate c:\opt\td-agent\etc\td-agent\* files"
for %%f in (%~dp0..\..\td-agent\etc\td-agent\*) do (
move /Y %%f "%~dp0..\etc\fluent\"
)
if not exist "%~dp0..\etc\fluent\plugin" (
mkdir "%~dp0..\etc\fluent\plugin"
)
echo "Migrate c:\opt\td-agent\etc\plugin directory"
for /d %%d in (%~dp0..\..\td-agent\etc\plugin\*) do (
move /Y %%d "%~dp0..\etc\fluent\plugin\"
)

echo "Ensure remaining files under td-agent"
tree %~dp0..\..\td-agent

@rem create symbolic link to c:\opt\fluent (we can't use hardlink for directory)
if exist "%~dp0..\..\td-agent\etc\td-agent" (
rmdir /S /Q "%~dp0..\..\td-agent\etc\td-agent"
)
echo "Create symlink c:\opt\td-agent\etc\td-agent to c:\opt\fluent\etc\fluent"
mklink /D %~dp0..\..\td-agent\etc\td-agent %~dp0..\..\fluent\etc\fluent
)
16 changes: 16 additions & 0 deletions fluent-package/msi/source.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@
Execute="deferred"
Return="check"
Impersonate="no" />

<Property Id="PostMigration" Value=" "/>
<CustomAction Id="SetPostMigrationCommand"
Property="PostMigration"
Value="&quot;[FLUENTPROJECTLOCATION]bin\fluent-package-post-migration.bat&quot;"/>
<CustomAction Id="PostMigration"
BinaryKey="WixCA"
DllEntry="WixQuietExec64"
Execute="deferred"
Return="check"
Impersonate="no" />

<Property Id="InstallFluentdWinSvc" Value=" "/>
<CustomAction Id="SetInstallFluentdWinSvcCommand"
Property="InstallFluentdWinSvc"
Expand Down Expand Up @@ -219,6 +231,10 @@
<InstallExecuteSequence>
<Custom Action="SetPostInstallCommand" After="InstallFiles">NOT Installed</Custom>
<Custom Action="PostInstall" After="SetPostInstallCommand">NOT Installed</Custom>

<Custom Action="SetPostMigrationCommand" Before="PostMigration">WIX_UPGRADE_DETECTED</Custom>
<Custom Action="PostMigration" Before="StartServices">WIX_UPGRADE_DETECTED</Custom>

<Custom Action="SetInstallFluentdWinSvcCommand" After="InstallFiles">NOT Installed</Custom>
<Custom Action="InstallFluentdWinSvc" After="SetInstallFluentdWinSvcCommand">NOT Installed</Custom>

Expand Down

0 comments on commit 90550e3

Please sign in to comment.