Skip to content

Commit

Permalink
Fix system user/group name in logrotate.d/fluentd again (#594)
Browse files Browse the repository at this point in the history
This is follow-up of #592 to fix problem correctly.

fluent-package/tempaltes/etc/logrotate.d/fluentd is used
for deb and rpm, so it should support both of different
system user/group respectively.

---------

Signed-off-by: Kentaro Hayashi <[email protected]>
  • Loading branch information
kenhys authored Nov 16, 2023
1 parent bf66110 commit b72b44c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
56 changes: 33 additions & 23 deletions fluent-package/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -475,25 +475,14 @@ class BuildTask
end
end

desc "Create fluent-package configuration files from template"
task :fluent_package_config do
fluentd_conf = "etc/#{PACKAGE_DIR}/#{SERVICE_NAME}.conf"
fluentd_conf_default = "opt/#{PACKAGE_DIR}/share/#{SERVICE_NAME}.conf"
configs = [fluentd_conf]
configs.concat([
"etc/logrotate.d/#{SERVICE_NAME}",
fluentd_conf_default,
]) unless windows? || macos?
configs.each do |config|
src =
if config == fluentd_conf_default
template_path(fluentd_conf)
else
template_path(config)
end
dest = File.join(STAGING_DIR, config)
render_template(dest, src, template_params)
end
desc "Create debian fluent-package configuration files from template"
task :deb_fluent_package_config do
render_fluent_package_config('deb')
end

desc "Create RPM fluent-package configuration files from template"
task :rpm_fluent_package_config do
render_fluent_package_config('rpm')
end

desc "Create systemd-tmpfiles configuration files from template"
Expand Down Expand Up @@ -596,16 +585,16 @@ class BuildTask
end

desc "Create configuration files for Red Hat like systems with systemd"
task :rpm_config => [:fluent_package_config, :systemd_tmpfiles_config, :bin_scripts, :rpm_systemd]
task :rpm_config => [:rpm_fluent_package_config, :systemd_tmpfiles_config, :bin_scripts, :rpm_systemd]

desc "Create configuration files for Debian like systems"
task :deb_config => [:fluent_package_config, :systemd_tmpfiles_config, :bin_scripts, :deb_systemd, :deb_scripts]
task :deb_config => [:deb_fluent_package_config, :systemd_tmpfiles_config, :bin_scripts, :deb_systemd, :deb_scripts]

desc "Create configuration files for Windows"
task :msi_config => [:fluent_package_config, :wix_config, :win_batch_files]
task :msi_config => [:rpm_fluent_package_config, :wix_config, :win_batch_files]

desc "Create configuration files for macOS"
task :dmg_config => [:fluent_package_config, :pkgbuild_scripts, :pkgbuild_config, :bin_scripts, :launchctl_config]
task :dmg_config => [:rpm_fluent_package_config, :pkgbuild_scripts, :pkgbuild_config, :bin_scripts, :launchctl_config]
end
end

Expand Down Expand Up @@ -1101,6 +1090,27 @@ class BuildTask
remove_files(git_dir, true)
end
end

def render_fluent_package_config(package_type)
# package_type must be 'deb' or 'rpm'
fluentd_conf = "etc/#{PACKAGE_DIR}/#{SERVICE_NAME}.conf"
fluentd_conf_default = "opt/#{PACKAGE_DIR}/share/#{SERVICE_NAME}.conf"
configs = [fluentd_conf]
configs.concat([
"etc/logrotate.d/#{SERVICE_NAME}",
fluentd_conf_default,
]) unless windows? || macos?
configs.each do |config|
src =
if config == fluentd_conf_default
template_path(fluentd_conf)
else
template_path(config)
end
dest = File.join(STAGING_DIR, config)
render_template(dest, src, template_params({ pkg_type: package_type }))
end
end
end

class LinuxPackageTask < PackageTask
Expand Down
4 changes: 4 additions & 0 deletions fluent-package/templates/etc/logrotate.d/fluentd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
compress
delaycompress
notifempty
<% if pkg_type == 'deb' %>
create 640 _<%= service_name %> _<%= service_name %>
<% else %>
create 640 <%= service_name %> <%= service_name %>
<% end %>
sharedscripts
postrotate
pid=/var/run/<%= package_dir %>/<%= service_name %>.pid
Expand Down

0 comments on commit b72b44c

Please sign in to comment.