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 units.sort.uniq.each do |unit|
80 if node[:lsb][:release].to_f >= 16.04
81 service "serial-getty@ttyS#{unit}" do
82 action [:enable, :start]
85 file "/etc/init/ttySttyS#{unit}.conf" do
89 template "/etc/init/ttyS#{unit}.conf" do
94 variables :unit => unit
97 service "ttyS#{unit}" do
98 provider Chef::Provider::Service::Upstart
99 action [:enable, :start]
100 supports :status => true, :restart => true, :reload => false
101 subscribes :restart, "template[/etc/init/ttyS#{unit}.conf]"
106 # if we need a different / special kernel version to make the hardware
107 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
108 # ensure that we have the package installed. the grub template will
109 # make sure that this is the default on boot.
110 if node[:hardware][:grub][:kernel]
111 kernel_version = node[:hardware][:grub][:kernel]
113 package "linux-image-#{kernel_version}-generic"
114 package "linux-image-extra-#{kernel_version}-generic"
115 package "linux-headers-#{kernel_version}-generic"
117 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
118 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
119 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
124 if File.exist?("/etc/default/grub")
125 execute "update-grub" do
127 command "/usr/sbin/update-grub"
130 template "/etc/default/grub" do
135 variables :units => units, :entry => grub_entry
136 notifies :run, "execute[update-grub]"
140 execute "update-initramfs" do
142 command "update-initramfs -u -k all"
147 template "/etc/initramfs-tools/conf.d/mdadm" do
148 source "initramfs-mdadm.erb"
152 notifies :run, "execute[update-initramfs]"
157 action [:enable, :start]
160 if node[:kernel][:modules].include?("ipmi_si")
164 if node[:lsb][:release].to_f >= 12.10
167 template "/etc/default/irqbalance" do
168 source "irqbalance.erb"
174 service "irqbalance" do
175 action [:start, :enable]
176 supports :status => false, :restart => true, :reload => false
177 subscribes :restart, "template[/etc/default/irqbalance]"
184 node[:kernel][:modules].each_key do |modname|
187 tools_packages << "hpssacli"
188 status_packages["cciss-vol-status"] ||= []
190 tools_packages << "hpssacli"
191 status_packages["cciss-vol-status"] ||= []
193 tools_packages << "lsiutil"
194 # status_packages["mpt-status"] ||= []
195 when "mpt2sas", "mpt3sas"
196 tools_packages << "sas2ircu"
197 status_packages["sas2ircu-status"] ||= []
199 tools_packages << "megactl"
200 status_packages["megaraid-status"] ||= []
202 tools_packages << "megacli"
203 status_packages["megaclisas-status"] ||= []
205 tools_packages << "arcconf"
206 status_packages["aacraid-status"] ||= []
208 tools_packages << "areca"
212 node[:block_device].each do |name, attributes|
213 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
215 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
216 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
218 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
219 status_packages["cciss-vol-status"] |= [File.basename(sg)]
224 %w(hpssacli lsiutil sas2ircu megactl megacli arcconf).each do |tools_package|
225 if tools_packages.include?(tools_package)
226 package tools_package
228 package tools_package do
234 if tools_packages.include?("areca")
239 repository "git://chef.openstreetmap.org/areca.git"
244 directory "/opt/areca" do
250 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
251 if status_packages.include?(status_package)
252 package status_package
254 template "/etc/default/#{status_package}d" do
255 source "raid.default.erb"
259 variables :devices => status_packages[status_package]
262 service "#{status_package}d" do
263 action [:start, :enable]
264 supports :status => false, :restart => true, :reload => false
265 subscribes :restart, "template[/etc/default/#{status_package}d]"
268 package status_package do
272 file "/etc/default/#{status_package}d" do
278 disks = if node[:hardware][:disk]
279 node[:hardware][:disk][:disks]
284 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
286 nvmes = if node[:hardware][:pci]
287 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
292 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
294 if !intel_ssds.empty? || !intel_nvmes.empty?
298 remote_file "#{Chef::Config[:file_cache_path]}/DataCenterTool_3_0_0_Linux.zip" do
299 source "https://downloadmirror.intel.com/23931/eng/DataCenterTool_3_0_0_Linux.zip"
302 execute "unzip-DataCenterTool" do
303 command "unzip DataCenterTool_3_0_0_Linux.zip isdct-3.0.0.400-15.x86_64.rpm"
304 cwd Chef::Config[:file_cache_path]
307 not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct-3.0.0.400-15.x86_64.rpm") }
310 execute "alien-isdct" do
311 command "alien --to-deb isdct-3.0.0.400-15.x86_64.rpm"
312 cwd Chef::Config[:file_cache_path]
315 not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct_3.0.0.400-16_amd64.deb") }
318 dpkg_package "isdct" do
319 source "#{Chef::Config[:file_cache_path]}/isdct_3.0.0.400-16_amd64.deb"
323 disks = disks.map do |disk|
324 next if disk[:state] == "spun_down"
326 if disk[:smart_device]
327 controller = node[:hardware][:disk][:controllers][disk[:controller]]
328 device = controller[:device].sub("/dev/", "")
329 smart = disk[:smart_device]
331 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
332 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
333 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
334 elsif smart =~ /^.*,(\d+)$/
335 munin = "#{device}-#{Regexp.last_match(1)}"
336 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
337 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
340 device = disk[:device].sub("/dev/", "")
350 :hddtemp => munin.tr("-:", "_")
354 smartd_service = if node[:lsb][:release].to_f >= 16.04
360 disks = disks.compact
363 package "smartmontools"
365 template "/usr/local/bin/smartd-mailer" do
366 source "smartd-mailer.erb"
372 template "/etc/smartd.conf" do
373 source "smartd.conf.erb"
377 variables :disks => disks
380 template "/etc/default/smartmontools" do
381 source "smartmontools.erb"
387 service smartd_service do
388 action [:enable, :start]
389 subscribes :reload, "template[/etc/smartd.conf]"
390 subscribes :restart, "template[/etc/default/smartmontools]"
393 # Don't try and do munin monitoring of disks behind
394 # an Areca controller as they only allow one thing to
395 # talk to the controller at a time and smartd will
396 # throw errors if it clashes with munin
397 disks = disks.reject { |disk| disk[:smart] && disk[:smart].start_with?("areca,") }
400 munin_plugin "smart_#{disk[:munin]}" do
402 conf "munin.smart.erb"
403 conf_variables :disk => disk
407 service smartd_service do
408 action [:stop, :disable]
413 munin_plugin "hddtemp_smartctl" do
414 conf "munin.hddtemp.erb"
415 conf_variables :disks => disks
418 munin_plugin "hddtemp_smartctl" do
420 conf "munin.hddtemp.erb"
424 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
425 disks.map { |d| "smart_#{d[:munin]}" }
427 plugins.each do |plugin|
428 munin_plugin plugin do
433 if File.exist?("/etc/mdadm/mdadm.conf")
434 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
435 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
440 file "/etc/mdadm/mdadm.conf" do
449 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
453 template "/etc/modules" do
460 if node[:lsb][:release].to_f <= 12.10
461 service "module-init-tools" do
462 provider Chef::Provider::Service::Upstart
464 subscribes :start, "template[/etc/modules]"
468 if node[:lsb][:release].to_f >= 15.10
469 provider Chef::Provider::Service::Systemd
471 provider Chef::Provider::Service::Upstart
474 subscribes :start, "template[/etc/modules]"
478 if node[:hardware][:watchdog]
481 template "/etc/default/watchdog" do
482 source "watchdog.erb"
486 variables :module => node[:hardware][:watchdog]
489 service "watchdog" do
490 action [:enable, :start]
494 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
497 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
498 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
499 chip = format("coretemp-isa-%04d", cpu)
501 temps = if File.exist?("#{coretemp}/name")
502 Dir.glob("#{coretemp}/temp*_input").map do |temp|
503 File.basename(temp).sub("temp", "").sub("_input", "").to_i
506 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
507 File.basename(temp).sub("temp", "").sub("_input", "").to_i
512 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
516 temps.each_with_index do |temp, index|
517 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
521 execute "/etc/sensors.d/chef.conf" do
523 command "/usr/bin/sensors -s"
528 template "/etc/sensors.d/chef.conf" do
529 source "sensors.conf.erb"
533 notifies :run, "execute[/etc/sensors.d/chef.conf]"