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")
66 when "TYAN Computer Corporation"
70 when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW", "SYS-2028U-TN24R4T+"
79 # Remove legacy HP G4 support which breaks modern hp-health 10.4
80 if manufacturer == "HP"
81 file "/opt/hp/hp-health/bin/hpasmd" do
84 file "/usr/lib/libhpasmintrfc.so.3.0" do
88 file "/usr/lib/libhpasmintrfc.so.3" do
92 file "/usr/lib/libhpasmintrfc.so" do
96 directory "/opt/hp/hp-legacy" do
102 units.sort.uniq.each do |unit|
103 if node[:lsb][:release].to_f >= 16.04
104 service "serial-getty@ttyS#{unit}" do
105 action [:enable, :start]
108 file "/etc/init/ttySttyS#{unit}.conf" do
112 template "/etc/init/ttyS#{unit}.conf" do
113 source "tty.conf.erb"
117 variables :unit => unit
120 service "ttyS#{unit}" do
121 provider Chef::Provider::Service::Upstart
122 action [:enable, :start]
123 supports :status => true, :restart => true, :reload => false
124 subscribes :restart, "template[/etc/init/ttyS#{unit}.conf]"
129 # if we need a different / special kernel version to make the hardware
130 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
131 # ensure that we have the package installed. the grub template will
132 # make sure that this is the default on boot.
133 if node[:hardware][:grub][:kernel]
134 kernel_version = node[:hardware][:grub][:kernel]
136 package "linux-image-#{kernel_version}-generic"
137 package "linux-image-extra-#{kernel_version}-generic"
138 package "linux-headers-#{kernel_version}-generic"
140 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
141 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
142 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
147 if File.exist?("/etc/default/grub")
148 execute "update-grub" do
150 command "/usr/sbin/update-grub"
153 template "/etc/default/grub" do
158 variables :units => units, :entry => grub_entry
159 notifies :run, "execute[update-grub]"
163 execute "update-initramfs" do
165 command "update-initramfs -u -k all"
170 template "/etc/initramfs-tools/conf.d/mdadm" do
171 source "initramfs-mdadm.erb"
175 notifies :run, "execute[update-initramfs]"
180 action [:enable, :start]
183 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]"
207 node[:kernel][:modules].each_key do |modname|
210 tools_packages << "hpssacli"
211 status_packages["cciss-vol-status"] ||= []
213 tools_packages << "hpssacli"
214 status_packages["cciss-vol-status"] ||= []
216 tools_packages << "lsiutil"
217 # status_packages["mpt-status"] ||= []
218 when "mpt2sas", "mpt3sas"
219 tools_packages << "sas2ircu"
220 status_packages["sas2ircu-status"] ||= []
222 tools_packages << "megactl"
223 status_packages["megaraid-status"] ||= []
225 tools_packages << "megacli"
226 status_packages["megaclisas-status"] ||= []
228 tools_packages << "arcconf"
229 status_packages["aacraid-status"] ||= []
231 tools_packages << "areca"
235 node[:block_device].each do |name, attributes|
236 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
238 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
239 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
241 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
242 status_packages["cciss-vol-status"] |= [File.basename(sg)]
247 %w(hpssacli lsiutil sas2ircu megactl megacli arcconf).each do |tools_package|
248 if tools_packages.include?(tools_package)
249 package tools_package
251 package tools_package do
257 if tools_packages.include?("areca")
262 repository "git://chef.openstreetmap.org/areca.git"
267 directory "/opt/areca" do
273 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
274 if status_packages.include?(status_package)
275 package status_package
277 template "/etc/default/#{status_package}d" do
278 source "raid.default.erb"
282 variables :devices => status_packages[status_package]
285 service "#{status_package}d" do
286 action [:start, :enable]
287 supports :status => false, :restart => true, :reload => false
288 subscribes :restart, "template[/etc/default/#{status_package}d]"
291 package status_package do
295 file "/etc/default/#{status_package}d" do
301 disks = if node[:hardware][:disk]
302 node[:hardware][:disk][:disks]
307 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
309 nvmes = if node[:hardware][:pci]
310 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
315 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
317 if !intel_ssds.empty? || !intel_nvmes.empty?
321 remote_file "#{Chef::Config[:file_cache_path]}/DataCenterTool_3_0_0_Linux.zip" do
322 source "https://downloadmirror.intel.com/23931/eng/DataCenterTool_3_0_0_Linux.zip"
325 execute "unzip-DataCenterTool" do
326 command "unzip DataCenterTool_3_0_0_Linux.zip isdct-3.0.0.400-15.x86_64.rpm"
327 cwd Chef::Config[:file_cache_path]
330 not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct-3.0.0.400-15.x86_64.rpm") }
333 execute "alien-isdct" do
334 command "alien --to-deb isdct-3.0.0.400-15.x86_64.rpm"
335 cwd Chef::Config[:file_cache_path]
338 not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct_3.0.0.400-16_amd64.deb") }
341 dpkg_package "isdct" do
342 source "#{Chef::Config[:file_cache_path]}/isdct_3.0.0.400-16_amd64.deb"
346 disks = disks.map do |disk|
347 next if disk[:state] == "spun_down"
349 if disk[:smart_device]
350 controller = node[:hardware][:disk][:controllers][disk[:controller]]
351 device = controller[:device].sub("/dev/", "")
352 smart = disk[:smart_device]
354 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
355 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
356 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
357 elsif smart =~ /^.*,(\d+)$/
358 munin = "#{device}-#{Regexp.last_match(1)}"
359 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
360 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
363 device = disk[:device].sub("/dev/", "")
373 :hddtemp => munin.tr("-:", "_")
377 smartd_service = if node[:lsb][:release].to_f >= 16.04
383 disks = disks.compact
386 package "smartmontools"
388 template "/usr/local/bin/smartd-mailer" do
389 source "smartd-mailer.erb"
395 template "/etc/smartd.conf" do
396 source "smartd.conf.erb"
400 variables :disks => disks
403 template "/etc/default/smartmontools" do
404 source "smartmontools.erb"
410 service smartd_service do
411 action [:enable, :start]
412 subscribes :reload, "template[/etc/smartd.conf]"
413 subscribes :restart, "template[/etc/default/smartmontools]"
416 # Don't try and do munin monitoring of disks behind
417 # an Areca controller as they only allow one thing to
418 # talk to the controller at a time and smartd will
419 # throw errors if it clashes with munin
420 disks = disks.reject { |disk| disk[:smart] && disk[:smart].start_with?("areca,") }
423 munin_plugin "smart_#{disk[:munin]}" do
425 conf "munin.smart.erb"
426 conf_variables :disk => disk
430 service smartd_service do
431 action [:stop, :disable]
436 munin_plugin "hddtemp_smartctl" do
437 conf "munin.hddtemp.erb"
438 conf_variables :disks => disks
441 munin_plugin "hddtemp_smartctl" do
443 conf "munin.hddtemp.erb"
447 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
448 disks.map { |d| "smart_#{d[:munin]}" }
450 plugins.each do |plugin|
451 munin_plugin plugin do
456 if File.exist?("/etc/mdadm/mdadm.conf")
457 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
458 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
463 file "/etc/mdadm/mdadm.conf" do
472 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
476 template "/etc/modules" do
483 if node[:lsb][:release].to_f <= 12.10
484 service "module-init-tools" do
485 provider Chef::Provider::Service::Upstart
487 subscribes :start, "template[/etc/modules]"
491 if node[:lsb][:release].to_f >= 15.10
492 provider Chef::Provider::Service::Systemd
494 provider Chef::Provider::Service::Upstart
497 subscribes :start, "template[/etc/modules]"
501 if node[:hardware][:watchdog]
504 template "/etc/default/watchdog" do
505 source "watchdog.erb"
509 variables :module => node[:hardware][:watchdog]
512 service "watchdog" do
513 action [:enable, :start]
517 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
520 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
521 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
522 chip = format("coretemp-isa-%04d", cpu)
524 temps = if File.exist?("#{coretemp}/name")
525 Dir.glob("#{coretemp}/temp*_input").map do |temp|
526 File.basename(temp).sub("temp", "").sub("_input", "").to_i
529 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
530 File.basename(temp).sub("temp", "").sub("_input", "").to_i
535 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
539 temps.each_with_index do |temp, index|
540 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
544 execute "/etc/sensors.d/chef.conf" do
546 command "/usr/bin/sensors -s"
551 template "/etc/sensors.d/chef.conf" do
552 source "sensors.conf.erb"
556 notifies :run, "execute[/etc/sensors.d/chef.conf]"