From e7d822d0729f0344a9ee414c53472c7182f21198 Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Thu, 7 Mar 2024 12:07:28 +0900 Subject: [PATCH] msi: fix slow start issue on Windows Until https://github.com/chef/win32-service/pull/85 is merged, use forked version of win32-service. This fix should be applied to fluent-package not to block starting fluentdwinsvc service on Windows. See https://github.com/fluent/fluent-package-builder/issues/618 Closes: #630 NOTE: even though just putting the following line does not install forked version of win32-service, so install it explicitly as same as fluentd gem. gem "win32-service", github: "fluent-plugins-nursery/win32-service", branch: "fluent-package", platforms: [:mingw, :x64_mingw] Signed-off-by: Kentaro Hayashi --- fluent-package/Gemfile | 13 ++++++++++++- fluent-package/Gemfile.lock | 14 ++++++++++---- fluent-package/Rakefile | 29 ++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/fluent-package/Gemfile b/fluent-package/Gemfile index 0418bbb0b..2b31310f0 100644 --- a/fluent-package/Gemfile +++ b/fluent-package/Gemfile @@ -31,11 +31,21 @@ if ENV["INSTALL_GEM_FROM_LOCAL_REPO"] # into managed Gemfile.lock source FLUENTD_LOCAL_GEM_REPO do gem "fluentd" + # Bundle forked version of win32-service until + # https://github.com/chef/win32-service/pull/85 is merged. + # This workaround should be applied to fluent-package not to block starting + # fluentdwinsvc service on Windows. See + # https://github.com/fluent/fluent-package-builder/issues/618 + # NOTE: platforms: does not work in source ... do block + if RUBY_PLATFORM =~ /mswin|mingw/ + gem "win32-service" + end end else # Lock to specific revision git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } gem "fluentd", github: "fluent/fluentd", ref: FLUENTD_REVISION + gem "win32-service", github: "fluent-plugins-nursery/win32-service", branch: "fluent-package", platforms: [:mingw, :x64_mingw] end # plugin gems @@ -81,7 +91,8 @@ gem "ffi-win32-extensions", "1.0.4", platforms: windows_platforms gem "nokogiri", "1.15.5", platforms: windows_platforms gem "win32-event", "0.6.3", platforms: windows_platforms gem "win32-ipc", "0.7.0", platforms: windows_platforms -gem "win32-service", "2.3.2", platforms: windows_platforms +# Use officially released version when PR was merged and released. +#gem "win32-service", "2.3.2", platforms: windows_platforms gem "winevt_c", "0.10.1", platforms: windows_platforms gem "win32-eventlog", "0.6.7", platforms: windows_platforms gem "fluent-plugin-parser-winevt_xml", "0.2.6", platforms: windows_platforms diff --git a/fluent-package/Gemfile.lock b/fluent-package/Gemfile.lock index 2295f8414..4f55b4e26 100644 --- a/fluent-package/Gemfile.lock +++ b/fluent-package/Gemfile.lock @@ -1,3 +1,12 @@ +GIT + remote: https://github.com/fluent-plugins-nursery/win32-service + revision: cfcc2007b3843127329d6a7307a62a927a714327 + branch: fluent-package + specs: + win32-service (2.3.2) + ffi + ffi-win32-extensions + GIT remote: https://github.com/fluent/fluentd revision: d3cf2e0f95a0ad88b9897197db6c5152310f114f @@ -257,9 +266,6 @@ GEM ffi win32-ipc (0.7.0) ffi - win32-service (2.3.2) - ffi - ffi-win32-extensions winevt_c (0.10.1) yajl-ruby (1.4.3) zip-zip (0.3) @@ -333,7 +339,7 @@ DEPENDENCIES win32-event (= 0.6.3) win32-eventlog (= 0.6.7) win32-ipc (= 0.7.0) - win32-service (= 2.3.2) + win32-service! winevt_c (= 0.10.1) yajl-ruby (= 1.4.3) diff --git a/fluent-package/Rakefile b/fluent-package/Rakefile index 5b1b37912..78ff7a710 100755 --- a/fluent-package/Rakefile +++ b/fluent-package/Rakefile @@ -177,6 +177,7 @@ class DownloadTask attr_reader :file_jemalloc_source attr_reader :file_ruby_source, :file_ruby_installer_x64 attr_reader :file_fluentd_archive + attr_reader :file_win32_service_archive attr_reader :files_ruby_gems attr_reader :file_openssl_source @@ -199,6 +200,7 @@ class DownloadTask define_jemalloc_file define_ruby_files define_fluentd_archive + define_win32_service_archive if windows? define_gem_files define_openssl_file @@ -210,7 +212,8 @@ class DownloadTask task :ruby => [@file_ruby_source, @file_ruby_installer_x64] desc "Clone fluentd repository and create a tarball" - task :fluentd => @file_fluentd_archive + task :fluentd => windows? ? [@file_fluentd_archive, @file_win32_service_archive] : + [@file_fluentd_archive] desc "Download ruby gems" task :ruby_gems => @files_ruby_gems @@ -318,6 +321,21 @@ class DownloadTask end end + def define_win32_service_archive + @file_win32_service_archive = File.join(DOWNLOADS_DIR, "win32-service.tar.gz") + file @file_win32_service_archive do + ensure_directory(DOWNLOADS_DIR) do + dirname = "win32-service" + rm_rf(dirname) if File.exist?(dirname) + sh("git", "clone", "https://github.com/fluent-plugins-nursery/win32-service.git") + cd("win32-service") do + sh("git", "checkout", "fluent-package") + end + sh(*tar_command, "cvfz", "#{dirname}.tar.gz", dirname) + end + end + end + def define_gem_files paths = [] Dir.glob("#{DOWNLOADS_DIR}/*.gem") do |path| @@ -436,6 +454,15 @@ class BuildTask setup_local_gem_repo install_gemfiles end + if windows? + archive_path = @download_task.file_win32_service_archive + sh(*tar_command, "xvf", archive_path, *tar_options) unless File.exist?("win32-service") + cd("win32-service") do + sh("rake", "build") + setup_local_gem_repo + install_gemfiles + end + end end end