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"
86 link "/opt/hp/hp-health/bin/hpasmd" do
87 to "/opt/hp/hp-legacy/hpasmd"
90 link "/usr/lib/libhpasmintrfc.so.3.0" do
91 to "/opt/hp/hp-legacy/libhpasmintrfc.so.3.0"
94 link "/usr/lib/libhpasmintrfc.so.3" do
95 to "libhpasmintrfc.so.3.0"
98 link "/usr/lib/libhpasmintrfc.so" do
99 to "libhpasmintrfc.so.3.0"
104 file "/etc/init/ttySttyS#{unit}.conf" do
108 template "/etc/init/ttyS#{unit}.conf" do
109 source "tty.conf.erb"
113 variables :unit => unit, :speed => speed
116 service "ttyS#{unit}" do
117 provider Chef::Provider::Service::Upstart
118 action [:enable, :start]
119 supports :status => true, :restart => true, :reload => false
120 subscribes :restart, "template[/etc/init/ttyS#{unit}.conf]"
124 # if we need a different / special kernel version to make the hardware
125 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
126 # ensure that we have the package installed. the grub template will
127 # make sure that this is the default on boot.
128 if node[:hardware][:grub][:kernel]
129 kernel_version = node[:hardware][:grub][:kernel]
131 package "linux-image-#{kernel_version}-generic"
132 package "linux-image-extra-#{kernel_version}-generic"
133 package "linux-headers-#{kernel_version}-generic"
135 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
136 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
137 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
142 if File.exist?("/etc/default/grub")
143 execute "update-grub" do
145 command "/usr/sbin/update-grub"
148 template "/etc/default/grub" do
153 variables :unit => unit, :speed => speed, :entry => grub_entry
154 notifies :run, "execute[update-grub]"
158 execute "update-initramfs" do
160 command "update-initramfs -u -k all"
165 template "/etc/initramfs-tools/conf.d/mdadm" do
166 source "initramfs-mdadm.erb"
170 notifies :run, "execute[update-initramfs]"
175 action [:enable, :start]
178 if node[:kernel][:modules].include?("ipmi_si")
182 if node[:lsb][:release].to_f >= 12.10
185 template "/etc/default/irqbalance" do
186 source "irqbalance.erb"
192 service "irqbalance" do
193 action [:start, :enable]
194 supports :status => false, :restart => true, :reload => false
195 subscribes :restart, "template[/etc/default/irqbalance]"
202 node[:kernel][:modules].each_key do |modname|
205 tools_packages << "hpssacli"
206 status_packages["cciss-vol-status"] ||= []
208 tools_packages << "hpssacli"
209 status_packages["cciss-vol-status"] ||= []
211 tools_packages << "lsiutil"
212 # status_packages["mpt-status"] ||= []
213 when "mpt2sas", "mpt3sas"
214 tools_packages << "sas2ircu"
215 status_packages["sas2ircu-status"] ||= []
217 tools_packages << "megactl"
218 status_packages["megaraid-status"] ||= []
220 tools_packages << "megacli"
221 status_packages["megaclisas-status"] ||= []
223 tools_packages << "arcconf"
224 status_packages["aacraid-status"] ||= []
226 tools_packages << "areca"
230 node[:block_device].each do |name, attributes|
231 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
233 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
234 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
236 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
237 status_packages["cciss-vol-status"] |= [File.basename(sg)]
242 %w(hpacucli lsiutil sas2ircu megactl megacli arcconf).each do |tools_package|
243 if tools_packages.include?(tools_package)
244 package tools_package
246 package tools_package do
252 if tools_packages.include?("areca")
257 repository "git://chef.openstreetmap.org/areca.git"
262 directory "/opt/areca" do
268 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
269 if status_packages.include?(status_package)
270 package status_package
272 template "/etc/default/#{status_package}d" do
273 source "raid.default.erb"
277 variables :devices => status_packages[status_package]
280 service "#{status_package}d" do
281 action [:start, :enable]
282 supports :status => false, :restart => true, :reload => false
283 subscribes :restart, "template[/etc/default/#{status_package}d]"
286 package status_package do
290 file "/etc/default/#{status_package}d" do
298 node[:block_device].each do |name, attributes|
299 disks << { :device => name } if attributes[:vendor] == "ATA"
302 if status_packages["cciss-vol-status"] && File.exist?("/usr/sbin/cciss_vol_status")
303 status_packages["cciss-vol-status"].each do |device|
304 IO.popen(["cciss_vol_status", "-V", "/dev/#{device}"]).each do |line|
305 disks << { :device => device, :driver => "cciss", :id => Regexp.last_match[1].to_i - 1 } if line =~ / bay ([0-9]+) +HP /
310 if status_packages["megaclisas-status"]
313 Dir.glob("/sys/class/scsi_host/host*") do |host|
314 driver = File.new("#{host}/proc_name").read.chomp
316 next unless driver == "megaraid_sas"
318 bus = host.sub("/sys/class/scsi_host/host", "")
319 device = File.basename(Dir.glob("/sys/bus/scsi/devices/#{bus}:*/scsi_generic/*").first)
321 IO.popen(["megacli", "-PDList", "-a#{controller}", "-NoLog"]).each do |line|
322 disks << { :device => device, :driver => "megaraid", :id => Regexp.last_match[1] } if line =~ /^Device Id: ([0-9]+)$/
324 disks.pop if line =~ /^Firmware state: Hotspare, Spun down$/
331 if tools_packages.include?("lsiutil")
332 Dir.glob("/sys/class/scsi_host/host*") do |host|
333 driver = File.new("#{host}/proc_name").read.chomp
335 next unless driver == "mptsas"
337 bus = host.sub("/sys/class/scsi_host/host", "")
339 Dir.glob("/sys/bus/scsi/devices/#{bus}:0:*/scsi_generic/*").each do |sg|
340 disks << { :device => File.basename(sg) }
345 if status_packages["sas2ircu-status"]
346 Dir.glob("/sys/class/scsi_host/host*") do |host|
347 driver = File.new("#{host}/proc_name").read.chomp
349 next unless driver == "mpt2sas" || driver == "mpt3sas"
351 bus = host.sub("/sys/class/scsi_host/host", "")
353 Dir.glob("/sys/bus/scsi/devices/#{bus}:0:*/scsi_generic/*").each do |sg|
354 next if File.directory?("#{sg}/../../block")
356 disks << { :device => File.basename(sg) }
361 if status_packages["aacraid-status"]
362 Dir.glob("/sys/class/scsi_host/host*") do |host|
363 driver = File.new("#{host}/proc_name").read.chomp
365 next unless driver == "aacraid"
367 bus = host.sub("/sys/class/scsi_host/host", "")
369 Dir.glob("/sys/bus/scsi/devices/#{bus}:1:*/scsi_generic/*").each do |sg|
370 disks << { :device => File.basename(sg) }
375 if tools_packages.include?("areca") && File.exist?("/opt/areca/x86_64/cli64")
376 device = IO.popen(["lsscsi", "-g"]).grep(%r{Areca +RAID controller .*/dev/(sg[0-9]+)}) do
380 IO.popen(["/opt/areca/x86_64/cli64", "disk", "info"]).each do |line|
381 next if line =~ /N\.A\./
383 if line =~ /^ +[0-9]+ +0*([0-9]+) +(?:Slot#|SLOT )0*([0-9]+) +/
384 enc = Regexp.last_match[1]
385 slot = Regexp.last_match[2]
387 disks << { :device => device, :driver => "areca", :id => "#{slot}/#{enc}" }
388 elsif line =~ /^ +([0-9]+) +[0-9]+ +/
389 disks << { :device => device, :driver => "areca", :id => Regexp.last_match[1] }
395 if disk[:device] =~ %r{^cciss/(.*)$}
396 id = File.read("/sys/bus/cciss/devices/#{Regexp.last_match[1]}/unique_id").chomp
398 disk[:munin] = "cciss-3#{id.downcase}"
400 disk[:munin] = disk[:device]
404 disk[:munin] = "#{disk[:munin]}-#{disk[:id].to_s.tr('/', ':')}"
407 disk[:hddtemp] = disk[:munin].tr("-:", "_")
411 package "smartmontools"
413 template "/usr/local/bin/smartd-mailer" do
414 source "smartd-mailer.erb"
420 template "/etc/smartd.conf" do
421 source "smartd.conf.erb"
425 variables :disks => disks
426 notifies :reload, "service[smartmontools]"
429 template "/etc/default/smartmontools" do
430 source "smartmontools.erb"
434 notifies :restart, "service[smartmontools]"
437 service "smartmontools" do
438 action [:enable, :start]
439 supports :status => true, :restart => true, :reload => true
442 # Don't try and do munin monitoring of disks behind
443 # an Areca controller as they only allow one thing to
444 # talk to the controller at a time and smartd will
445 # throw errors if it clashes with munin
446 disks = disks.reject { |disk| disk[:driver] == "areca" }
449 munin_plugin "smart_#{disk[:munin]}" do
451 conf "munin.smart.erb"
452 conf_variables :disk => disk
456 munin_plugin "hddtemp_smartctl" do
457 conf "munin.hddtemp.erb"
458 conf_variables :disks => disks
461 service "smartmontools" do
462 action [:stop, :disable]
465 munin_plugin "hddtemp_smartctl" do
470 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
471 disks.map { |d| "smart_#{d[:munin]}" }
473 plugins.each do |plugin|
474 munin_plugin plugin do
479 if File.exist?("/etc/mdadm/mdadm.conf")
480 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
481 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
486 file "/etc/mdadm/mdadm.conf" do
495 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
499 template "/etc/modules" do
506 if node[:lsb][:release].to_f <= 12.10
507 service "module-init-tools" do
508 provider Chef::Provider::Service::Upstart
510 subscribes :start, "template[/etc/modules]"
514 provider Chef::Provider::Service::Upstart
516 subscribes :start, "template[/etc/modules]"
520 if node[:hardware][:watchdog]
523 template "/etc/default/watchdog" do
524 source "watchdog.erb"
528 variables :module => node[:hardware][:watchdog]
531 service "watchdog" do
532 action [:enable, :start]
536 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
539 execute "/etc/sensors.d/chef.conf" do
541 command "/usr/bin/sensors -s"
546 template "/etc/sensors.d/chef.conf" do
547 source "sensors.conf.erb"
551 notifies :run, "execute[/etc/sensors.d/chef.conf]"