]> git.openstreetmap.org Git - chef.git/blob - cookbooks/oxidized/recipes/default.rb
serverinfo: fix vendor folder
[chef.git] / cookbooks / oxidized / recipes / default.rb
1 #
2 # Cookbook:: oxidized
3 # Recipe:: default
4 #
5 # Copyright:: 2022, 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 "git"
21 include_recipe "ruby"
22
23 package %w[
24   gcc
25   g++
26   make
27   cmake
28   libssl-dev
29   libssh2-1-dev
30   zlib1g-dev
31   pkg-config
32 ]
33
34 keys = data_bag_item("oxidized", "keys")
35 devices = data_bag_item("oxidized", "devices")
36
37 directory "/etc/oxidized" do
38   owner "root"
39   group "root"
40   mode "755"
41 end
42
43 template "/etc/oxidized/config" do
44   source "config.erb"
45   owner "oxidized"
46   group "oxidized"
47   mode "444"
48   notifies :restart, "service[oxidized]"
49 end
50
51 template "/etc/oxidized/routers.db" do
52   source "routers.db.erb"
53   owner "oxidized"
54   group "oxidized"
55   mode "400"
56   variables :devices => devices
57   notifies :restart, "service[oxidized]"
58 end
59
60 directory "/var/log/oxidized" do
61   owner "oxidized"
62   group "oxidized"
63   mode "755"
64 end
65
66 directory "/opt/oxidized" do
67   owner "oxidized"
68   group "oxidized"
69   mode "755"
70 end
71
72 git "/opt/oxidized/daemon" do
73   action :sync
74   repository "https://github.com/openstreetmap/oxidized.git"
75   depth 1
76   user "oxidized"
77   group "oxidized"
78   notifies :run, "bundle_install[/opt/oxidized/daemon]", :immediately
79 end
80
81 directory "/opt/oxidized/.ssh" do
82   owner "oxidized"
83   group "oxidized"
84   mode "700"
85 end
86
87 # Key is set as a deployment key in github repo
88 file "/opt/oxidized/.ssh/id_ed25519" do
89   content keys["git"].join("\n")
90   owner "oxidized"
91   group "oxidized"
92   mode "400"
93   notifies :delete, "file[/opt/oxidized/.ssh/id_ed25519.pub]", :immediately
94   notifies :restart, "service[oxidized]"
95 end
96
97 # Ensure public key is deleted if private key is changed. Trigged by notify
98 file "/opt/oxidized/.ssh/id_ed25519.pub" do
99   action :nothing
100 end
101
102 execute "/opt/oxidized/.ssh/id_ed25519.pub" do
103   command "ssh-keygen -f /opt/oxidized/.ssh/id_ed25519 -y > /opt/oxidized/.ssh/id_ed25519.pub"
104   user "oxidized"
105   group "oxidized"
106   creates "/opt/oxidized/.ssh/id_ed25519.pub"
107   notifies :restart, "service[oxidized]"
108 end
109
110 ssh_known_hosts_entry "github.com" do
111   action [:create, :flush]
112   file_location "/opt/oxidized/.ssh/known_hosts"
113   owner "oxidized"
114   group "oxidized"
115 end
116
117 directory "/var/lib/oxidized" do
118   owner "oxidized"
119   group "oxidized"
120   mode "750"
121 end
122
123 git "/var/lib/oxidized/configs.git" do
124   action :sync
125   repository "git@github.com:openstreetmap/oxidized-configs.git" # Uses oxidized ssh key
126   checkout_branch "master" # branch is hardcoded in oxidized
127   user "oxidized"
128   group "oxidized"
129 end
130
131 bundle_install "/opt/oxidized/daemon" do
132   action :nothing
133   options "--deployment"
134   user "oxidized"
135   group "oxidized"
136   notifies :restart, "service[oxidized]"
137 end
138
139 # Based on https://github.com/ytti/oxidized/blob/master/extra/oxidized.service
140 systemd_service "oxidized" do
141   description "oxidized network device backup daemon"
142   after "network.target"
143   user "oxidized"
144   working_directory "/opt/oxidized/daemon"
145   runtime_directory "oxidized"
146   exec_start "#{node[:ruby][:bundle]} exec oxidized"
147   environment "OXIDIZED_HOME" => "/etc/oxidized",
148               "OXIDIZED_LOGS" => "/var/log/oxidized"
149   nice 10
150   sandbox :enable_network => true
151   read_write_paths ["/run/oxidized", "/var/lib/oxidized", "/var/log/oxidized"]
152   restart "on-failure"
153   notifies :restart, "service[oxidized]"
154 end
155
156 service "oxidized" do
157   action [:enable, :start]
158 end
159
160 template "/etc/logrotate.d/oxidized" do
161   source "logrotate.erb"
162   owner "root"
163   group "root"
164   mode "644"
165 end