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 disks = disks.map do |disk|
285 next if disk[:state] == "spun_down"
287 if disk[:smart_device]
288 controller = node[:hardware][:disk][:controllers][disk[:controller]]
289 device = controller[:device].sub("/dev/", "")
290 smart = disk[:smart_device]
292 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
293 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
294 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
295 elsif smart =~ /^.*,(\d+)$/
296 munin = "#{device}-#{Regexp.last_match(1)}"
297 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
298 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
301 device = disk[:device].sub("/dev/", "")
311 :hddtemp => munin.tr("-:", "_")
315 disks = disks.compact
318 package "smartmontools"
320 template "/usr/local/bin/smartd-mailer" do
321 source "smartd-mailer.erb"
327 template "/etc/smartd.conf" do
328 source "smartd.conf.erb"
332 variables :disks => disks
333 notifies :reload, "service[smartmontools]"
336 template "/etc/default/smartmontools" do
337 source "smartmontools.erb"
341 notifies :restart, "service[smartmontools]"
344 service "smartmontools" do
345 action [:enable, :start]
346 supports :status => true, :restart => true, :reload => true
349 # Don't try and do munin monitoring of disks behind
350 # an Areca controller as they only allow one thing to
351 # talk to the controller at a time and smartd will
352 # throw errors if it clashes with munin
353 disks = disks.reject { |disk| disk[:smart] && disk[:smart].start_with?("areca,") }
356 munin_plugin "smart_#{disk[:munin]}" do
358 conf "munin.smart.erb"
359 conf_variables :disk => disk
363 service "smartmontools" do
364 action [:stop, :disable]
369 munin_plugin "hddtemp_smartctl" do
370 conf "munin.hddtemp.erb"
371 conf_variables :disks => disks
374 munin_plugin "hddtemp_smartctl" do
376 conf "munin.hddtemp.erb"
380 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
381 disks.map { |d| "smart_#{d[:munin]}" }
383 plugins.each do |plugin|
384 munin_plugin plugin do
389 if File.exist?("/etc/mdadm/mdadm.conf")
390 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
391 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
396 file "/etc/mdadm/mdadm.conf" do
405 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
409 template "/etc/modules" do
416 if node[:lsb][:release].to_f <= 12.10
417 service "module-init-tools" do
418 provider Chef::Provider::Service::Upstart
420 subscribes :start, "template[/etc/modules]"
424 if node[:lsb][:release].to_f >= 15.10
425 provider Chef::Provider::Service::Systemd
427 provider Chef::Provider::Service::Upstart
430 subscribes :start, "template[/etc/modules]"
434 if node[:hardware][:watchdog]
437 template "/etc/default/watchdog" do
438 source "watchdog.erb"
442 variables :module => node[:hardware][:watchdog]
445 service "watchdog" do
446 action [:enable, :start]
450 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
453 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
454 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
455 chip = format("coretemp-isa-%04d", cpu)
457 temps = if File.exist?("#{coretemp}/name")
458 Dir.glob("#{coretemp}/temp*_input").map do |temp|
459 File.basename(temp).sub("temp", "").sub("_input", "").to_i
462 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
463 File.basename(temp).sub("temp", "").sub("_input", "").to_i
468 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
472 temps.each_with_index do |temp, index|
473 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
477 execute "/etc/sensors.d/chef.conf" do
479 command "/usr/bin/sensors -s"
484 template "/etc/sensors.d/chef.conf" do
485 source "sensors.conf.erb"
489 notifies :run, "execute[/etc/sensors.d/chef.conf]"