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 if node[:hardware][:grub][:kernel]
128 kernel_version = node[:hardware][:grub][:kernel]
130 package "linux-image-#{kernel_version}-generic"
131 package "linux-image-extra-#{kernel_version}-generic"
132 package "linux-headers-#{kernel_version}-generic"
134 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
135 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
136 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
141 if File.exist?("/etc/default/grub")
142 execute "update-grub" do
144 command "/usr/sbin/update-grub"
147 template "/etc/default/grub" do
152 variables :unit => unit, :speed => speed, :entry => grub_entry
153 notifies :run, "execute[update-grub]"
157 execute "update-initramfs" do
159 command "update-initramfs -u -k all"
164 template "/etc/initramfs-tools/conf.d/mdadm" do
165 source "initramfs-mdadm.erb"
169 notifies :run, "execute[update-initramfs]"
174 action [:enable, :start]
177 if node[:kernel][:modules].include?("ipmi_si")
181 if node[:lsb][:release].to_f >= 12.10
184 template "/etc/default/irqbalance" do
185 source "irqbalance.erb"
191 service "irqbalance" do
192 action [:start, :enable]
193 supports :status => false, :restart => true, :reload => false
194 subscribes :restart, "template[/etc/default/irqbalance]"
201 node[:kernel][:modules].each_key do |modname|
204 tools_packages << "hpacucli"
205 status_packages["cciss-vol-status"] ||= []
207 tools_packages << "hpacucli"
208 status_packages["cciss-vol-status"] ||= []
210 tools_packages << "lsiutil"
211 # status_packages["mpt-status"] ||= []
212 when "mpt2sas", "mpt3sas"
213 tools_packages << "sas2ircu"
214 status_packages["sas2ircu-status"] ||= []
216 tools_packages << "megactl"
217 status_packages["megaraid-status"] ||= []
219 tools_packages << "megacli"
220 status_packages["megaclisas-status"] ||= []
222 tools_packages << "arcconf"
223 status_packages["aacraid-status"] ||= []
225 tools_packages << "areca"
229 node[:block_device].each do |name, attributes|
230 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
232 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
233 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
235 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
236 status_packages["cciss-vol-status"] |= [File.basename(sg)]
241 %w(hpacucli lsiutil sas2ircu megactl megacli arcconf).each do |tools_package|
242 if tools_packages.include?(tools_package)
243 package tools_package
245 package tools_package do
251 if tools_packages.include?("areca")
256 repository "git://chef.openstreetmap.org/areca.git"
261 directory "/opt/areca" do
267 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
268 if status_packages.include?(status_package)
269 package status_package
271 template "/etc/default/#{status_package}d" do
272 source "raid.default.erb"
276 variables :devices => status_packages[status_package]
279 service "#{status_package}d" do
280 action [:start, :enable]
281 supports :status => false, :restart => true, :reload => false
282 subscribes :restart, "template[/etc/default/#{status_package}d]"
285 package status_package do
289 file "/etc/default/#{status_package}d" do
297 node[:block_device].each do |name, attributes|
298 disks << { :device => name } if attributes[:vendor] == "ATA"
301 if status_packages["cciss-vol-status"] && File.exist?("/usr/sbin/cciss_vol_status")
302 status_packages["cciss-vol-status"].each do |device|
303 IO.popen(["cciss_vol_status", "-V", "/dev/#{device}"]).each do |line|
304 disks << { :device => device, :driver => "cciss", :id => Regexp.last_match[1].to_i - 1 } if line =~ / bay ([0-9]+) +HP /
309 if status_packages["megaclisas-status"]
312 Dir.glob("/sys/class/scsi_host/host*") do |host|
313 driver = File.new("#{host}/proc_name").read.chomp
315 next unless driver == "megaraid_sas"
317 bus = host.sub("/sys/class/scsi_host/host", "")
318 device = File.basename(Dir.glob("/sys/bus/scsi/devices/#{bus}:*/scsi_generic/*").first)
320 IO.popen(["megacli", "-PDList", "-a#{controller}", "-NoLog"]).each do |line|
321 disks << { :device => device, :driver => "megaraid", :id => Regexp.last_match[1] } if line =~ /^Device Id: ([0-9]+)$/
323 disks.pop if line =~ /^Firmware state: Hotspare, Spun down$/
330 if tools_packages.include?("lsiutil")
331 Dir.glob("/sys/class/scsi_host/host*") do |host|
332 driver = File.new("#{host}/proc_name").read.chomp
334 next unless driver == "mptsas"
336 bus = host.sub("/sys/class/scsi_host/host", "")
338 Dir.glob("/sys/bus/scsi/devices/#{bus}:0:*/scsi_generic/*").each do |sg|
339 disks << { :device => File.basename(sg) }
344 if status_packages["sas2ircu-status"]
345 Dir.glob("/sys/class/scsi_host/host*") do |host|
346 driver = File.new("#{host}/proc_name").read.chomp
348 next unless driver == "mpt2sas" || driver == "mpt3sas"
350 bus = host.sub("/sys/class/scsi_host/host", "")
352 Dir.glob("/sys/bus/scsi/devices/#{bus}:0:*/scsi_generic/*").each do |sg|
353 next if File.directory?("#{sg}/../../block")
355 disks << { :device => File.basename(sg) }
360 if status_packages["aacraid-status"]
361 Dir.glob("/sys/class/scsi_host/host*") do |host|
362 driver = File.new("#{host}/proc_name").read.chomp
364 next unless driver == "aacraid"
366 bus = host.sub("/sys/class/scsi_host/host", "")
368 Dir.glob("/sys/bus/scsi/devices/#{bus}:1:*/scsi_generic/*").each do |sg|
369 disks << { :device => File.basename(sg) }
374 if tools_packages.include?("areca") && File.exist?("/opt/areca/x86_64/cli64")
375 device = IO.popen(["lsscsi", "-g"]).grep(%r{Areca +RAID controller .*/dev/(sg[0-9]+)}) do
379 IO.popen(["/opt/areca/x86_64/cli64", "disk", "info"]).each do |line|
380 next if line =~ /N\.A\./
382 if line =~ /^ +[0-9]+ +0*([0-9]+) +(?:Slot#|SLOT )0*([0-9]+) +/
383 enc = Regexp.last_match[1]
384 slot = Regexp.last_match[2]
386 disks << { :device => device, :driver => "areca", :id => "#{slot}/#{enc}" }
387 elsif line =~ /^ +([0-9]+) +[0-9]+ +/
388 disks << { :device => device, :driver => "areca", :id => Regexp.last_match[1] }
394 if disk[:device] =~ %r{^cciss/(.*)$}
395 id = File.read("/sys/bus/cciss/devices/#{Regexp.last_match[1]}/unique_id").chomp
397 disk[:munin] = "cciss-3#{id.downcase}"
399 disk[:munin] = disk[:device]
403 disk[:munin] = "#{disk[:munin]}-#{disk[:id].to_s.tr('/', ':')}"
406 disk[:hddtemp] = disk[:munin].tr("-:", "_")
410 package "smartmontools"
412 template "/etc/smartd.conf" do
413 source "smartd.conf.erb"
417 variables :disks => disks
418 notifies :reload, "service[smartmontools]"
421 template "/etc/default/smartmontools" do
422 source "smartmontools.erb"
426 notifies :restart, "service[smartmontools]"
429 service "smartmontools" do
430 action [:enable, :start]
431 supports :status => true, :restart => true, :reload => true
434 # Don't try and do munin monitoring of disks behind
435 # an Areca controller as they only allow one thing to
436 # talk to the controller at a time and smartd will
437 # throw errors if it clashes with munin
438 disks = disks.reject { |disk| disk[:driver] == "areca" }
441 munin_plugin "smart_#{disk[:munin]}" do
443 conf "munin.smart.erb"
444 conf_variables :disk => disk
448 munin_plugin "hddtemp_smartctl" do
449 conf "munin.hddtemp.erb"
450 conf_variables :disks => disks
453 service "smartmontools" do
454 action [:stop, :disable]
457 munin_plugin "hddtemp_smartctl" do
462 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
463 disks.map { |d| "smart_#{d[:munin]}" }
465 plugins.each do |plugin|
466 munin_plugin plugin do
471 if File.exist?("/etc/mdadm/mdadm.conf")
472 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
473 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
478 file "/etc/mdadm/mdadm.conf" do
487 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
491 template "/etc/modules" do
498 if node[:lsb][:release].to_f <= 12.10
499 service "module-init-tools" do
500 provider Chef::Provider::Service::Upstart
502 subscribes :start, "template[/etc/modules]"
506 provider Chef::Provider::Service::Upstart
508 subscribes :start, "template[/etc/modules]"
512 if node[:hardware][:watchdog]
515 template "/etc/default/watchdog" do
516 source "watchdog.erb"
520 variables :module => node[:hardware][:watchdog]
523 service "watchdog" do
524 action [:enable, :start]
528 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
531 execute "/etc/sensors.d/chef.conf" do
533 command "/usr/bin/sensors -s"
538 template "/etc/sensors.d/chef.conf" do
539 source "sensors.conf.erb"
543 notifies :run, "execute[/etc/sensors.d/chef.conf]"