]> git.openstreetmap.org Git - chef.git/blob - cookbooks/hardware/recipes/default.rb
7923d3868d0213e8114ba0225c3628c78f9a2fac
[chef.git] / cookbooks / hardware / recipes / default.rb
1 #
2 # Cookbook Name:: hardware
3 # Recipe:: default
4 #
5 # Copyright 2012, 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 #     http://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 case node[:cpu][:"0"][:vendor_id]
21 when "GenuineIntel"
22   package "intel-microcode"
23 end
24
25 case node[:cpu][:"0"][:vendor_id]
26 when "AuthenticAMD"
27   if node[:lsb][:release].to_f >= 14.04
28     package "amd64-microcode"
29   end
30 end
31
32 if node[:dmi] and node[:dmi][:system]
33   case node[:dmi][:system][:manufacturer]
34   when "empty"
35     manufacturer = node[:dmi][:base_board][:manufacturer]
36     product = node[:dmi][:base_board][:product_name]
37   else
38     manufacturer = node[:dmi][:system][:manufacturer]
39     product = node[:dmi][:system][:product_name]
40   end
41 else
42   manufacturer = "Unknown"
43   product = "Unknown"
44 end
45
46 case manufacturer
47 when "HP"
48   package "hponcfg"
49   package "hp-health"
50   unit = "1"
51   speed = "115200"
52 when "TYAN"
53   unit = "0"
54   speed = "115200"
55 when "TYAN Computer Corporation"
56   unit = "0"
57   speed = "115200"
58 when "Supermicro"
59   case product
60   when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW"
61     unit = "1"
62     speed = "115200"
63   else
64     unit = "0"
65     speed = "115200"
66   end
67 when "IBM"
68   unit = "0"
69   speed = "115200"
70 end
71
72 if manufacturer == "HP" and node[:lsb][:release].to_f > 11.10
73   include_recipe "git"
74
75   git "/opt/hp/hp-legacy" do
76     action :sync
77     repository "git://chef.openstreetmap.org/hp-legacy.git"
78     user "root"
79     group "root"
80   end
81
82   link "/opt/hp/hp-health/bin/hpasmd" do
83     to "/opt/hp/hp-legacy/hpasmd"
84   end
85
86   link "/usr/lib/libhpasmintrfc.so.3.0" do
87     to "/opt/hp/hp-legacy/libhpasmintrfc.so.3.0"
88   end
89
90   link "/usr/lib/libhpasmintrfc.so.3" do
91     to "libhpasmintrfc.so.3.0"
92   end
93
94   link "/usr/lib/libhpasmintrfc.so" do
95     to "libhpasmintrfc.so.3.0"
96   end
97 end
98
99 unless unit.nil?
100   file "/etc/init/ttySttyS#{unit}.conf" do
101     action :delete
102   end
103
104   template "/etc/init/ttyS#{unit}.conf" do
105     source "tty.conf.erb"
106     owner "root"
107     group "root"
108     mode 0644
109     variables :unit => unit, :speed => speed
110   end
111
112   service "ttyS#{unit}" do
113     provider Chef::Provider::Service::Upstart
114     action [ :enable, :start ]
115     supports :status => true, :restart => true, :reload => false
116     subscribes :restart, "template[/etc/init/ttyS#{unit}.conf]"
117   end
118 end
119
120 if File.exist?("/etc/default/grub")
121   execute "update-grub" do
122     action :nothing
123     command "/usr/sbin/update-grub"
124   end
125
126   template "/etc/default/grub" do
127     source "grub.erb"
128     owner "root"
129     group "root"
130     mode 0644
131     variables :unit => unit, :speed => speed
132     notifies :run, "execute[update-grub]"
133   end
134 end
135
136 execute "update-initramfs" do
137   action :nothing
138   command "update-initramfs -u -k all"
139   user "root"
140   group "root"
141 end
142
143 template "/etc/initramfs-tools/conf.d/mdadm" do
144   source "initramfs-mdadm.erb"
145   owner "root"
146   group "root"
147   mode 0644
148   notifies :run, "execute[update-initramfs]"
149 end
150
151 if node[:kernel][:modules].include?("ipmi_si")
152   package "ipmitool"
153 end
154
155 if node[:lsb][:release].to_f >= 12.10
156   package "irqbalance"
157
158   template "/etc/default/irqbalance" do
159     source "irqbalance.erb"
160     owner "root"
161     group "root"
162     mode 0644
163   end
164
165   service "irqbalance" do
166     action [ :start, :enable ]
167     supports :status => false, :restart => true, :reload => false
168     subscribes :restart, "template[/etc/default/irqbalance]"
169   end
170 end
171
172 tools_packages = []
173 status_packages = {}
174
175 node[:kernel][:modules].each_key do |modname|
176   case modname
177   when "cciss"
178     tools_packages << "hpacucli"
179     status_packages["cciss-vol-status"] ||= []
180   when "hpsa"
181     tools_packages << "hpacucli"
182     status_packages["cciss-vol-status"] ||= []
183   when "mptsas"
184     tools_packages << "lsiutil"
185     #status_packages["mpt-status"] ||= []
186   when "mpt2sas"
187     tools_packages << "sas2ircu"
188     status_packages["sas2ircu-status"] ||= []
189   when "megaraid_mm"
190     tools_packages << "megactl"
191     status_packages["megaraid-status"] ||= []
192   when "megaraid_sas"
193     tools_packages << "megacli"
194     status_packages["megaclisas-status"] ||= []
195   when "aacraid"
196     tools_packages << "arcconf"
197     status_packages["aacraid-status"] ||= []
198   end
199 end
200
201 node[:block_device].each do |name,attributes|
202   if attributes[:vendor] == "HP" and attributes[:model] == "LOGICAL VOLUME"
203     if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
204       status_packages["cciss-vol-status"] |= [ "cciss/#{$1}d0" ]
205     else
206       Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
207         status_packages["cciss-vol-status"] |= [ File.basename(sg) ]
208       end
209     end
210   end
211 end
212
213 ["hpacucli", "lsiutil", "sas2ircu", "megactl", "megacli", "arcconf"].each do |tools_package|
214   if tools_packages.include?(tools_package)
215     package tools_package
216   else
217     package tools_package do
218       action :purge
219     end
220   end
221 end
222
223 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
224   if status_packages.include?(status_package)
225     package status_package
226
227     template "/etc/default/#{status_package}d" do
228       source "raid.default.erb"
229       owner "root"
230       group "root"
231       mode 0644
232       variables :devices => status_packages[status_package]
233     end
234
235     service "#{status_package}d" do
236       action [ :start, :enable ]
237       supports :status => false, :restart => true, :reload => false
238       subscribes :restart, "template[/etc/default/#{status_package}d]"
239     end
240   else
241     package status_package do
242       action :purge
243     end
244
245     file "/etc/default/#{status_package}d" do
246       action :delete
247     end
248   end
249 end
250
251 if File.exists?("/proc/xen")
252   watchdog = "xen_wdt"
253 elsif node[:kernel][:modules].include?("i6300esb")
254   watchdog = "none"
255 end
256
257 if watchdog
258   package "watchdog"
259
260   template "/etc/default/watchdog" do
261     source "watchdog.erb"
262     owner "root"
263     group "root"
264     mode 0644
265     variables :module => watchdog
266   end
267
268   service "watchdog" do
269     action [ :enable, :start ]
270   end
271 end