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 ohai_plugin "hardware" do
24 template "ohai.rb.erb"
27 case node[:cpu][:"0"][:vendor_id]
29 package "intel-microcode"
32 case node[:cpu][:"0"][:vendor_id]
34 if node[:lsb][:release].to_f >= 14.04
35 package "amd64-microcode"
39 if node[:dmi] && node[:dmi][:system]
40 case node[:dmi][:system][:manufacturer]
42 manufacturer = node[:dmi][:base_board][:manufacturer]
43 product = node[:dmi][:base_board][:product_name]
45 manufacturer = node[:dmi][:system][:manufacturer]
46 product = node[:dmi][:system][:product_name]
49 manufacturer = "Unknown"
55 if node[:roles].include?("bytemark") || node[:roles].include?("exonetric")
63 # Downgrade hp-health to 10.0.0.1.3-4. as 10.40-1815.49 has issues with reliable startup
64 package "hp-health" do
66 version "10.0.0.1.3-4."
67 notifies :restart, "service[hp-health]"
70 service "hp-health" do
71 action [:enable, :start]
72 supports :status => true, :restart => true, :reload => true
78 when "TYAN Computer Corporation"
82 when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW", "SYS-2028U-TN24R4T+"
91 # Remove legacy HP G4 support which breaks modern hp-health 10.4
92 if manufacturer == "HP"
93 %w(/opt/hp/hp-health/bin/hpasmd /usr/lib/libhpasmintrfc.so.3.0 %/usr/lib/libhpasmintrfc.so.3 /usr/lib/libhpasmintrfc.so).each do |filename|
99 directory "/opt/hp/hp-legacy" do
105 units.sort.uniq.each do |unit|
106 if node[:lsb][:release].to_f >= 16.04
107 service "serial-getty@ttyS#{unit}" do
108 action [:enable, :start]
111 file "/etc/init/ttySttyS#{unit}.conf" do
115 template "/etc/init/ttyS#{unit}.conf" do
116 source "tty.conf.erb"
120 variables :unit => unit
123 service "ttyS#{unit}" do
124 provider Chef::Provider::Service::Upstart
125 action [:enable, :start]
126 supports :status => true, :restart => true, :reload => false
127 subscribes :restart, "template[/etc/init/ttyS#{unit}.conf]"
132 # if we need a different / special kernel version to make the hardware
133 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
134 # ensure that we have the package installed. the grub template will
135 # make sure that this is the default on boot.
136 if node[:hardware][:grub][:kernel]
137 kernel_version = node[:hardware][:grub][:kernel]
139 package "linux-image-#{kernel_version}-generic"
140 package "linux-image-extra-#{kernel_version}-generic"
141 package "linux-headers-#{kernel_version}-generic"
143 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
144 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
145 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
150 if File.exist?("/etc/default/grub")
151 execute "update-grub" do
153 command "/usr/sbin/update-grub"
156 template "/etc/default/grub" do
161 variables :units => units, :entry => grub_entry
162 notifies :run, "execute[update-grub]"
166 execute "update-initramfs" do
168 command "update-initramfs -u -k all"
173 template "/etc/initramfs-tools/conf.d/mdadm" do
174 source "initramfs-mdadm.erb"
178 notifies :run, "execute[update-initramfs]"
183 action [:enable, :start]
186 if node[:kernel][:modules].include?("ipmi_si")
190 if node[:lsb][:release].to_f >= 12.10
193 template "/etc/default/irqbalance" do
194 source "irqbalance.erb"
200 service "irqbalance" do
201 action [:start, :enable]
202 supports :status => false, :restart => true, :reload => false
203 subscribes :restart, "template[/etc/default/irqbalance]"
210 node[:kernel][:modules].each_key do |modname|
213 tools_packages << "hpssacli"
214 status_packages["cciss-vol-status"] ||= []
216 tools_packages << "hpssacli"
217 status_packages["cciss-vol-status"] ||= []
219 tools_packages << "lsiutil"
220 # status_packages["mpt-status"] ||= []
221 when "mpt2sas", "mpt3sas"
222 tools_packages << "sas2ircu"
223 status_packages["sas2ircu-status"] ||= []
225 tools_packages << "megactl"
226 status_packages["megaraid-status"] ||= []
228 tools_packages << "megacli"
229 status_packages["megaclisas-status"] ||= []
231 tools_packages << "arcconf"
232 status_packages["aacraid-status"] ||= []
234 tools_packages << "areca"
238 node[:block_device].each do |name, attributes|
239 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
241 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
242 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
244 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
245 status_packages["cciss-vol-status"] |= [File.basename(sg)]
250 %w(hpssacli lsiutil sas2ircu megactl megacli arcconf).each do |tools_package|
251 if tools_packages.include?(tools_package)
252 package tools_package
254 package tools_package do
260 if tools_packages.include?("areca")
265 repository "git://chef.openstreetmap.org/areca.git"
270 directory "/opt/areca" do
276 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
277 if status_packages.include?(status_package)
278 package status_package
280 template "/etc/default/#{status_package}d" do
281 source "raid.default.erb"
285 variables :devices => status_packages[status_package]
288 service "#{status_package}d" do
289 action [:start, :enable]
290 supports :status => false, :restart => true, :reload => false
291 subscribes :restart, "template[/etc/default/#{status_package}d]"
294 package status_package do
298 file "/etc/default/#{status_package}d" do
304 disks = if node[:hardware][:disk]
305 node[:hardware][:disk][:disks]
310 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
312 nvmes = if node[:hardware][:pci]
313 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
318 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
320 if !intel_ssds.empty? || !intel_nvmes.empty?
324 remote_file "#{Chef::Config[:file_cache_path]}/DataCenterTool_3_0_0_Linux.zip" do
325 source "https://downloadmirror.intel.com/23931/eng/DataCenterTool_3_0_0_Linux.zip"
328 execute "unzip-DataCenterTool" do
329 command "unzip DataCenterTool_3_0_0_Linux.zip isdct-3.0.0.400-15.x86_64.rpm"
330 cwd Chef::Config[:file_cache_path]
333 not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct-3.0.0.400-15.x86_64.rpm") }
336 execute "alien-isdct" do
337 command "alien --to-deb isdct-3.0.0.400-15.x86_64.rpm"
338 cwd Chef::Config[:file_cache_path]
341 not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct_3.0.0.400-16_amd64.deb") }
344 dpkg_package "isdct" do
345 source "#{Chef::Config[:file_cache_path]}/isdct_3.0.0.400-16_amd64.deb"
349 disks = disks.map do |disk|
350 next if disk[:state] == "spun_down"
352 if disk[:smart_device]
353 controller = node[:hardware][:disk][:controllers][disk[:controller]]
354 device = controller[:device].sub("/dev/", "")
355 smart = disk[:smart_device]
357 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
358 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
359 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
360 elsif smart =~ /^.*,(\d+)$/
361 munin = "#{device}-#{Regexp.last_match(1)}"
362 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
363 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
366 device = disk[:device].sub("/dev/", "")
376 :hddtemp => munin.tr("-:", "_")
380 smartd_service = if node[:lsb][:release].to_f >= 16.04
386 disks = disks.compact
389 package "smartmontools"
391 template "/usr/local/bin/smartd-mailer" do
392 source "smartd-mailer.erb"
398 template "/etc/smartd.conf" do
399 source "smartd.conf.erb"
403 variables :disks => disks
406 template "/etc/default/smartmontools" do
407 source "smartmontools.erb"
413 service smartd_service do
414 action [:enable, :start]
415 subscribes :reload, "template[/etc/smartd.conf]"
416 subscribes :restart, "template[/etc/default/smartmontools]"
419 # Don't try and do munin monitoring of disks behind
420 # an Areca controller as they only allow one thing to
421 # talk to the controller at a time and smartd will
422 # throw errors if it clashes with munin
423 disks = disks.reject { |disk| disk[:smart] && disk[:smart].start_with?("areca,") }
426 munin_plugin "smart_#{disk[:munin]}" do
428 conf "munin.smart.erb"
429 conf_variables :disk => disk
433 service smartd_service do
434 action [:stop, :disable]
439 munin_plugin "hddtemp_smartctl" do
440 conf "munin.hddtemp.erb"
441 conf_variables :disks => disks
444 munin_plugin "hddtemp_smartctl" do
446 conf "munin.hddtemp.erb"
450 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
451 disks.map { |d| "smart_#{d[:munin]}" }
453 plugins.each do |plugin|
454 munin_plugin plugin do
459 if File.exist?("/etc/mdadm/mdadm.conf")
460 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
461 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
466 file "/etc/mdadm/mdadm.conf" do
475 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
479 template "/etc/modules" do
486 if node[:lsb][:release].to_f <= 12.10
487 service "module-init-tools" do
488 provider Chef::Provider::Service::Upstart
490 subscribes :start, "template[/etc/modules]"
494 if node[:lsb][:release].to_f >= 15.10
495 provider Chef::Provider::Service::Systemd
497 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 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
524 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
525 chip = format("coretemp-isa-%04d", cpu)
527 temps = if File.exist?("#{coretemp}/name")
528 Dir.glob("#{coretemp}/temp*_input").map do |temp|
529 File.basename(temp).sub("temp", "").sub("_input", "").to_i
532 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
533 File.basename(temp).sub("temp", "").sub("_input", "").to_i
538 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
542 temps.each_with_index do |temp, index|
543 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
547 execute "/etc/sensors.d/chef.conf" do
549 command "/usr/bin/sensors -s"
554 template "/etc/sensors.d/chef.conf" do
555 source "sensors.conf.erb"
559 notifies :run, "execute[/etc/sensors.d/chef.conf]"