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")
63 # Downgrade hp-health to 10.0.0.1.3-4. as 10.40-1815.49 has issues with reliable startup
64 package "hp-health" do
66 version "10.0.0.1.3-4."
68 notifies :restart, "service[hp-health]"
71 service "hp-health" do
72 action [:enable, :start]
73 supports :status => true, :restart => true
79 when "TYAN Computer Corporation"
83 when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW", "SYS-2028U-TN24R4T+"
92 # Remove legacy HP G4 support which breaks modern hp-health 10.4
93 if manufacturer == "HP"
94 %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|
100 directory "/opt/hp/hp-legacy" do
106 units.sort.uniq.each do |unit|
107 if node[:lsb][:release].to_f >= 16.04
108 service "serial-getty@ttyS#{unit}" do
109 action [:enable, :start]
112 file "/etc/init/ttySttyS#{unit}.conf" do
116 template "/etc/init/ttyS#{unit}.conf" do
117 source "tty.conf.erb"
121 variables :unit => unit
124 service "ttyS#{unit}" do
125 provider Chef::Provider::Service::Upstart
126 action [:enable, :start]
127 supports :status => true, :restart => true, :reload => false
128 subscribes :restart, "template[/etc/init/ttyS#{unit}.conf]"
133 # if we need a different / special kernel version to make the hardware
134 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
135 # ensure that we have the package installed. the grub template will
136 # make sure that this is the default on boot.
137 if node[:hardware][:grub][:kernel]
138 kernel_version = node[:hardware][:grub][:kernel]
140 package "linux-image-#{kernel_version}-generic"
141 package "linux-image-extra-#{kernel_version}-generic"
142 package "linux-headers-#{kernel_version}-generic"
144 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
145 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
146 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
151 if File.exist?("/etc/default/grub")
152 execute "update-grub" do
154 command "/usr/sbin/update-grub"
157 template "/etc/default/grub" do
162 variables :units => units, :entry => grub_entry
163 notifies :run, "execute[update-grub]"
167 execute "update-initramfs" do
169 command "update-initramfs -u -k all"
174 template "/etc/initramfs-tools/conf.d/mdadm" do
175 source "initramfs-mdadm.erb"
179 notifies :run, "execute[update-initramfs]"
184 action [:enable, :start]
187 if node[:kernel][:modules].include?("ipmi_si")
191 if node[:lsb][:release].to_f >= 12.10
194 template "/etc/default/irqbalance" do
195 source "irqbalance.erb"
201 service "irqbalance" do
202 action [:start, :enable]
203 supports :status => false, :restart => true, :reload => false
204 subscribes :restart, "template[/etc/default/irqbalance]"
211 node[:kernel][:modules].each_key do |modname|
214 tools_packages << "hpssacli"
215 status_packages["cciss-vol-status"] ||= []
217 tools_packages << "hpssacli"
218 status_packages["cciss-vol-status"] ||= []
220 tools_packages << "lsiutil"
221 # status_packages["mpt-status"] ||= []
222 when "mpt2sas", "mpt3sas"
223 tools_packages << "sas2ircu"
224 status_packages["sas2ircu-status"] ||= []
226 tools_packages << "megactl"
227 status_packages["megaraid-status"] ||= []
229 tools_packages << "megacli"
230 status_packages["megaclisas-status"] ||= []
232 tools_packages << "arcconf"
233 status_packages["aacraid-status"] ||= []
235 tools_packages << "areca"
239 node[:block_device].each do |name, attributes|
240 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
242 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
243 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
245 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
246 status_packages["cciss-vol-status"] |= [File.basename(sg)]
251 %w(hpssacli lsiutil sas2ircu megactl megacli arcconf).each do |tools_package|
252 if tools_packages.include?(tools_package)
253 package tools_package
255 package tools_package do
261 if tools_packages.include?("areca")
266 repository "git://chef.openstreetmap.org/areca.git"
271 directory "/opt/areca" do
277 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
278 if status_packages.include?(status_package)
279 package status_package
281 template "/etc/default/#{status_package}d" do
282 source "raid.default.erb"
286 variables :devices => status_packages[status_package]
289 service "#{status_package}d" do
290 action [:start, :enable]
291 supports :status => false, :restart => true, :reload => false
292 subscribes :restart, "template[/etc/default/#{status_package}d]"
295 package status_package do
299 file "/etc/default/#{status_package}d" do
305 disks = if node[:hardware][:disk]
306 node[:hardware][:disk][:disks]
311 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
313 nvmes = if node[:hardware][:pci]
314 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
319 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
321 if !intel_ssds.empty? || !intel_nvmes.empty?
325 remote_file "#{Chef::Config[:file_cache_path]}/DataCenterTool_3_0_0_Linux.zip" do
326 source "https://downloadmirror.intel.com/23931/eng/DataCenterTool_3_0_0_Linux.zip"
329 execute "unzip-DataCenterTool" do
330 command "unzip DataCenterTool_3_0_0_Linux.zip isdct-3.0.0.400-15.x86_64.rpm"
331 cwd Chef::Config[:file_cache_path]
334 not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct-3.0.0.400-15.x86_64.rpm") }
337 execute "alien-isdct" do
338 command "alien --to-deb isdct-3.0.0.400-15.x86_64.rpm"
339 cwd Chef::Config[:file_cache_path]
342 not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct_3.0.0.400-16_amd64.deb") }
345 dpkg_package "isdct" do
346 source "#{Chef::Config[:file_cache_path]}/isdct_3.0.0.400-16_amd64.deb"
350 disks = disks.map do |disk|
351 next if disk[:state] == "spun_down"
353 if disk[:smart_device]
354 controller = node[:hardware][:disk][:controllers][disk[:controller]]
355 device = controller[:device].sub("/dev/", "")
356 smart = disk[:smart_device]
358 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
359 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
360 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
361 elsif smart =~ /^.*,(\d+)$/
362 munin = "#{device}-#{Regexp.last_match(1)}"
363 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
364 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
367 device = disk[:device].sub("/dev/", "")
377 :hddtemp => munin.tr("-:", "_")
381 smartd_service = if node[:lsb][:release].to_f >= 16.04
387 disks = disks.compact
390 package "smartmontools"
392 template "/usr/local/bin/smartd-mailer" do
393 source "smartd-mailer.erb"
399 template "/etc/smartd.conf" do
400 source "smartd.conf.erb"
404 variables :disks => disks
407 template "/etc/default/smartmontools" do
408 source "smartmontools.erb"
414 service smartd_service do
415 action [:enable, :start]
416 subscribes :reload, "template[/etc/smartd.conf]"
417 subscribes :restart, "template[/etc/default/smartmontools]"
420 # Don't try and do munin monitoring of disks behind
421 # an Areca controller as they only allow one thing to
422 # talk to the controller at a time and smartd will
423 # throw errors if it clashes with munin
424 disks = disks.reject { |disk| disk[:smart] && disk[:smart].start_with?("areca,") }
427 munin_plugin "smart_#{disk[:munin]}" do
429 conf "munin.smart.erb"
430 conf_variables :disk => disk
434 service smartd_service do
435 action [:stop, :disable]
440 munin_plugin "hddtemp_smartctl" do
441 conf "munin.hddtemp.erb"
442 conf_variables :disks => disks
445 munin_plugin "hddtemp_smartctl" do
447 conf "munin.hddtemp.erb"
451 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
452 disks.map { |d| "smart_#{d[:munin]}" }
454 plugins.each do |plugin|
455 munin_plugin plugin do
460 if File.exist?("/etc/mdadm/mdadm.conf")
461 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
462 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
467 file "/etc/mdadm/mdadm.conf" do
476 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
480 template "/etc/modules" do
487 if node[:lsb][:release].to_f <= 12.10
488 service "module-init-tools" do
489 provider Chef::Provider::Service::Upstart
491 subscribes :start, "template[/etc/modules]"
495 if node[:lsb][:release].to_f >= 15.10
496 provider Chef::Provider::Service::Systemd
498 provider Chef::Provider::Service::Upstart
501 subscribes :start, "template[/etc/modules]"
505 if node[:hardware][:watchdog]
508 template "/etc/default/watchdog" do
509 source "watchdog.erb"
513 variables :module => node[:hardware][:watchdog]
516 service "watchdog" do
517 action [:enable, :start]
521 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
524 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
525 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
526 chip = format("coretemp-isa-%04d", cpu)
528 temps = if File.exist?("#{coretemp}/name")
529 Dir.glob("#{coretemp}/temp*_input").map do |temp|
530 File.basename(temp).sub("temp", "").sub("_input", "").to_i
533 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
534 File.basename(temp).sub("temp", "").sub("_input", "").to_i
539 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
543 temps.each_with_index do |temp, index|
544 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
548 execute "/etc/sensors.d/chef.conf" do
550 command "/usr/bin/sensors -s"
555 template "/etc/sensors.d/chef.conf" do
556 source "sensors.conf.erb"
560 notifies :run, "execute[/etc/sensors.d/chef.conf]"