From f2c5c9e904adce651c4cdb22df13b44b7ac2dc9c Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 28 Jun 2022 08:19:52 +0100 Subject: [PATCH] Make the GeoIP database directory vary with the OS version --- cookbooks/geoipupdate/attributes/default.rb | 5 +++++ cookbooks/geoipupdate/recipes/default.rb | 4 ++-- cookbooks/piwik/recipes/default.rb | 8 +++++--- cookbooks/web/resources/rails_port.rb | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cookbooks/geoipupdate/attributes/default.rb b/cookbooks/geoipupdate/attributes/default.rb index 3165aa115..315dfe146 100644 --- a/cookbooks/geoipupdate/attributes/default.rb +++ b/cookbooks/geoipupdate/attributes/default.rb @@ -1,4 +1,9 @@ default[:geoipupdate][:account] = "149244" default[:geoipupdate][:editions] = %w[GeoLite2-ASN GeoLite2-City GeoLite2-Country] +default[:geoipupdate][:directory] = if node[:lsb][:release].to_f < 22.04 + "/usr/share/GeoIP" + else + "/var/lib/GeoIP" + end default[:apt][:sources] |= ["maxmind"] diff --git a/cookbooks/geoipupdate/recipes/default.rb b/cookbooks/geoipupdate/recipes/default.rb index 2b2c23632..036c27881 100644 --- a/cookbooks/geoipupdate/recipes/default.rb +++ b/cookbooks/geoipupdate/recipes/default.rb @@ -35,7 +35,7 @@ execute "geoipupdate" do command "geoipupdate" user "root" group "root" - not_if { kitchen? || node[:geoipupdate][:editions].all? { |edition| ::File.exist?("/usr/share/GeoIP/#{edition}.mmdb") } } + not_if { kitchen? || node[:geoipupdate][:editions].all? { |edition| ::File.exist?("#{node[:geoipupdate][:directory]}/#{edition}.mmdb") } } end systemd_service "geoipupdate" do @@ -46,7 +46,7 @@ systemd_service "geoipupdate" do private_devices true protect_system "strict" protect_home true - read_write_paths %w[/usr/share/GeoIP /var/lib/GeoIP] + read_write_paths node[:geoipupdate][:directory] end systemd_timer "geoipupdate" do diff --git a/cookbooks/piwik/recipes/default.rb b/cookbooks/piwik/recipes/default.rb index b2a27737a..0a32dda4e 100644 --- a/cookbooks/piwik/recipes/default.rb +++ b/cookbooks/piwik/recipes/default.rb @@ -39,6 +39,8 @@ apache_module "rewrite" version = node[:piwik][:version] +geoip_directory = node[:geoipupdate][:directory] + directory "/opt/piwik-#{version}" do owner "root" group "root" @@ -95,15 +97,15 @@ directory "/opt/piwik-#{version}/piwik/tmp/assets" do end link "/opt/piwik-#{version}/piwik/misc/GeoLite2-ASN.mmdb" do - to "/usr/share/GeoIP/GeoLite2-ASN.mmdb" + to "#{geoip_directory}/GeoLite2-ASN.mmdb" end link "/opt/piwik-#{version}/piwik/misc/GeoLite2-City.mmdb" do - to "/usr/share/GeoIP/GeoLite2-City.mmdb" + to "#{geoip_directory}/GeoLite2-City.mmdb" end link "/opt/piwik-#{version}/piwik/misc/GeoLite2-Country.mmdb" do - to "/usr/share/GeoIP/GeoLite2-Country.mmdb" + to "#{geoip_directory}/GeoLite2-Country.mmdb" end link "/srv/piwik.openstreetmap.org" do diff --git a/cookbooks/web/resources/rails_port.rb b/cookbooks/web/resources/rails_port.rb index e4e206ae5..565a21efe 100644 --- a/cookbooks/web/resources/rails_port.rb +++ b/cookbooks/web/resources/rails_port.rb @@ -191,7 +191,7 @@ action :create do line.gsub!(/^( *)#geonames_username:.*$/, "\\1geonames_username: \"openstreetmap\"") - line.gsub!(/^( *)#maxmind_database:.*$/, "\\1maxmind_database: \"/usr/share/GeoIP/GeoLite2-Country.mmdb\"") + line.gsub!(/^( *)#maxmind_database:.*$/, "\\1maxmind_database: \"#{node[:geoipupdate][:directory]}/GeoLite2-Country.mmdb\"") if new_resource.gpx_dir line.gsub!(/^( *)gpx_trace_dir:.*$/, "\\1gpx_trace_dir: \"#{new_resource.gpx_dir}/traces\"") -- 2.39.5