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"] ||= []
194 when "mpt2sas", "mpt3sas"
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" || driver == "mpt3sas"
332 bus = host.sub("/sys/class/scsi_host/host", "")
334 Dir.glob("/sys/bus/scsi/devices/#{bus}:0:*/scsi_generic/*").each do |sg|
335 next if File.directory?("#{sg}/../../block")
337 disks << { :device => File.basename(sg) }
342 if status_packages["aacraid-status"]
343 Dir.glob("/sys/class/scsi_host/host*") do |host|
344 driver = File.new("#{host}/proc_name").read.chomp
346 next unless driver == "aacraid"
348 bus = host.sub("/sys/class/scsi_host/host", "")
350 Dir.glob("/sys/bus/scsi/devices/#{bus}:1:*/scsi_generic/*").each do |sg|
351 disks << { :device => File.basename(sg) }
356 if tools_packages.include?("areca") && File.exist?("/opt/areca/x86_64/cli64")
357 device = IO.popen(["lsscsi", "-g"]).grep(%r{Areca +RAID controller .*/dev/(sg[0-9]+)}) do
361 IO.popen(["/opt/areca/x86_64/cli64", "disk", "info"]).each do |line|
362 next if line =~ /N\.A\./
364 if line =~ /^ +[0-9]+ +0*([0-9]+) +(?:Slot#|SLOT )0*([0-9]+) +/
365 enc = Regexp.last_match[1]
366 slot = Regexp.last_match[2]
368 disks << { :device => device, :driver => "areca", :id => "#{slot}/#{enc}" }
369 elsif line =~ /^ +([0-9]+) +[0-9]+ +/
370 disks << { :device => device, :driver => "areca", :id => Regexp.last_match[1] }
376 if disk[:device] =~ %r{^cciss/(.*)$}
377 id = File.read("/sys/bus/cciss/devices/#{Regexp.last_match[1]}/unique_id").chomp
379 disk[:munin] = "cciss-3#{id.downcase}"
381 disk[:munin] = disk[:device]
385 disk[:munin] = "#{disk[:munin]}-#{disk[:id].to_s.tr('/', ':')}"
388 disk[:hddtemp] = disk[:munin].tr("-:", "_")
392 package "smartmontools"
394 template "/etc/smartd.conf" do
395 source "smartd.conf.erb"
399 variables :disks => disks
400 notifies :reload, "service[smartmontools]"
403 template "/etc/default/smartmontools" do
404 source "smartmontools.erb"
408 notifies :restart, "service[smartmontools]"
411 service "smartmontools" do
412 action [:enable, :start]
413 supports :status => true, :restart => true, :reload => true
416 # Don't try and do munin monitoring of disks behind
417 # an Areca controller as they only allow one thing to
418 # talk to the controller at a time and smartd will
419 # throw errors if it clashes with munin
420 disks = disks.reject { |disk| disk[:driver] == "areca" }
423 munin_plugin "smart_#{disk[:munin]}" do
425 conf "munin.smart.erb"
426 conf_variables :disk => disk
430 munin_plugin "hddtemp_smartctl" do
431 conf "munin.hddtemp.erb"
432 conf_variables :disks => disks
435 service "smartmontools" do
436 action [:stop, :disable]
439 munin_plugin "hddtemp_smartctl" do
444 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
445 disks.map { |d| "smart_#{d[:munin]}" }
447 plugins.each do |plugin|
448 munin_plugin plugin do
453 if File.exist?("/etc/mdadm/mdadm.conf")
454 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
455 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
460 file "/etc/mdadm/mdadm.conf" do
469 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
473 template "/etc/modules" do
480 if node[:lsb][:release].to_f <= 12.10
481 service "module-init-tools" do
482 provider Chef::Provider::Service::Upstart
484 subscribes :start, "template[/etc/modules]"
488 provider Chef::Provider::Service::Upstart
490 subscribes :start, "template[/etc/modules]"
494 if node[:hardware][:watchdog]
497 template "/etc/default/watchdog" do
498 source "watchdog.erb"
502 variables :module => node[:hardware][:watchdog]
505 service "watchdog" do
506 action [:enable, :start]
510 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
513 execute "/etc/sensors.d/chef.conf" do
515 command "/usr/bin/sensors -s"
520 template "/etc/sensors.d/chef.conf" do
521 source "sensors.conf.erb"
525 notifies :run, "execute[/etc/sensors.d/chef.conf]"