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"
31 package "amd64-microcode"
34 if node[:dmi] && node[:dmi][:system]
35 case node[:dmi][:system][:manufacturer]
37 manufacturer = node[:dmi][:base_board][:manufacturer]
38 product = node[:dmi][:base_board][:product_name]
40 manufacturer = node[:dmi][:system][:manufacturer]
41 product = node[:dmi][:system][:product_name]
44 manufacturer = "Unknown"
50 if node[:roles].include?("bytemark") || node[:roles].include?("exonetric")
58 package "hp-health" do
60 notifies :restart, "service[hp-health]"
63 service "hp-health" do
64 action [:enable, :start]
65 supports :status => true, :restart => true
71 when "TYAN Computer Corporation"
75 when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW", "SYS-2028U-TN24R4T+", "Super Server"
84 # Remove legacy HP G4 support which breaks modern hp-health 10.4
85 if manufacturer == "HP"
86 %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|
92 directory "/opt/hp/hp-legacy" do
98 units.sort.uniq.each do |unit|
99 if node[:lsb][:release].to_f >= 16.04
100 service "serial-getty@ttyS#{unit}" do
101 action [:enable, :start]
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
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]"
125 # if we need a different / special kernel version to make the hardware
126 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
127 # ensure that we have the package installed. the grub template will
128 # make sure that this is the default on boot.
129 if node[:hardware][:grub][:kernel]
130 kernel_version = node[:hardware][:grub][:kernel]
132 package "linux-image-#{kernel_version}-generic"
133 package "linux-image-extra-#{kernel_version}-generic"
134 package "linux-headers-#{kernel_version}-generic"
136 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
137 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
138 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
143 if File.exist?("/etc/default/grub")
144 execute "update-grub" do
146 command "/usr/sbin/update-grub"
149 template "/etc/default/grub" do
154 variables :units => units, :entry => grub_entry
155 notifies :run, "execute[update-grub]"
159 execute "update-initramfs" do
161 command "update-initramfs -u -k all"
166 template "/etc/initramfs-tools/conf.d/mdadm" do
167 source "initramfs-mdadm.erb"
171 notifies :run, "execute[update-initramfs]"
176 action [:enable, :start]
179 package "ipmitool" if node[:kernel][:modules].include?("ipmi_si")
183 template "/etc/default/irqbalance" do
184 source "irqbalance.erb"
190 service "irqbalance" do
191 action [:start, :enable]
192 supports :status => false, :restart => true, :reload => false
193 subscribes :restart, "template[/etc/default/irqbalance]"
196 # Link Layer Discovery Protocol Daemon
199 action [:start, :enable]
200 supports :status => true, :restart => true, :reload => true
206 node[:kernel][:modules].each_key do |modname|
209 tools_packages << "hpssacli"
210 status_packages["cciss-vol-status"] ||= []
212 tools_packages << "hpssacli"
213 status_packages["cciss-vol-status"] ||= []
215 tools_packages << "lsiutil"
216 status_packages["mpt-status"] ||= []
217 when "mpt2sas", "mpt3sas"
218 tools_packages << "sas2ircu"
219 status_packages["sas2ircu-status"] ||= []
221 tools_packages << "megactl"
222 status_packages["megaraid-status"] ||= []
224 tools_packages << "megacli"
225 status_packages["megaclisas-status"] ||= []
227 tools_packages << "arcconf"
228 status_packages["aacraid-status"] ||= []
230 tools_packages << "areca"
234 node[:block_device].each do |name, attributes|
235 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
237 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
238 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
240 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
241 status_packages["cciss-vol-status"] |= [File.basename(sg)]
246 %w[hpssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
247 if tools_packages.include?(tools_package)
248 package tools_package
250 package tools_package do
256 if tools_packages.include?("areca")
261 repository "git://chef.openstreetmap.org/areca.git"
266 directory "/opt/areca" do
272 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
273 if status_packages.include?(status_package)
274 package status_package
276 template "/etc/default/#{status_package}d" do
277 source "raid.default.erb"
281 variables :devices => status_packages[status_package]
284 service "#{status_package}d" do
285 action [:start, :enable]
286 supports :status => false, :restart => true, :reload => false
287 subscribes :restart, "template[/etc/default/#{status_package}d]"
290 package status_package do
294 file "/etc/default/#{status_package}d" do
300 disks = if node[:hardware][:disk]
301 node[:hardware][:disk][:disks]
306 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
308 nvmes = if node[:hardware][:pci]
309 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
314 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
316 if !intel_ssds.empty? || !intel_nvmes.empty?
319 remote_file "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_3.0.7_Linux.zip" do
320 source "https://downloadmirror.intel.com/27144/eng/Intel_SSD_Data_Center_Tool_3.0.7_Linux.zip"
323 execute "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_3.0.7_Linux.zip" do
324 command "unzip Intel_SSD_Data_Center_Tool_3.0.7_Linux.zip isdct_3.0.7.401-17_amd64.deb"
325 cwd Chef::Config[:file_cache_path]
328 not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct_3.0.7.401-17_amd64.deb") }
331 dpkg_package "isdct" do
332 version "3.0.7.401-17"
333 source "#{Chef::Config[:file_cache_path]}/isdct_3.0.7.401-17_amd64.deb"
337 disks = disks.map do |disk|
338 next if disk[:state] == "spun_down"
340 if disk[:smart_device]
341 controller = node[:hardware][:disk][:controllers][disk[:controller]]
342 device = controller[:device].sub("/dev/", "")
343 smart = disk[:smart_device]
345 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
346 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
347 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
348 elsif smart =~ /^.*,(\d+)$/
349 munin = "#{device}-#{Regexp.last_match(1)}"
350 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
351 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
354 device = disk[:device].sub("/dev/", "")
364 :hddtemp => munin.tr("-:", "_")
368 smartd_service = if node[:lsb][:release].to_f >= 16.04
374 disks = disks.compact
376 if disks.count.positive?
377 package "smartmontools"
379 template "/usr/local/bin/smartd-mailer" do
380 source "smartd-mailer.erb"
386 template "/etc/smartd.conf" do
387 source "smartd.conf.erb"
391 variables :disks => disks
394 template "/etc/default/smartmontools" do
395 source "smartmontools.erb"
401 service smartd_service do
402 action [:enable, :start]
403 subscribes :reload, "template[/etc/smartd.conf]"
404 subscribes :restart, "template[/etc/default/smartmontools]"
407 # Don't try and do munin monitoring of disks behind
408 # an Areca controller as they only allow one thing to
409 # talk to the controller at a time and smartd will
410 # throw errors if it clashes with munin
411 disks = disks.reject { |disk| disk[:smart] && disk[:smart].start_with?("areca,") }
414 munin_plugin "smart_#{disk[:munin]}" do
416 conf "munin.smart.erb"
417 conf_variables :disk => disk
421 service smartd_service do
422 action [:stop, :disable]
426 if disks.count.positive?
427 munin_plugin "hddtemp_smartctl" do
428 conf "munin.hddtemp.erb"
429 conf_variables :disks => disks
432 munin_plugin "hddtemp_smartctl" do
434 conf "munin.hddtemp.erb"
438 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
439 disks.map { |d| "smart_#{d[:munin]}" }
441 plugins.each do |plugin|
442 munin_plugin plugin do
447 if File.exist?("/etc/mdadm/mdadm.conf")
448 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
449 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
454 file "/etc/mdadm/mdadm.conf" do
463 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
467 template "/etc/modules" do
476 subscribes :start, "template[/etc/modules]"
479 if node[:hardware][:watchdog]
482 template "/etc/default/watchdog" do
483 source "watchdog.erb"
487 variables :module => node[:hardware][:watchdog]
490 service "watchdog" do
491 action [:enable, :start]
495 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
498 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
499 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
500 chip = format("coretemp-isa-%04d", cpu)
502 temps = if File.exist?("#{coretemp}/name")
503 Dir.glob("#{coretemp}/temp*_input").map do |temp|
504 File.basename(temp).sub("temp", "").sub("_input", "").to_i
507 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
508 File.basename(temp).sub("temp", "").sub("_input", "").to_i
513 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
517 temps.each_with_index do |temp, index|
518 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
522 execute "/etc/sensors.d/chef.conf" do
524 command "/usr/bin/sensors -s"
529 template "/etc/sensors.d/chef.conf" do
530 source "sensors.conf.erb"
534 notifies :run, "execute[/etc/sensors.d/chef.conf]"