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 include_recipe "tools"
21 include_recipe "munin"
23 case node[:cpu][:"0"][:vendor_id]
25 package "intel-microcode"
28 case node[:cpu][:"0"][:vendor_id]
30 if node[:lsb][:release].to_f >= 14.04
31 package "amd64-microcode"
35 if node[:dmi] && node[:dmi][:system]
36 case node[:dmi][:system][:manufacturer]
38 manufacturer = node[:dmi][:base_board][:manufacturer]
39 product = node[:dmi][:base_board][:product_name]
41 manufacturer = node[:dmi][:system][:manufacturer]
42 product = node[:dmi][:system][:product_name]
45 manufacturer = "Unknown"
58 when "TYAN Computer Corporation"
63 when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW"
75 if manufacturer == "HP" && node[:lsb][:release].to_f > 11.10
78 git "/opt/hp/hp-legacy" do
80 repository "git://chef.openstreetmap.org/hp-legacy.git"
85 link "/opt/hp/hp-health/bin/hpasmd" do
86 to "/opt/hp/hp-legacy/hpasmd"
89 link "/usr/lib/libhpasmintrfc.so.3.0" do
90 to "/opt/hp/hp-legacy/libhpasmintrfc.so.3.0"
93 link "/usr/lib/libhpasmintrfc.so.3" do
94 to "libhpasmintrfc.so.3.0"
97 link "/usr/lib/libhpasmintrfc.so" do
98 to "libhpasmintrfc.so.3.0"
103 file "/etc/init/ttySttyS#{unit}.conf" do
107 template "/etc/init/ttyS#{unit}.conf" do
108 source "tty.conf.erb"
112 variables :unit => unit, :speed => speed
115 service "ttyS#{unit}" do
116 provider Chef::Provider::Service::Upstart
117 action [:enable, :start]
118 supports :status => true, :restart => true, :reload => false
119 subscribes :restart, "template[/etc/init/ttyS#{unit}.conf]"
123 # if we need a different / special kernel version to make the hardware
124 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
125 # ensure that we have the package installed. the grub template will
126 # make sure that this is the default on boot.
127 unless node[:hardware][:grub][:kernel] == :latest
128 package "linux-image-#{node[:hardware][:grub][:kernel]}-generic"
129 package "linux-image-extra-#{node[:hardware][:grub][:kernel]}-generic"
130 package "linux-headers-#{node[:hardware][:grub][:kernel]}-generic"
133 if File.exist?("/etc/default/grub")
134 execute "update-grub" do
136 command "/usr/sbin/update-grub"
139 template "/etc/default/grub" do
144 variables :unit => unit, :speed => speed
145 notifies :run, "execute[update-grub]"
149 execute "update-initramfs" do
151 command "update-initramfs -u -k all"
156 template "/etc/initramfs-tools/conf.d/mdadm" do
157 source "initramfs-mdadm.erb"
161 notifies :run, "execute[update-initramfs]"
166 action [:enable, :start]
169 if node[:kernel][:modules].include?("ipmi_si")
173 if node[:lsb][:release].to_f >= 12.10
176 template "/etc/default/irqbalance" do
177 source "irqbalance.erb"
183 service "irqbalance" do
184 action [:start, :enable]
185 supports :status => false, :restart => true, :reload => false
186 subscribes :restart, "template[/etc/default/irqbalance]"
193 node[:kernel][:modules].each_key do |modname|
196 tools_packages << "hpacucli"
197 status_packages["cciss-vol-status"] ||= []
199 tools_packages << "hpacucli"
200 status_packages["cciss-vol-status"] ||= []
202 tools_packages << "lsiutil"
203 # status_packages["mpt-status"] ||= []
204 when "mpt2sas", "mpt3sas"
205 tools_packages << "sas2ircu"
206 status_packages["sas2ircu-status"] ||= []
208 tools_packages << "megactl"
209 status_packages["megaraid-status"] ||= []
211 tools_packages << "megacli"
212 status_packages["megaclisas-status"] ||= []
214 tools_packages << "arcconf"
215 status_packages["aacraid-status"] ||= []
217 tools_packages << "areca"
221 node[:block_device].each do |name, attributes|
222 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
224 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
225 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
227 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
228 status_packages["cciss-vol-status"] |= [File.basename(sg)]
233 %w(hpacucli lsiutil sas2ircu megactl megacli arcconf).each do |tools_package|
234 if tools_packages.include?(tools_package)
235 package tools_package
237 package tools_package do
243 if tools_packages.include?("areca")
248 repository "git://chef.openstreetmap.org/areca.git"
253 directory "/opt/areca" do
259 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
260 if status_packages.include?(status_package)
261 package status_package
263 template "/etc/default/#{status_package}d" do
264 source "raid.default.erb"
268 variables :devices => status_packages[status_package]
271 service "#{status_package}d" do
272 action [:start, :enable]
273 supports :status => false, :restart => true, :reload => false
274 subscribes :restart, "template[/etc/default/#{status_package}d]"
277 package status_package do
281 file "/etc/default/#{status_package}d" do
289 node[:block_device].each do |name, attributes|
290 disks << { :device => name } if attributes[:vendor] == "ATA"
293 if status_packages["cciss-vol-status"] && File.exist?("/usr/sbin/cciss_vol_status")
294 status_packages["cciss-vol-status"].each do |device|
295 IO.popen(["cciss_vol_status", "-V", "/dev/#{device}"]).each do |line|
296 disks << { :device => device, :driver => "cciss", :id => Regexp.last_match[1].to_i - 1 } if line =~ / bay ([0-9]+) +HP /
301 if status_packages["megaclisas-status"]
304 Dir.glob("/sys/class/scsi_host/host*") do |host|
305 driver = File.new("#{host}/proc_name").read.chomp
307 next unless driver == "megaraid_sas"
309 bus = host.sub("/sys/class/scsi_host/host", "")
310 device = File.basename(Dir.glob("/sys/bus/scsi/devices/#{bus}:*/scsi_generic/*").first)
312 IO.popen(["megacli", "-PDList", "-a#{controller}", "-NoLog"]).each do |line|
313 disks << { :device => device, :driver => "megaraid", :id => Regexp.last_match[1] } if line =~ /^Device Id: ([0-9]+)$/
315 disks.pop if line =~ /^Firmware state: Hotspare, Spun down$/
322 if tools_packages.include?("lsiutil")
323 Dir.glob("/sys/class/scsi_host/host*") do |host|
324 driver = File.new("#{host}/proc_name").read.chomp
326 next unless driver == "mptsas"
328 bus = host.sub("/sys/class/scsi_host/host", "")
330 Dir.glob("/sys/bus/scsi/devices/#{bus}:0:*/scsi_generic/*").each do |sg|
331 disks << { :device => File.basename(sg) }
336 if status_packages["sas2ircu-status"]
337 Dir.glob("/sys/class/scsi_host/host*") do |host|
338 driver = File.new("#{host}/proc_name").read.chomp
340 next unless driver == "mpt2sas" || driver == "mpt3sas"
342 bus = host.sub("/sys/class/scsi_host/host", "")
344 Dir.glob("/sys/bus/scsi/devices/#{bus}:0:*/scsi_generic/*").each do |sg|
345 next if File.directory?("#{sg}/../../block")
347 disks << { :device => File.basename(sg) }
352 if status_packages["aacraid-status"]
353 Dir.glob("/sys/class/scsi_host/host*") do |host|
354 driver = File.new("#{host}/proc_name").read.chomp
356 next unless driver == "aacraid"
358 bus = host.sub("/sys/class/scsi_host/host", "")
360 Dir.glob("/sys/bus/scsi/devices/#{bus}:1:*/scsi_generic/*").each do |sg|
361 disks << { :device => File.basename(sg) }
366 if tools_packages.include?("areca") && File.exist?("/opt/areca/x86_64/cli64")
367 device = IO.popen(["lsscsi", "-g"]).grep(%r{Areca +RAID controller .*/dev/(sg[0-9]+)}) do
371 IO.popen(["/opt/areca/x86_64/cli64", "disk", "info"]).each do |line|
372 next if line =~ /N\.A\./
374 if line =~ /^ +[0-9]+ +0*([0-9]+) +(?:Slot#|SLOT )0*([0-9]+) +/
375 enc = Regexp.last_match[1]
376 slot = Regexp.last_match[2]
378 disks << { :device => device, :driver => "areca", :id => "#{slot}/#{enc}" }
379 elsif line =~ /^ +([0-9]+) +[0-9]+ +/
380 disks << { :device => device, :driver => "areca", :id => Regexp.last_match[1] }
386 if disk[:device] =~ %r{^cciss/(.*)$}
387 id = File.read("/sys/bus/cciss/devices/#{Regexp.last_match[1]}/unique_id").chomp
389 disk[:munin] = "cciss-3#{id.downcase}"
391 disk[:munin] = disk[:device]
395 disk[:munin] = "#{disk[:munin]}-#{disk[:id].to_s.tr('/', ':')}"
398 disk[:hddtemp] = disk[:munin].tr("-:", "_")
402 package "smartmontools"
404 template "/etc/smartd.conf" do
405 source "smartd.conf.erb"
409 variables :disks => disks
410 notifies :reload, "service[smartmontools]"
413 template "/etc/default/smartmontools" do
414 source "smartmontools.erb"
418 notifies :restart, "service[smartmontools]"
421 service "smartmontools" do
422 action [:enable, :start]
423 supports :status => true, :restart => true, :reload => true
426 # Don't try and do munin monitoring of disks behind
427 # an Areca controller as they only allow one thing to
428 # talk to the controller at a time and smartd will
429 # throw errors if it clashes with munin
430 disks = disks.reject { |disk| disk[:driver] == "areca" }
433 munin_plugin "smart_#{disk[:munin]}" do
435 conf "munin.smart.erb"
436 conf_variables :disk => disk
440 munin_plugin "hddtemp_smartctl" do
441 conf "munin.hddtemp.erb"
442 conf_variables :disks => disks
445 service "smartmontools" do
446 action [:stop, :disable]
449 munin_plugin "hddtemp_smartctl" do
454 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
455 disks.map { |d| "smart_#{d[:munin]}" }
457 plugins.each do |plugin|
458 munin_plugin plugin do
463 if File.exist?("/etc/mdadm/mdadm.conf")
464 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
465 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
470 file "/etc/mdadm/mdadm.conf" do
479 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
483 template "/etc/modules" do
490 if node[:lsb][:release].to_f <= 12.10
491 service "module-init-tools" do
492 provider Chef::Provider::Service::Upstart
494 subscribes :start, "template[/etc/modules]"
498 provider Chef::Provider::Service::Upstart
500 subscribes :start, "template[/etc/modules]"
504 if node[:hardware][:watchdog]
507 template "/etc/default/watchdog" do
508 source "watchdog.erb"
512 variables :module => node[:hardware][:watchdog]
515 service "watchdog" do
516 action [:enable, :start]
520 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
523 execute "/etc/sensors.d/chef.conf" do
525 command "/usr/bin/sensors -s"
530 template "/etc/sensors.d/chef.conf" do
531 source "sensors.conf.erb"
535 notifies :run, "execute[/etc/sensors.d/chef.conf]"