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 # Downgrade hp-health to 10.0.0.1.3-4. as 10.40-1815.49 has issues with reliable startup
59 package "hp-health" do
61 version "10.0.0.1.3-4."
63 notifies :restart, "service[hp-health]"
66 service "hp-health" do
67 action [:enable, :start]
68 supports :status => true, :restart => true
74 when "TYAN Computer Corporation"
78 when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW", "SYS-2028U-TN24R4T+", "Super Server"
87 # Remove legacy HP G4 support which breaks modern hp-health 10.4
88 if manufacturer == "HP"
89 %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|
95 directory "/opt/hp/hp-legacy" do
101 units.sort.uniq.each do |unit|
102 if node[:lsb][:release].to_f >= 16.04
103 service "serial-getty@ttyS#{unit}" do
104 action [:enable, :start]
107 file "/etc/init/ttySttyS#{unit}.conf" do
111 template "/etc/init/ttyS#{unit}.conf" do
112 source "tty.conf.erb"
116 variables :unit => unit
119 service "ttyS#{unit}" do
120 provider Chef::Provider::Service::Upstart
121 action [:enable, :start]
122 supports :status => true, :restart => true, :reload => false
123 subscribes :restart, "template[/etc/init/ttyS#{unit}.conf]"
128 # if we need a different / special kernel version to make the hardware
129 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
130 # ensure that we have the package installed. the grub template will
131 # make sure that this is the default on boot.
132 if node[:hardware][:grub][:kernel]
133 kernel_version = node[:hardware][:grub][:kernel]
135 package "linux-image-#{kernel_version}-generic"
136 package "linux-image-extra-#{kernel_version}-generic"
137 package "linux-headers-#{kernel_version}-generic"
139 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
140 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
141 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
146 if File.exist?("/etc/default/grub")
147 execute "update-grub" do
149 command "/usr/sbin/update-grub"
152 template "/etc/default/grub" do
157 variables :units => units, :entry => grub_entry
158 notifies :run, "execute[update-grub]"
162 execute "update-initramfs" do
164 command "update-initramfs -u -k all"
169 template "/etc/initramfs-tools/conf.d/mdadm" do
170 source "initramfs-mdadm.erb"
174 notifies :run, "execute[update-initramfs]"
179 action [:enable, :start]
182 package "ipmitool" if node[:kernel][:modules].include?("ipmi_si")
186 template "/etc/default/irqbalance" do
187 source "irqbalance.erb"
193 service "irqbalance" do
194 action [:start, :enable]
195 supports :status => false, :restart => true, :reload => false
196 subscribes :restart, "template[/etc/default/irqbalance]"
199 # Link Layer Discovery Protocol Daemon
202 action [:start, :enable]
203 supports :status => true, :restart => true, :reload => true
209 node[:kernel][:modules].each_key do |modname|
212 tools_packages << "hpssacli"
213 status_packages["cciss-vol-status"] ||= []
215 tools_packages << "hpssacli"
216 status_packages["cciss-vol-status"] ||= []
218 tools_packages << "lsiutil"
219 status_packages["mpt-status"] ||= []
220 when "mpt2sas", "mpt3sas"
221 tools_packages << "sas2ircu"
222 status_packages["sas2ircu-status"] ||= []
224 tools_packages << "megactl"
225 status_packages["megaraid-status"] ||= []
227 tools_packages << "megacli"
228 status_packages["megaclisas-status"] ||= []
230 tools_packages << "arcconf"
231 status_packages["aacraid-status"] ||= []
233 tools_packages << "areca"
237 node[:block_device].each do |name, attributes|
238 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
240 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
241 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
243 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
244 status_packages["cciss-vol-status"] |= [File.basename(sg)]
249 %w[hpssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
250 if tools_packages.include?(tools_package)
251 package tools_package
253 package tools_package do
259 if tools_packages.include?("areca")
264 repository "git://chef.openstreetmap.org/areca.git"
269 directory "/opt/areca" do
275 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
276 if status_packages.include?(status_package)
277 package status_package
279 template "/etc/default/#{status_package}d" do
280 source "raid.default.erb"
284 variables :devices => status_packages[status_package]
287 service "#{status_package}d" do
288 action [:start, :enable]
289 supports :status => false, :restart => true, :reload => false
290 subscribes :restart, "template[/etc/default/#{status_package}d]"
293 package status_package do
297 file "/etc/default/#{status_package}d" do
303 disks = if node[:hardware][:disk]
304 node[:hardware][:disk][:disks]
309 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
311 nvmes = if node[:hardware][:pci]
312 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
317 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
319 if !intel_ssds.empty? || !intel_nvmes.empty?
323 remote_file "#{Chef::Config[:file_cache_path]}/DataCenterTool_3_0_0_Linux.zip" do
324 source "https://downloadmirror.intel.com/23931/eng/DataCenterTool_3_0_0_Linux.zip"
327 execute "unzip-DataCenterTool" do
328 command "unzip DataCenterTool_3_0_0_Linux.zip isdct-3.0.0.400-15.x86_64.rpm"
329 cwd Chef::Config[:file_cache_path]
332 not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct-3.0.0.400-15.x86_64.rpm") }
335 execute "alien-isdct" do
336 command "alien --to-deb isdct-3.0.0.400-15.x86_64.rpm"
337 cwd Chef::Config[:file_cache_path]
340 not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct_3.0.0.400-16_amd64.deb") }
343 dpkg_package "isdct" do
344 source "#{Chef::Config[:file_cache_path]}/isdct_3.0.0.400-16_amd64.deb"
348 disks = disks.map do |disk|
349 next if disk[:state] == "spun_down"
351 if disk[:smart_device]
352 controller = node[:hardware][:disk][:controllers][disk[:controller]]
353 device = controller[:device].sub("/dev/", "")
354 smart = disk[:smart_device]
356 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
357 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
358 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
359 elsif smart =~ /^.*,(\d+)$/
360 munin = "#{device}-#{Regexp.last_match(1)}"
361 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
362 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
365 device = disk[:device].sub("/dev/", "")
375 :hddtemp => munin.tr("-:", "_")
379 smartd_service = if node[:lsb][:release].to_f >= 16.04
385 disks = disks.compact
387 if disks.count.positive?
388 package "smartmontools"
390 template "/usr/local/bin/smartd-mailer" do
391 source "smartd-mailer.erb"
397 template "/etc/smartd.conf" do
398 source "smartd.conf.erb"
402 variables :disks => disks
405 template "/etc/default/smartmontools" do
406 source "smartmontools.erb"
412 service smartd_service do
413 action [:enable, :start]
414 subscribes :reload, "template[/etc/smartd.conf]"
415 subscribes :restart, "template[/etc/default/smartmontools]"
418 # Don't try and do munin monitoring of disks behind
419 # an Areca controller as they only allow one thing to
420 # talk to the controller at a time and smartd will
421 # throw errors if it clashes with munin
422 disks = disks.reject { |disk| disk[:smart] && disk[:smart].start_with?("areca,") }
425 munin_plugin "smart_#{disk[:munin]}" do
427 conf "munin.smart.erb"
428 conf_variables :disk => disk
432 service smartd_service do
433 action [:stop, :disable]
437 if disks.count.positive?
438 munin_plugin "hddtemp_smartctl" do
439 conf "munin.hddtemp.erb"
440 conf_variables :disks => disks
443 munin_plugin "hddtemp_smartctl" do
445 conf "munin.hddtemp.erb"
449 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
450 disks.map { |d| "smart_#{d[:munin]}" }
452 plugins.each do |plugin|
453 munin_plugin plugin do
458 if File.exist?("/etc/mdadm/mdadm.conf")
459 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
460 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
465 file "/etc/mdadm/mdadm.conf" do
474 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
478 template "/etc/modules" do
487 subscribes :start, "template[/etc/modules]"
490 if node[:hardware][:watchdog]
493 template "/etc/default/watchdog" do
494 source "watchdog.erb"
498 variables :module => node[:hardware][:watchdog]
501 service "watchdog" do
502 action [:enable, :start]
506 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
509 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
510 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
511 chip = format("coretemp-isa-%04d", cpu)
513 temps = if File.exist?("#{coretemp}/name")
514 Dir.glob("#{coretemp}/temp*_input").map do |temp|
515 File.basename(temp).sub("temp", "").sub("_input", "").to_i
518 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
519 File.basename(temp).sub("temp", "").sub("_input", "").to_i
524 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
528 temps.each_with_index do |temp, index|
529 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
533 execute "/etc/sensors.d/chef.conf" do
535 command "/usr/bin/sensors -s"
540 template "/etc/sensors.d/chef.conf" do
541 source "sensors.conf.erb"
545 notifies :run, "execute[/etc/sensors.d/chef.conf]"