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"
62 when "TYAN Computer Corporation"
67 when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW"
79 if manufacturer == "HP" && node[:lsb][:release].to_f > 11.10
82 git "/opt/hp/hp-legacy" do
84 repository "git://chef.openstreetmap.org/hp-legacy.git"
90 link "/opt/hp/hp-health/bin/hpasmd" do
91 to "/opt/hp/hp-legacy/hpasmd"
94 link "/usr/lib/libhpasmintrfc.so.3.0" do
95 to "/opt/hp/hp-legacy/libhpasmintrfc.so.3.0"
98 link "/usr/lib/libhpasmintrfc.so.3" do
99 to "libhpasmintrfc.so.3.0"
102 link "/usr/lib/libhpasmintrfc.so" do
103 to "libhpasmintrfc.so.3.0"
108 file "/etc/init/ttySttyS#{unit}.conf" do
112 template "/etc/init/ttyS#{unit}.conf" do
113 source "tty.conf.erb"
117 variables :unit => unit, :speed => speed
120 service "ttyS#{unit}" do
121 provider Chef::Provider::Service::Upstart
122 action [:enable, :start]
123 supports :status => true, :restart => true, :reload => false
124 subscribes :restart, "template[/etc/init/ttyS#{unit}.conf]"
128 # if we need a different / special kernel version to make the hardware
129 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
130 # ensure that we have the package installed. the grub template will
131 # make sure that this is the default on boot.
132 if node[:hardware][:grub][:kernel]
133 kernel_version = node[:hardware][:grub][:kernel]
135 package "linux-image-#{kernel_version}-generic"
136 package "linux-image-extra-#{kernel_version}-generic"
137 package "linux-headers-#{kernel_version}-generic"
139 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
140 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
141 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
146 if File.exist?("/etc/default/grub")
147 execute "update-grub" do
149 command "/usr/sbin/update-grub"
152 template "/etc/default/grub" do
157 variables :unit => unit, :speed => speed, :entry => grub_entry
158 notifies :run, "execute[update-grub]"
162 execute "update-initramfs" do
164 command "update-initramfs -u -k all"
169 template "/etc/initramfs-tools/conf.d/mdadm" do
170 source "initramfs-mdadm.erb"
174 notifies :run, "execute[update-initramfs]"
179 action [:enable, :start]
182 if node[:kernel][:modules].include?("ipmi_si")
186 if node[:lsb][:release].to_f >= 12.10
189 template "/etc/default/irqbalance" do
190 source "irqbalance.erb"
196 service "irqbalance" do
197 action [:start, :enable]
198 supports :status => false, :restart => true, :reload => false
199 subscribes :restart, "template[/etc/default/irqbalance]"
206 node[:kernel][:modules].each_key do |modname|
209 tools_packages << "hpssacli"
210 status_packages["cciss-vol-status"] ||= []
212 tools_packages << "hpssacli"
213 status_packages["cciss-vol-status"] ||= []
215 tools_packages << "lsiutil"
216 # status_packages["mpt-status"] ||= []
217 when "mpt2sas", "mpt3sas"
218 tools_packages << "sas2ircu"
219 status_packages["sas2ircu-status"] ||= []
221 tools_packages << "megactl"
222 status_packages["megaraid-status"] ||= []
224 tools_packages << "megacli"
225 status_packages["megaclisas-status"] ||= []
227 tools_packages << "arcconf"
228 status_packages["aacraid-status"] ||= []
230 tools_packages << "areca"
234 node[:block_device].each do |name, attributes|
235 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
237 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
238 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
240 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
241 status_packages["cciss-vol-status"] |= [File.basename(sg)]
246 %w(hpssacli lsiutil sas2ircu megactl megacli arcconf).each do |tools_package|
247 if tools_packages.include?(tools_package)
248 package tools_package
250 package tools_package do
256 if tools_packages.include?("areca")
261 repository "git://chef.openstreetmap.org/areca.git"
266 directory "/opt/areca" do
272 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
273 if status_packages.include?(status_package)
274 package status_package
276 template "/etc/default/#{status_package}d" do
277 source "raid.default.erb"
281 variables :devices => status_packages[status_package]
284 service "#{status_package}d" do
285 action [:start, :enable]
286 supports :status => false, :restart => true, :reload => false
287 subscribes :restart, "template[/etc/default/#{status_package}d]"
290 package status_package do
294 file "/etc/default/#{status_package}d" do
300 if node[:hardware][:disk]
301 disks = node[:hardware][:disk][:disks]
306 disks = disks.map do |disk|
307 next if disk[:state] == "spun_down"
309 if disk[:smart_device]
310 controller = node[:hardware][:disk][:controllers][disk[:controller]]
311 device = controller[:device].sub("/dev/", "")
312 smart = disk[:smart_device]
314 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
315 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
316 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
317 elsif smart =~ /^.*,(\d+)$/
318 munin = "#{device}-#{Regexp.last_match(1)}"
319 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
320 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
323 device = disk[:device].sub("/dev/", "")
333 :hddtemp => munin.tr("-:", "_")
337 disks = disks.compact
340 package "smartmontools"
342 template "/usr/local/bin/smartd-mailer" do
343 source "smartd-mailer.erb"
349 template "/etc/smartd.conf" do
350 source "smartd.conf.erb"
354 variables :disks => disks
355 notifies :reload, "service[smartmontools]"
358 template "/etc/default/smartmontools" do
359 source "smartmontools.erb"
363 notifies :restart, "service[smartmontools]"
366 service "smartmontools" do
367 action [:enable, :start]
368 supports :status => true, :restart => true, :reload => true
371 # Don't try and do munin monitoring of disks behind
372 # an Areca controller as they only allow one thing to
373 # talk to the controller at a time and smartd will
374 # throw errors if it clashes with munin
375 disks = disks.reject { |disk| disk[:smart] && disk[:smart].start_with?("areca,") }
378 munin_plugin "smart_#{disk[:munin]}" do
380 conf "munin.smart.erb"
381 conf_variables :disk => disk
385 service "smartmontools" do
386 action [:stop, :disable]
391 munin_plugin "hddtemp_smartctl" do
392 conf "munin.hddtemp.erb"
393 conf_variables :disks => disks
396 munin_plugin "hddtemp_smartctl" do
398 conf "munin.hddtemp.erb"
402 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
403 disks.map { |d| "smart_#{d[:munin]}" }
405 plugins.each do |plugin|
406 munin_plugin plugin do
411 if File.exist?("/etc/mdadm/mdadm.conf")
412 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
413 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
418 file "/etc/mdadm/mdadm.conf" do
427 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
431 template "/etc/modules" do
438 if node[:lsb][:release].to_f <= 12.10
439 service "module-init-tools" do
440 provider Chef::Provider::Service::Upstart
442 subscribes :start, "template[/etc/modules]"
446 provider Chef::Provider::Service::Upstart
448 subscribes :start, "template[/etc/modules]"
452 if node[:hardware][:watchdog]
455 template "/etc/default/watchdog" do
456 source "watchdog.erb"
460 variables :module => node[:hardware][:watchdog]
463 service "watchdog" do
464 action [:enable, :start]
468 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
471 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
472 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
473 chip = format("coretemp-isa-%04d", cpu)
475 if File.exist?("#{coretemp}/name")
476 temps = Dir.glob("#{coretemp}/temp*_input").map do |temp|
477 File.basename(temp).sub("temp", "").sub("_input", "").to_i
480 temps = Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
481 File.basename(temp).sub("temp", "").sub("_input", "").to_i
486 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
490 temps.each_with_index do |temp, index|
491 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
495 execute "/etc/sensors.d/chef.conf" do
497 command "/usr/bin/sensors -s"
502 template "/etc/sensors.d/chef.conf" do
503 source "sensors.conf.erb"
507 notifies :run, "execute[/etc/sensors.d/chef.conf]"