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 case node[:cpu][:"0"][:vendor_id]
25 package "intel-microcode"
28 case node[:cpu][:"0"][:vendor_id]
30 if node[:lsb][:release].to_f >= 14.04
31 package "amd64-microcode"
35 if node[:dmi] && node[:dmi][:system]
36 case node[:dmi][:system][:manufacturer]
38 manufacturer = node[:dmi][:base_board][:manufacturer]
39 product = node[:dmi][:base_board][:product_name]
41 manufacturer = node[:dmi][:system][:manufacturer]
42 product = node[:dmi][:system][:product_name]
45 manufacturer = "Unknown"
58 when "TYAN Computer Corporation"
63 when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW"
75 if manufacturer == "HP" && node[:lsb][:release].to_f > 11.10
78 git "/opt/hp/hp-legacy" do
80 repository "git://chef.openstreetmap.org/hp-legacy.git"
85 link "/opt/hp/hp-health/bin/hpasmd" do
86 to "/opt/hp/hp-legacy/hpasmd"
89 link "/usr/lib/libhpasmintrfc.so.3.0" do
90 to "/opt/hp/hp-legacy/libhpasmintrfc.so.3.0"
93 link "/usr/lib/libhpasmintrfc.so.3" do
94 to "libhpasmintrfc.so.3.0"
97 link "/usr/lib/libhpasmintrfc.so" do
98 to "libhpasmintrfc.so.3.0"
103 file "/etc/init/ttySttyS#{unit}.conf" do
107 template "/etc/init/ttyS#{unit}.conf" do
108 source "tty.conf.erb"
112 variables :unit => unit, :speed => speed
115 service "ttyS#{unit}" do
116 provider Chef::Provider::Service::Upstart
117 action [:enable, :start]
118 supports :status => true, :restart => true, :reload => false
119 subscribes :restart, "template[/etc/init/ttyS#{unit}.conf]"
123 if File.exist?("/etc/default/grub")
124 execute "update-grub" do
126 command "/usr/sbin/update-grub"
129 template "/etc/default/grub" do
134 variables :unit => unit, :speed => speed
135 notifies :run, "execute[update-grub]"
139 execute "update-initramfs" do
141 command "update-initramfs -u -k all"
146 template "/etc/initramfs-tools/conf.d/mdadm" do
147 source "initramfs-mdadm.erb"
151 notifies :run, "execute[update-initramfs]"
156 action [:enable, :start]
159 if node[:kernel][:modules].include?("ipmi_si")
163 if node[:lsb][:release].to_f >= 12.10
166 template "/etc/default/irqbalance" do
167 source "irqbalance.erb"
173 service "irqbalance" do
174 action [:start, :enable]
175 supports :status => false, :restart => true, :reload => false
176 subscribes :restart, "template[/etc/default/irqbalance]"
183 node[:kernel][:modules].each_key do |modname|
186 tools_packages << "hpacucli"
187 status_packages["cciss-vol-status"] ||= []
189 tools_packages << "hpacucli"
190 status_packages["cciss-vol-status"] ||= []
192 tools_packages << "lsiutil"
193 # status_packages["mpt-status"] ||= []
195 tools_packages << "sas2ircu"
196 status_packages["sas2ircu-status"] ||= []
198 tools_packages << "megactl"
199 status_packages["megaraid-status"] ||= []
201 tools_packages << "megacli"
202 status_packages["megaclisas-status"] ||= []
204 tools_packages << "arcconf"
205 status_packages["aacraid-status"] ||= []
207 tools_packages << "areca"
211 node[:block_device].each do |name, attributes|
212 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
214 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
215 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
217 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
218 status_packages["cciss-vol-status"] |= [File.basename(sg)]
223 %w(hpacucli lsiutil sas2ircu megactl megacli arcconf).each do |tools_package|
224 if tools_packages.include?(tools_package)
225 package tools_package
227 package tools_package do
233 if tools_packages.include?("areca")
238 repository "git://chef.openstreetmap.org/areca.git"
243 directory "/opt/areca" do
249 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
250 if status_packages.include?(status_package)
251 package status_package
253 template "/etc/default/#{status_package}d" do
254 source "raid.default.erb"
258 variables :devices => status_packages[status_package]
261 service "#{status_package}d" do
262 action [:start, :enable]
263 supports :status => false, :restart => true, :reload => false
264 subscribes :restart, "template[/etc/default/#{status_package}d]"
267 package status_package do
271 file "/etc/default/#{status_package}d" do
279 node[:block_device].each do |name, attributes|
280 disks << { :device => name } if attributes[:vendor] == "ATA"
283 if status_packages["cciss-vol-status"] && File.exist?("/usr/sbin/cciss_vol_status")
284 status_packages["cciss-vol-status"].each do |device|
285 IO.popen(["cciss_vol_status", "-V", "/dev/#{device}"]).each do |line|
286 disks << { :device => device, :driver => "cciss", :id => Regexp.last_match[1].to_i - 1 } if line =~ / bay ([0-9]+) +HP /
291 if status_packages["megaclisas-status"]
294 Dir.glob("/sys/class/scsi_host/host*") do |host|
295 driver = File.new("#{host}/proc_name").read.chomp
297 next unless driver == "megaraid_sas"
299 bus = host.sub("/sys/class/scsi_host/host", "")
300 device = File.basename(Dir.glob("/sys/bus/scsi/devices/#{bus}:*/scsi_generic/*").first)
302 IO.popen(["megacli", "-PDList", "-a#{controller}", "-NoLog"]).each do |line|
303 disks << { :device => device, :driver => "megaraid", :id => Regexp.last_match[1] } if line =~ /^Device Id: ([0-9]+)$/
305 disks.pop if line =~ /^Firmware state: Hotspare, Spun down$/
312 if tools_packages.include?("lsiutil")
313 Dir.glob("/sys/class/scsi_host/host*") do |host|
314 driver = File.new("#{host}/proc_name").read.chomp
316 next unless driver == "mptsas"
318 bus = host.sub("/sys/class/scsi_host/host", "")
320 Dir.glob("/sys/bus/scsi/devices/#{bus}:0:*/scsi_generic/*").each do |sg|
321 disks << { :device => File.basename(sg) }
326 if status_packages["sas2ircu-status"]
327 Dir.glob("/sys/class/scsi_host/host*") do |host|
328 driver = File.new("#{host}/proc_name").read.chomp
330 next unless driver == "mpt2sas"
332 bus = host.sub("/sys/class/scsi_host/host", "")
334 Dir.glob("/sys/bus/scsi/devices/#{bus}:0:*/scsi_generic/*").each do |sg|
335 disks << { :device => File.basename(sg) }
340 if status_packages["aacraid-status"]
341 Dir.glob("/sys/class/scsi_host/host*") do |host|
342 driver = File.new("#{host}/proc_name").read.chomp
344 next unless driver == "aacraid"
346 bus = host.sub("/sys/class/scsi_host/host", "")
348 Dir.glob("/sys/bus/scsi/devices/#{bus}:1:*/scsi_generic/*").each do |sg|
349 disks << { :device => File.basename(sg) }
354 if tools_packages.include?("areca") && File.exist?("/opt/areca/x86_64/cli64")
355 device = IO.popen(["lsscsi", "-g"]).grep(%r{Areca +RAID controller .*/dev/(sg[0-9]+)}) do
359 IO.popen(["/opt/areca/x86_64/cli64", "disk", "info"]).each do |line|
360 next if line =~ /N\.A\./
362 if line =~ /^ +[0-9]+ +0*([0-9]+) +(?:Slot#|SLOT )0*([0-9]+) +/
363 enc = Regexp.last_match[1]
364 slot = Regexp.last_match[2]
366 disks << { :device => device, :driver => "areca", :id => "#{slot}/#{enc}" }
367 elsif line =~ /^ +([0-9]+) +[0-9]+ +/
368 disks << { :device => device, :driver => "areca", :id => Regexp.last_match[1] }
374 if disk[:device] =~ %r{^cciss/(.*)$}
375 id = File.read("/sys/bus/cciss/devices/#{Regexp.last_match[1]}/unique_id").chomp
377 disk[:munin] = "cciss-3#{id.downcase}"
379 disk[:munin] = disk[:device]
383 disk[:munin] = "#{disk[:munin]}-#{disk[:id].to_s.tr('/', ':')}"
386 disk[:hddtemp] = disk[:munin].tr("-:", "_")
390 package "smartmontools"
392 template "/etc/smartd.conf" do
393 source "smartd.conf.erb"
397 variables :disks => disks
398 notifies :reload, "service[smartmontools]"
401 template "/etc/default/smartmontools" do
402 source "smartmontools.erb"
406 notifies :restart, "service[smartmontools]"
409 service "smartmontools" do
410 action [:enable, :start]
411 supports :status => true, :restart => true, :reload => true
414 # Don't try and do munin monitoring of disks behind
415 # an Areca controller as they only allow one thing to
416 # talk to the controller at a time and smartd will
417 # throw errors if it clashes with munin
418 disks = disks.reject { |disk| disk[:driver] == "areca" }
421 munin_plugin "smart_#{disk[:munin]}" do
423 conf "munin.smart.erb"
424 conf_variables :disk => disk
428 munin_plugin "hddtemp_smartctl" do
429 conf "munin.hddtemp.erb"
430 conf_variables :disks => disks
433 service "smartmontools" do
434 action [:stop, :disable]
437 munin_plugin "hddtemp_smartctl" do
442 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
443 disks.map { |d| "smart_#{d[:munin]}" }
445 plugins.each do |plugin|
446 munin_plugin plugin do
451 if File.exist?("/etc/mdadm/mdadm.conf")
452 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
453 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
458 file "/etc/mdadm/mdadm.conf" do
467 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
471 template "/etc/modules" do
478 if node[:lsb][:release].to_f <= 12.10
479 service "module-init-tools" do
480 provider Chef::Provider::Service::Upstart
482 subscribes :start, "template[/etc/modules]"
486 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 execute "/etc/sensors.d/chef.conf" do
513 command "/usr/bin/sensors -s"
518 template "/etc/sensors.d/chef.conf" do
519 source "sensors.conf.erb"
523 notifies :run, "execute[/etc/sensors.d/chef.conf]"