]> git.openstreetmap.org Git - chef.git/blob - cookbooks/geoipupdate/recipes/default.rb
Merge pull request #331 from Tigerfell/tiles
[chef.git] / cookbooks / geoipupdate / recipes / default.rb
1 #
2 # Cookbook:: geoipdate
3 # Recipe:: default
4 #
5 # Copyright:: 2020, OpenStreetMap Foundation
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 include_recipe "apt"
21
22 license_keys = data_bag_item("geoipupdate", "license-keys")
23
24 package "geoip-database" do
25   action :purge
26 end
27
28 package "geoip-database-contrib" do
29   action :purge
30 end
31
32 package "geoipupdate" do
33   action :purge
34   only_if { ::File.exist?("/etc/cron.d/geoipupdate") }
35 end
36
37 package "geoipupdate"
38
39 template "/etc/GeoIP.conf" do
40   source "GeoIP.conf.erb"
41   owner "root"
42   group "root"
43   mode "644"
44   variables :license_keys => license_keys
45 end
46
47 execute "geoipupdate" do
48   command "geoipupdate"
49   user "root"
50   group "root"
51   not_if { ENV.key?("TEST_KITCHEN") || node[:geoipupdate][:editions].all? { |edition| ::File.exist?("/usr/share/GeoIP/#{edition}.mmdb") } }
52 end
53
54 systemd_service "geoipdate" do
55   action :delete
56 end
57
58 systemd_service "geoipupdate" do
59   description "Update GeoIP databases"
60   user "root"
61   exec_start "/usr/bin/geoipupdate"
62   private_tmp true
63   private_devices true
64   protect_system "strict"
65   protect_home true
66   read_write_paths "/usr/share/GeoIP"
67 end
68
69 systemd_timer "geoipupdate" do
70   description "Update GeoIP databases"
71   on_boot_sec "15m"
72   on_unit_active_sec "7d"
73   randomized_delay_sec "4h"
74 end
75
76 service "geoipupdate.timer" do
77   action [:enable, :start]
78 end
79
80 directory "/var/lib/GeoIP" do
81   action :delete
82   recursive true
83 end