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 # https://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
68 if product.end_with?("Gen8", "Gen9")
71 notifies :restart, "service[hp-ams]"
75 action [:enable, :start]
76 supports :status => true, :restart => true
83 when "TYAN Computer Corporation"
87 when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW", "SYS-1028U-TN10RT+", "SYS-2028U-TN24R4T+", "Super Server"
96 units.sort.uniq.each do |unit|
97 if node[:lsb][:release].to_f >= 16.04
98 service "serial-getty@ttyS#{unit}" do
99 action [:enable, :start]
102 file "/etc/init/ttySttyS#{unit}.conf" do
106 template "/etc/init/ttyS#{unit}.conf" do
107 source "tty.conf.erb"
111 variables :unit => unit
114 service "ttyS#{unit}" do
115 provider Chef::Provider::Service::Upstart
116 action [:enable, :start]
117 supports :status => true, :restart => true, :reload => false
118 subscribes :restart, "template[/etc/init/ttyS#{unit}.conf]"
123 # if we need a different / special kernel version to make the hardware
124 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
125 # ensure that we have the package installed. the grub template will
126 # make sure that this is the default on boot.
127 if node[:hardware][:grub][:kernel]
128 kernel_version = node[:hardware][:grub][:kernel]
130 package "linux-image-#{kernel_version}-generic"
131 package "linux-image-extra-#{kernel_version}-generic"
132 package "linux-headers-#{kernel_version}-generic"
134 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
135 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
136 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
141 if File.exist?("/etc/default/grub")
142 execute "update-grub" do
144 command "/usr/sbin/update-grub"
147 template "/etc/default/grub" do
152 variables :units => units, :entry => grub_entry
153 notifies :run, "execute[update-grub]"
157 execute "update-initramfs" do
159 command "update-initramfs -u -k all"
164 template "/etc/initramfs-tools/conf.d/mdadm" do
165 source "initramfs-mdadm.erb"
169 notifies :run, "execute[update-initramfs]"
174 action [:enable, :start]
177 package "ipmitool" if node[:kernel][:modules].include?("ipmi_si")
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]"
194 # Link Layer Discovery Protocol Daemon
197 action [:start, :enable]
198 supports :status => true, :restart => true, :reload => true
201 if node[:hardware][:mcelog][:enabled]
204 %w[bus cache dimm iomca page socket-memory unknown].each do |trigger|
205 template "/etc/mcelog/#{trigger}-error-trigger.local" do
206 source "mcelog-trigger.erb"
214 action [:start, :enable]
215 supports :status => true, :restart => true, :reload => false
222 node[:kernel][:modules].each_key do |modname|
225 tools_packages << "ssacli"
226 status_packages["cciss-vol-status"] ||= []
228 tools_packages << "ssacli"
229 status_packages["cciss-vol-status"] ||= []
231 tools_packages << "lsiutil"
232 status_packages["mpt-status"] ||= []
233 when "mpt2sas", "mpt3sas"
234 tools_packages << "sas2ircu"
235 status_packages["sas2ircu-status"] ||= []
237 tools_packages << "megactl"
238 status_packages["megaraid-status"] ||= []
240 tools_packages << "megacli"
241 status_packages["megaclisas-status"] ||= []
243 tools_packages << "arcconf"
244 status_packages["aacraid-status"] ||= []
246 tools_packages << "areca"
250 node[:block_device].each do |name, attributes|
251 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
253 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
254 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
256 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
257 status_packages["cciss-vol-status"] |= [File.basename(sg)]
262 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
263 if tools_packages.include?(tools_package)
264 package tools_package
266 package tools_package do
272 if tools_packages.include?("areca")
277 repository "https://git.openstreetmap.org/private/areca.git"
282 directory "/opt/areca" do
288 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
289 if status_packages.include?(status_package)
290 package status_package
292 template "/etc/default/#{status_package}d" do
293 source "raid.default.erb"
297 variables :devices => status_packages[status_package]
300 service "#{status_package}d" do
301 action [:start, :enable]
302 supports :status => false, :restart => true, :reload => false
303 subscribes :restart, "template[/etc/default/#{status_package}d]"
306 package status_package do
310 file "/etc/default/#{status_package}d" do
316 disks = if node[:hardware][:disk]
317 node[:hardware][:disk][:disks]
322 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
324 nvmes = if node[:hardware][:pci]
325 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
330 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
332 if !intel_ssds.empty? || !intel_nvmes.empty?
335 remote_file "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_3.0.13_Linux.zip" do
336 source "https://downloadmirror.intel.com/27863/eng/Intel_SSD_Data_Center_Tool_3.0.13_Linux.zip"
339 execute "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_3.0.13_Linux.zip" do
340 command "unzip Intel_SSD_Data_Center_Tool_3.0.13_Linux.zip isdct_3.0.13.400-17_amd64.deb"
341 cwd Chef::Config[:file_cache_path]
344 not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct_3.0.13.400-17_amd64.deb") }
347 dpkg_package "isdct" do
348 version "3.0.13.400-17"
349 source "#{Chef::Config[:file_cache_path]}/isdct_3.0.13.400-17_amd64.deb"
353 disks = disks.map do |disk|
354 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
356 if disk[:smart_device]
357 controller = node[:hardware][:disk][:controllers][disk[:controller]]
359 if controller && controller[:device]
360 device = controller[:device].sub("/dev/", "")
361 smart = disk[:smart_device]
363 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
364 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
365 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
366 elsif smart =~ /^.*,(\d+)$/
367 munin = "#{device}-#{Regexp.last_match(1)}"
368 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
369 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
373 device = disk[:device].sub("/dev/", "")
383 :hddtemp => munin.tr("-:", "_")
387 smartd_service = if node[:lsb][:release].to_f >= 16.04
393 disks = disks.compact
395 if disks.count.positive?
396 package "smartmontools"
398 template "/usr/local/bin/smartd-mailer" do
399 source "smartd-mailer.erb"
405 template "/etc/smartd.conf" do
406 source "smartd.conf.erb"
410 variables :disks => disks
413 template "/etc/default/smartmontools" do
414 source "smartmontools.erb"
420 service smartd_service do
421 action [:enable, :start]
422 subscribes :reload, "template[/etc/smartd.conf]"
423 subscribes :restart, "template[/etc/default/smartmontools]"
426 # Don't try and do munin monitoring of disks behind
427 # an Areca controller as they only allow one thing to
428 # talk to the controller at a time and smartd will
429 # throw errors if it clashes with munin
430 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
433 munin_plugin "smart_#{disk[:munin]}" do
435 conf "munin.smart.erb"
436 conf_variables :disk => disk
440 service smartd_service do
441 action [:stop, :disable]
445 if disks.count.positive?
446 munin_plugin "hddtemp_smartctl" do
447 conf "munin.hddtemp.erb"
448 conf_variables :disks => disks
451 munin_plugin "hddtemp_smartctl" do
453 conf "munin.hddtemp.erb"
457 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
458 disks.map { |d| "smart_#{d[:munin]}" }
460 plugins.each do |plugin|
461 munin_plugin plugin do
463 conf "munin.smart.erb"
467 if File.exist?("/etc/mdadm/mdadm.conf")
468 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
469 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
474 file "/etc/mdadm/mdadm.conf" do
483 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
487 template "/etc/modules" do
496 subscribes :start, "template[/etc/modules]"
499 if node[:hardware][:watchdog]
502 template "/etc/default/watchdog" do
503 source "watchdog.erb"
507 variables :module => node[:hardware][:watchdog]
510 service "watchdog" do
511 action [:enable, :start]
515 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
518 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
519 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
520 chip = format("coretemp-isa-%04d", cpu)
522 temps = if File.exist?("#{coretemp}/name")
523 Dir.glob("#{coretemp}/temp*_input").map do |temp|
524 File.basename(temp).sub("temp", "").sub("_input", "").to_i
527 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
528 File.basename(temp).sub("temp", "").sub("_input", "").to_i
533 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
537 temps.each_with_index do |temp, index|
538 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
542 execute "/etc/sensors.d/chef.conf" do
544 command "/usr/bin/sensors -s"
549 template "/etc/sensors.d/chef.conf" do
550 source "sensors.conf.erb"
554 notifies :run, "execute[/etc/sensors.d/chef.conf]"