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 %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|
87 directory "/opt/hp/hp-legacy" do
93 units.sort.uniq.each do |unit|
94 if node[:lsb][:release].to_f >= 16.04
95 service "serial-getty@ttyS#{unit}" do
96 action [:enable, :start]
99 file "/etc/init/ttySttyS#{unit}.conf" do
103 template "/etc/init/ttyS#{unit}.conf" do
104 source "tty.conf.erb"
108 variables :unit => unit
111 service "ttyS#{unit}" do
112 provider Chef::Provider::Service::Upstart
113 action [:enable, :start]
114 supports :status => true, :restart => true, :reload => false
115 subscribes :restart, "template[/etc/init/ttyS#{unit}.conf]"
120 # if we need a different / special kernel version to make the hardware
121 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
122 # ensure that we have the package installed. the grub template will
123 # make sure that this is the default on boot.
124 if node[:hardware][:grub][:kernel]
125 kernel_version = node[:hardware][:grub][:kernel]
127 package "linux-image-#{kernel_version}-generic"
128 package "linux-image-extra-#{kernel_version}-generic"
129 package "linux-headers-#{kernel_version}-generic"
131 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
132 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
133 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
138 if File.exist?("/etc/default/grub")
139 execute "update-grub" do
141 command "/usr/sbin/update-grub"
144 template "/etc/default/grub" do
149 variables :units => units, :entry => grub_entry
150 notifies :run, "execute[update-grub]"
154 execute "update-initramfs" do
156 command "update-initramfs -u -k all"
161 template "/etc/initramfs-tools/conf.d/mdadm" do
162 source "initramfs-mdadm.erb"
166 notifies :run, "execute[update-initramfs]"
171 action [:enable, :start]
174 if node[:kernel][:modules].include?("ipmi_si")
178 if node[:lsb][:release].to_f >= 12.10
181 template "/etc/default/irqbalance" do
182 source "irqbalance.erb"
188 service "irqbalance" do
189 action [:start, :enable]
190 supports :status => false, :restart => true, :reload => false
191 subscribes :restart, "template[/etc/default/irqbalance]"
198 node[:kernel][:modules].each_key do |modname|
201 tools_packages << "hpssacli"
202 status_packages["cciss-vol-status"] ||= []
204 tools_packages << "hpssacli"
205 status_packages["cciss-vol-status"] ||= []
207 tools_packages << "lsiutil"
208 # status_packages["mpt-status"] ||= []
209 when "mpt2sas", "mpt3sas"
210 tools_packages << "sas2ircu"
211 status_packages["sas2ircu-status"] ||= []
213 tools_packages << "megactl"
214 status_packages["megaraid-status"] ||= []
216 tools_packages << "megacli"
217 status_packages["megaclisas-status"] ||= []
219 tools_packages << "arcconf"
220 status_packages["aacraid-status"] ||= []
222 tools_packages << "areca"
226 node[:block_device].each do |name, attributes|
227 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
229 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
230 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
232 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
233 status_packages["cciss-vol-status"] |= [File.basename(sg)]
238 %w(hpssacli lsiutil sas2ircu megactl megacli arcconf).each do |tools_package|
239 if tools_packages.include?(tools_package)
240 package tools_package
242 package tools_package do
248 if tools_packages.include?("areca")
253 repository "git://chef.openstreetmap.org/areca.git"
258 directory "/opt/areca" do
264 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
265 if status_packages.include?(status_package)
266 package status_package
268 template "/etc/default/#{status_package}d" do
269 source "raid.default.erb"
273 variables :devices => status_packages[status_package]
276 service "#{status_package}d" do
277 action [:start, :enable]
278 supports :status => false, :restart => true, :reload => false
279 subscribes :restart, "template[/etc/default/#{status_package}d]"
282 package status_package do
286 file "/etc/default/#{status_package}d" do
292 disks = if node[:hardware][:disk]
293 node[:hardware][:disk][:disks]
298 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
300 nvmes = if node[:hardware][:pci]
301 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
306 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
308 if !intel_ssds.empty? || !intel_nvmes.empty?
312 remote_file "#{Chef::Config[:file_cache_path]}/DataCenterTool_3_0_0_Linux.zip" do
313 source "https://downloadmirror.intel.com/23931/eng/DataCenterTool_3_0_0_Linux.zip"
316 execute "unzip-DataCenterTool" do
317 command "unzip DataCenterTool_3_0_0_Linux.zip isdct-3.0.0.400-15.x86_64.rpm"
318 cwd Chef::Config[:file_cache_path]
321 not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct-3.0.0.400-15.x86_64.rpm") }
324 execute "alien-isdct" do
325 command "alien --to-deb isdct-3.0.0.400-15.x86_64.rpm"
326 cwd Chef::Config[:file_cache_path]
329 not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct_3.0.0.400-16_amd64.deb") }
332 dpkg_package "isdct" do
333 source "#{Chef::Config[:file_cache_path]}/isdct_3.0.0.400-16_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
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]
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
474 if node[:lsb][:release].to_f <= 12.10
475 service "module-init-tools" do
476 provider Chef::Provider::Service::Upstart
478 subscribes :start, "template[/etc/modules]"
482 if node[:lsb][:release].to_f >= 15.10
483 provider Chef::Provider::Service::Systemd
485 provider Chef::Provider::Service::Upstart
488 subscribes :start, "template[/etc/modules]"
492 if node[:hardware][:watchdog]
495 template "/etc/default/watchdog" do
496 source "watchdog.erb"
500 variables :module => node[:hardware][:watchdog]
503 service "watchdog" do
504 action [:enable, :start]
508 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
511 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
512 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
513 chip = format("coretemp-isa-%04d", cpu)
515 temps = if File.exist?("#{coretemp}/name")
516 Dir.glob("#{coretemp}/temp*_input").map do |temp|
517 File.basename(temp).sub("temp", "").sub("_input", "").to_i
520 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
521 File.basename(temp).sub("temp", "").sub("_input", "").to_i
526 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
530 temps.each_with_index do |temp, index|
531 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
535 execute "/etc/sensors.d/chef.conf" do
537 command "/usr/bin/sensors -s"
542 template "/etc/sensors.d/chef.conf" do
543 source "sensors.conf.erb"
547 notifies :run, "execute[/etc/sensors.d/chef.conf]"