2 # Cookbook Name:: hardware
5 # Copyright 2012, OpenStreetMap Foundation
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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.
20 case node[:cpu][:"0"][:vendor_id]
22 package "intel-microcode"
25 case node[:cpu][:"0"][:vendor_id]
27 if node[:lsb][:release].to_f >= 14.04
28 package "amd64-microcode"
32 if node[:dmi] && node[:dmi][:system]
33 case node[:dmi][:system][:manufacturer]
35 manufacturer = node[:dmi][:base_board][:manufacturer]
36 product = node[:dmi][:base_board][:product_name]
38 manufacturer = node[:dmi][:system][:manufacturer]
39 product = node[:dmi][:system][:product_name]
42 manufacturer = "Unknown"
55 when "TYAN Computer Corporation"
60 when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW"
72 if manufacturer == "HP" && node[:lsb][:release].to_f > 11.10
75 git "/opt/hp/hp-legacy" do
77 repository "git://chef.openstreetmap.org/hp-legacy.git"
82 link "/opt/hp/hp-health/bin/hpasmd" do
83 to "/opt/hp/hp-legacy/hpasmd"
86 link "/usr/lib/libhpasmintrfc.so.3.0" do
87 to "/opt/hp/hp-legacy/libhpasmintrfc.so.3.0"
90 link "/usr/lib/libhpasmintrfc.so.3" do
91 to "libhpasmintrfc.so.3.0"
94 link "/usr/lib/libhpasmintrfc.so" do
95 to "libhpasmintrfc.so.3.0"
100 file "/etc/init/ttySttyS#{unit}.conf" do
104 template "/etc/init/ttyS#{unit}.conf" do
105 source "tty.conf.erb"
109 variables :unit => unit, :speed => speed
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]"
120 if File.exist?("/etc/default/grub")
121 execute "update-grub" do
123 command "/usr/sbin/update-grub"
126 template "/etc/default/grub" do
131 variables :unit => unit, :speed => speed
132 notifies :run, "execute[update-grub]"
136 execute "update-initramfs" do
138 command "update-initramfs -u -k all"
143 template "/etc/initramfs-tools/conf.d/mdadm" do
144 source "initramfs-mdadm.erb"
148 notifies :run, "execute[update-initramfs]"
153 action [:enable, :start]
156 if node[:kernel][:modules].include?("ipmi_si")
160 if node[:lsb][:release].to_f >= 12.10
163 template "/etc/default/irqbalance" do
164 source "irqbalance.erb"
170 service "irqbalance" do
171 action [:start, :enable]
172 supports :status => false, :restart => true, :reload => false
173 subscribes :restart, "template[/etc/default/irqbalance]"
180 node[:kernel][:modules].each_key do |modname|
183 tools_packages << "hpacucli"
184 status_packages["cciss-vol-status"] ||= []
186 tools_packages << "hpacucli"
187 status_packages["cciss-vol-status"] ||= []
189 tools_packages << "lsiutil"
190 # status_packages["mpt-status"] ||= []
192 tools_packages << "sas2ircu"
193 status_packages["sas2ircu-status"] ||= []
195 tools_packages << "megactl"
196 status_packages["megaraid-status"] ||= []
198 tools_packages << "megacli"
199 status_packages["megaclisas-status"] ||= []
201 tools_packages << "arcconf"
202 status_packages["aacraid-status"] ||= []
206 node[:block_device].each do |name, attributes|
207 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
209 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
210 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
212 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
213 status_packages["cciss-vol-status"] |= [File.basename(sg)]
218 %w(hpacucli lsiutil sas2ircu megactl megacli arcconf).each do |tools_package|
219 if tools_packages.include?(tools_package)
220 package tools_package
222 package tools_package do
228 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
229 if status_packages.include?(status_package)
230 package status_package
232 template "/etc/default/#{status_package}d" do
233 source "raid.default.erb"
237 variables :devices => status_packages[status_package]
240 service "#{status_package}d" do
241 action [:start, :enable]
242 supports :status => false, :restart => true, :reload => false
243 subscribes :restart, "template[/etc/default/#{status_package}d]"
246 package status_package do
250 file "/etc/default/#{status_package}d" do
258 node[:block_device].each do |name, attributes|
259 disks << { :device => name } if attributes[:vendor] == "ATA"
262 if status_packages["cciss-vol-status"]
263 status_packages["cciss-vol-status"].each do |device|
264 IO.popen(["cciss_vol_status", "-V", "/dev/#{device}"]).each do |line|
265 disks << { :device => device, :driver => "cciss", :id => Regexp.last_match[1].to_i - 1 } if line =~ / bay ([0-9]+) +HP /
270 if status_packages["megaclisas-status"]
273 Dir.glob("/sys/class/scsi_host/host*") do |host|
274 driver = File.new("#{host}/proc_name").read.chomp
276 next unless driver == "megaraid_sas"
278 bus = host.sub("/sys/class/scsi_host/host", "")
279 device = File.basename(Dir.glob("/sys/bus/scsi/devices/#{bus}:*/scsi_generic/*").first)
281 IO.popen(["megacli", "-PDList", "-a#{controller}", "-NoLog"]).each do |line|
282 disks << { :device => device, :driver => "megaraid", :id => Regexp.last_match[1] } if line =~ /^Device Id: ([0-9]+)$/
284 disks.pop if line =~ /^Firmware state: Hotspare, Spun down$/
291 if status_packages["sas2ircu-status"]
292 Dir.glob("/sys/class/scsi_host/host*") do |host|
293 driver = File.new("#{host}/proc_name").read.chomp
295 next unless driver == "mpt2sas"
297 bus = host.sub("/sys/class/scsi_host/host", "")
299 Dir.glob("/sys/bus/scsi/devices/#{bus}:0:*/scsi_generic/*").each do |sg|
300 disks << { :device => File.basename(sg) }
305 if status_packages["aacraid-status"]
306 Dir.glob("/sys/class/scsi_host/host*") do |host|
307 driver = File.new("#{host}/proc_name").read.chomp
309 next unless driver == "aacraid"
311 bus = host.sub("/sys/class/scsi_host/host", "")
313 Dir.glob("/sys/bus/scsi/devices/#{bus}:1:*/scsi_generic/*").each do |sg|
314 disks << { :device => File.basename(sg) }
320 package "smartmontools"
322 template "/etc/smartd.conf" do
323 source "smartd.conf.erb"
327 variables :disks => disks
328 notifies :reload, "service[smartmontools]"
331 template "/etc/default/smartmontools" do
332 source "smartmontools.erb"
336 notifies :restart, "service[smartmontools]"
339 service "smartmontools" do
340 action [:enable, :start]
343 service "smartmontools" do
344 action [:stop, :disable]
348 if File.exist?("/etc/mdadm/mdadm.conf")
349 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
350 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
355 file "/etc/mdadm/mdadm.conf" do
364 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
368 template "/etc/modules" do
375 if node[:lsb][:release].to_f <= 12.10
376 service "module-init-tools" do
377 provider Chef::Provider::Service::Upstart
379 subscribes :start, "template[/etc/modules]"
383 provider Chef::Provider::Service::Upstart
385 subscribes :start, "template[/etc/modules]"
389 if node[:hardware][:watchdog]
392 template "/etc/default/watchdog" do
393 source "watchdog.erb"
397 variables :module => node[:hardware][:watchdog]
400 service "watchdog" do
401 action [:enable, :start]
405 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
408 execute "/etc/sensors.d/chef.conf" do
410 command "/usr/bin/sensors -s"
415 template "/etc/sensors.d/chef.conf" do
416 source "sensors.conf.erb"
420 notifies :run, "execute[/etc/sensors.d/chef.conf]"