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
203 # mcelog Daemon to log / alert on machine check events
206 action [:start, :enable]
207 supports :status => true, :restart => true, :reload => false
213 node[:kernel][:modules].each_key do |modname|
216 tools_packages << "ssacli"
217 status_packages["cciss-vol-status"] ||= []
219 tools_packages << "ssacli"
220 status_packages["cciss-vol-status"] ||= []
222 tools_packages << "lsiutil"
223 status_packages["mpt-status"] ||= []
224 when "mpt2sas", "mpt3sas"
225 tools_packages << "sas2ircu"
226 status_packages["sas2ircu-status"] ||= []
228 tools_packages << "megactl"
229 status_packages["megaraid-status"] ||= []
231 tools_packages << "megacli"
232 status_packages["megaclisas-status"] ||= []
234 tools_packages << "arcconf"
235 status_packages["aacraid-status"] ||= []
237 tools_packages << "areca"
241 node[:block_device].each do |name, attributes|
242 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
244 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
245 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
247 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
248 status_packages["cciss-vol-status"] |= [File.basename(sg)]
253 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
254 if tools_packages.include?(tools_package)
255 package tools_package
257 package tools_package do
263 if tools_packages.include?("areca")
268 repository "git://chef.openstreetmap.org/areca.git"
273 directory "/opt/areca" do
279 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
280 if status_packages.include?(status_package)
281 package status_package
283 template "/etc/default/#{status_package}d" do
284 source "raid.default.erb"
288 variables :devices => status_packages[status_package]
291 service "#{status_package}d" do
292 action [:start, :enable]
293 supports :status => false, :restart => true, :reload => false
294 subscribes :restart, "template[/etc/default/#{status_package}d]"
297 package status_package do
301 file "/etc/default/#{status_package}d" do
307 disks = if node[:hardware][:disk]
308 node[:hardware][:disk][:disks]
313 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
315 nvmes = if node[:hardware][:pci]
316 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
321 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
323 if !intel_ssds.empty? || !intel_nvmes.empty?
326 remote_file "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_3.0.7_Linux.zip" do
327 source "https://downloadmirror.intel.com/27144/eng/Intel_SSD_Data_Center_Tool_3.0.7_Linux.zip"
330 execute "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_3.0.7_Linux.zip" do
331 command "unzip Intel_SSD_Data_Center_Tool_3.0.7_Linux.zip isdct_3.0.7.401-17_amd64.deb"
332 cwd Chef::Config[:file_cache_path]
335 not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct_3.0.7.401-17_amd64.deb") }
338 dpkg_package "isdct" do
339 version "3.0.7.401-17"
340 source "#{Chef::Config[:file_cache_path]}/isdct_3.0.7.401-17_amd64.deb"
344 disks = disks.map do |disk|
345 next if disk[:state] == "spun_down"
347 if disk[:smart_device]
348 controller = node[:hardware][:disk][:controllers][disk[:controller]]
349 device = controller[:device].sub("/dev/", "")
350 smart = disk[:smart_device]
352 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
353 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
354 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
355 elsif smart =~ /^.*,(\d+)$/
356 munin = "#{device}-#{Regexp.last_match(1)}"
357 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
358 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
361 device = disk[:device].sub("/dev/", "")
371 :hddtemp => munin.tr("-:", "_")
375 smartd_service = if node[:lsb][:release].to_f >= 16.04
381 disks = disks.compact
383 if disks.count.positive?
384 package "smartmontools"
386 template "/usr/local/bin/smartd-mailer" do
387 source "smartd-mailer.erb"
393 template "/etc/smartd.conf" do
394 source "smartd.conf.erb"
398 variables :disks => disks
401 template "/etc/default/smartmontools" do
402 source "smartmontools.erb"
408 service smartd_service do
409 action [:enable, :start]
410 subscribes :reload, "template[/etc/smartd.conf]"
411 subscribes :restart, "template[/etc/default/smartmontools]"
414 # Don't try and do munin monitoring of disks behind
415 # an Areca controller as they only allow one thing to
416 # talk to the controller at a time and smartd will
417 # throw errors if it clashes with munin
418 disks = disks.reject { |disk| disk[:smart] && disk[:smart].start_with?("areca,") }
421 munin_plugin "smart_#{disk[:munin]}" do
423 conf "munin.smart.erb"
424 conf_variables :disk => disk
428 service smartd_service do
429 action [:stop, :disable]
433 if disks.count.positive?
434 munin_plugin "hddtemp_smartctl" do
435 conf "munin.hddtemp.erb"
436 conf_variables :disks => disks
439 munin_plugin "hddtemp_smartctl" do
441 conf "munin.hddtemp.erb"
445 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
446 disks.map { |d| "smart_#{d[:munin]}" }
448 plugins.each do |plugin|
449 munin_plugin plugin do
454 if File.exist?("/etc/mdadm/mdadm.conf")
455 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
456 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
461 file "/etc/mdadm/mdadm.conf" do
470 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
474 template "/etc/modules" do
483 subscribes :start, "template[/etc/modules]"
486 if node[:hardware][:watchdog]
489 template "/etc/default/watchdog" do
490 source "watchdog.erb"
494 variables :module => node[:hardware][:watchdog]
497 service "watchdog" do
498 action [:enable, :start]
502 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
505 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
506 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
507 chip = format("coretemp-isa-%04d", cpu)
509 temps = if File.exist?("#{coretemp}/name")
510 Dir.glob("#{coretemp}/temp*_input").map do |temp|
511 File.basename(temp).sub("temp", "").sub("_input", "").to_i
514 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
515 File.basename(temp).sub("temp", "").sub("_input", "").to_i
520 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
524 temps.each_with_index do |temp, index|
525 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
529 execute "/etc/sensors.d/chef.conf" do
531 command "/usr/bin/sensors -s"
536 template "/etc/sensors.d/chef.conf" do
537 source "sensors.conf.erb"
541 notifies :run, "execute[/etc/sensors.d/chef.conf]"