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 package "amd64-microcode" if node[:lsb][:release].to_f >= 14.04
37 if node[:dmi] && node[:dmi][:system]
38 case node[:dmi][:system][:manufacturer]
40 manufacturer = node[:dmi][:base_board][:manufacturer]
41 product = node[:dmi][:base_board][:product_name]
43 manufacturer = node[:dmi][:system][:manufacturer]
44 product = node[:dmi][:system][:product_name]
47 manufacturer = "Unknown"
53 if node[:roles].include?("bytemark") || node[:roles].include?("exonetric")
61 # Downgrade hp-health to 10.0.0.1.3-4. as 10.40-1815.49 has issues with reliable startup
62 package "hp-health" do
64 version "10.0.0.1.3-4."
66 notifies :restart, "service[hp-health]"
69 service "hp-health" do
70 action [:enable, :start]
71 supports :status => true, :restart => true
77 when "TYAN Computer Corporation"
81 when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW", "SYS-2028U-TN24R4T+", "Super Server"
90 # Remove legacy HP G4 support which breaks modern hp-health 10.4
91 if manufacturer == "HP"
92 %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|
98 directory "/opt/hp/hp-legacy" do
104 units.sort.uniq.each do |unit|
105 if node[:lsb][:release].to_f >= 16.04
106 service "serial-getty@ttyS#{unit}" do
107 action [:enable, :start]
110 file "/etc/init/ttySttyS#{unit}.conf" do
114 template "/etc/init/ttyS#{unit}.conf" do
115 source "tty.conf.erb"
119 variables :unit => unit
122 service "ttyS#{unit}" do
123 provider Chef::Provider::Service::Upstart
124 action [:enable, :start]
125 supports :status => true, :restart => true, :reload => false
126 subscribes :restart, "template[/etc/init/ttyS#{unit}.conf]"
131 # if we need a different / special kernel version to make the hardware
132 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
133 # ensure that we have the package installed. the grub template will
134 # make sure that this is the default on boot.
135 if node[:hardware][:grub][:kernel]
136 kernel_version = node[:hardware][:grub][:kernel]
138 package "linux-image-#{kernel_version}-generic"
139 package "linux-image-extra-#{kernel_version}-generic"
140 package "linux-headers-#{kernel_version}-generic"
142 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
143 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
144 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
149 if File.exist?("/etc/default/grub")
150 execute "update-grub" do
152 command "/usr/sbin/update-grub"
155 template "/etc/default/grub" do
160 variables :units => units, :entry => grub_entry
161 notifies :run, "execute[update-grub]"
165 execute "update-initramfs" do
167 command "update-initramfs -u -k all"
172 template "/etc/initramfs-tools/conf.d/mdadm" do
173 source "initramfs-mdadm.erb"
177 notifies :run, "execute[update-initramfs]"
182 action [:enable, :start]
185 package "ipmitool" if node[:kernel][:modules].include?("ipmi_si")
187 if node[:lsb][:release].to_f >= 12.10
190 template "/etc/default/irqbalance" do
191 source "irqbalance.erb"
197 service "irqbalance" do
198 action [:start, :enable]
199 supports :status => false, :restart => true, :reload => false
200 subscribes :restart, "template[/etc/default/irqbalance]"
204 # Link Layer Discovery Protocol Daemon
207 action [:start, :enable]
208 supports :status => true, :restart => true, :reload => true
214 node[:kernel][:modules].each_key do |modname|
217 tools_packages << "hpssacli"
218 status_packages["cciss-vol-status"] ||= []
220 tools_packages << "hpssacli"
221 status_packages["cciss-vol-status"] ||= []
223 tools_packages << "lsiutil"
224 # status_packages["mpt-status"] ||= []
225 when "mpt2sas", "mpt3sas"
226 tools_packages << "sas2ircu"
227 status_packages["sas2ircu-status"] ||= []
229 tools_packages << "megactl"
230 status_packages["megaraid-status"] ||= []
232 tools_packages << "megacli"
233 status_packages["megaclisas-status"] ||= []
235 tools_packages << "arcconf"
236 status_packages["aacraid-status"] ||= []
238 tools_packages << "areca"
242 node[:block_device].each do |name, attributes|
243 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
245 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
246 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
248 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
249 status_packages["cciss-vol-status"] |= [File.basename(sg)]
254 %w(hpssacli lsiutil sas2ircu megactl megacli arcconf).each do |tools_package|
255 if tools_packages.include?(tools_package)
256 package tools_package
258 package tools_package do
264 if tools_packages.include?("areca")
269 repository "git://chef.openstreetmap.org/areca.git"
274 directory "/opt/areca" do
280 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
281 if status_packages.include?(status_package)
282 package status_package
284 template "/etc/default/#{status_package}d" do
285 source "raid.default.erb"
289 variables :devices => status_packages[status_package]
292 service "#{status_package}d" do
293 action [:start, :enable]
294 supports :status => false, :restart => true, :reload => false
295 subscribes :restart, "template[/etc/default/#{status_package}d]"
298 package status_package do
302 file "/etc/default/#{status_package}d" do
308 disks = if node[:hardware][:disk]
309 node[:hardware][:disk][:disks]
314 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
316 nvmes = if node[:hardware][:pci]
317 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
322 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
324 if !intel_ssds.empty? || !intel_nvmes.empty?
328 remote_file "#{Chef::Config[:file_cache_path]}/DataCenterTool_3_0_0_Linux.zip" do
329 source "https://downloadmirror.intel.com/23931/eng/DataCenterTool_3_0_0_Linux.zip"
332 execute "unzip-DataCenterTool" do
333 command "unzip DataCenterTool_3_0_0_Linux.zip isdct-3.0.0.400-15.x86_64.rpm"
334 cwd Chef::Config[:file_cache_path]
337 not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct-3.0.0.400-15.x86_64.rpm") }
340 execute "alien-isdct" do
341 command "alien --to-deb isdct-3.0.0.400-15.x86_64.rpm"
342 cwd Chef::Config[:file_cache_path]
345 not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct_3.0.0.400-16_amd64.deb") }
348 dpkg_package "isdct" do
349 source "#{Chef::Config[:file_cache_path]}/isdct_3.0.0.400-16_amd64.deb"
353 disks = disks.map do |disk|
354 next if disk[:state] == "spun_down"
356 if disk[:smart_device]
357 controller = node[:hardware][:disk][:controllers][disk[:controller]]
358 device = controller[:device].sub("/dev/", "")
359 smart = disk[:smart_device]
361 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
362 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
363 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
364 elsif smart =~ /^.*,(\d+)$/
365 munin = "#{device}-#{Regexp.last_match(1)}"
366 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
367 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
370 device = disk[:device].sub("/dev/", "")
380 :hddtemp => munin.tr("-:", "_")
384 smartd_service = if node[:lsb][:release].to_f >= 16.04
390 disks = disks.compact
393 package "smartmontools"
395 template "/usr/local/bin/smartd-mailer" do
396 source "smartd-mailer.erb"
402 template "/etc/smartd.conf" do
403 source "smartd.conf.erb"
407 variables :disks => disks
410 template "/etc/default/smartmontools" do
411 source "smartmontools.erb"
417 service smartd_service do
418 action [:enable, :start]
419 subscribes :reload, "template[/etc/smartd.conf]"
420 subscribes :restart, "template[/etc/default/smartmontools]"
423 # Don't try and do munin monitoring of disks behind
424 # an Areca controller as they only allow one thing to
425 # talk to the controller at a time and smartd will
426 # throw errors if it clashes with munin
427 disks = disks.reject { |disk| disk[:smart] && disk[:smart].start_with?("areca,") }
430 munin_plugin "smart_#{disk[:munin]}" do
432 conf "munin.smart.erb"
433 conf_variables :disk => disk
437 service smartd_service do
438 action [:stop, :disable]
443 munin_plugin "hddtemp_smartctl" do
444 conf "munin.hddtemp.erb"
445 conf_variables :disks => disks
448 munin_plugin "hddtemp_smartctl" do
450 conf "munin.hddtemp.erb"
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 if node[:lsb][:release].to_f >= 15.10
499 provider Chef::Provider::Service::Systemd
501 provider Chef::Provider::Service::Upstart
504 subscribes :start, "template[/etc/modules]"
508 if node[:hardware][:watchdog]
511 template "/etc/default/watchdog" do
512 source "watchdog.erb"
516 variables :module => node[:hardware][:watchdog]
519 service "watchdog" do
520 action [:enable, :start]
524 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
527 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
528 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
529 chip = format("coretemp-isa-%04d", cpu)
531 temps = if File.exist?("#{coretemp}/name")
532 Dir.glob("#{coretemp}/temp*_input").map do |temp|
533 File.basename(temp).sub("temp", "").sub("_input", "").to_i
536 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
537 File.basename(temp).sub("temp", "").sub("_input", "").to_i
542 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
546 temps.each_with_index do |temp, index|
547 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
551 execute "/etc/sensors.d/chef.conf" do
553 command "/usr/bin/sensors -s"
558 template "/etc/sensors.d/chef.conf" do
559 source "sensors.conf.erb"
563 notifies :run, "execute[/etc/sensors.d/chef.conf]"