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"
22 case node[:cpu][:"0"][:vendor_id]
24 package "intel-microcode"
27 case node[:cpu][:"0"][:vendor_id]
29 if node[:lsb][:release].to_f >= 14.04
30 package "amd64-microcode"
34 if node[:dmi] && node[:dmi][:system]
35 case node[:dmi][:system][:manufacturer]
37 manufacturer = node[:dmi][:base_board][:manufacturer]
38 product = node[:dmi][:base_board][:product_name]
40 manufacturer = node[:dmi][:system][:manufacturer]
41 product = node[:dmi][:system][:product_name]
44 manufacturer = "Unknown"
57 when "TYAN Computer Corporation"
62 when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW"
74 if manufacturer == "HP" && node[:lsb][:release].to_f > 11.10
77 git "/opt/hp/hp-legacy" do
79 repository "git://chef.openstreetmap.org/hp-legacy.git"
84 link "/opt/hp/hp-health/bin/hpasmd" do
85 to "/opt/hp/hp-legacy/hpasmd"
88 link "/usr/lib/libhpasmintrfc.so.3.0" do
89 to "/opt/hp/hp-legacy/libhpasmintrfc.so.3.0"
92 link "/usr/lib/libhpasmintrfc.so.3" do
93 to "libhpasmintrfc.so.3.0"
96 link "/usr/lib/libhpasmintrfc.so" do
97 to "libhpasmintrfc.so.3.0"
102 file "/etc/init/ttySttyS#{unit}.conf" do
106 template "/etc/init/ttyS#{unit}.conf" do
107 source "tty.conf.erb"
111 variables :unit => unit, :speed => speed
114 service "ttyS#{unit}" do
115 provider Chef::Provider::Service::Upstart
116 action [:enable, :start]
117 supports :status => true, :restart => true, :reload => false
118 subscribes :restart, "template[/etc/init/ttyS#{unit}.conf]"
122 if File.exist?("/etc/default/grub")
123 execute "update-grub" do
125 command "/usr/sbin/update-grub"
128 template "/etc/default/grub" do
133 variables :unit => unit, :speed => speed
134 notifies :run, "execute[update-grub]"
138 execute "update-initramfs" do
140 command "update-initramfs -u -k all"
145 template "/etc/initramfs-tools/conf.d/mdadm" do
146 source "initramfs-mdadm.erb"
150 notifies :run, "execute[update-initramfs]"
155 action [:enable, :start]
158 if node[:kernel][:modules].include?("ipmi_si")
162 if node[:lsb][:release].to_f >= 12.10
165 template "/etc/default/irqbalance" do
166 source "irqbalance.erb"
172 service "irqbalance" do
173 action [:start, :enable]
174 supports :status => false, :restart => true, :reload => false
175 subscribes :restart, "template[/etc/default/irqbalance]"
182 node[:kernel][:modules].each_key do |modname|
185 tools_packages << "hpacucli"
186 status_packages["cciss-vol-status"] ||= []
188 tools_packages << "hpacucli"
189 status_packages["cciss-vol-status"] ||= []
191 tools_packages << "lsiutil"
192 # status_packages["mpt-status"] ||= []
194 tools_packages << "sas2ircu"
195 status_packages["sas2ircu-status"] ||= []
197 tools_packages << "megactl"
198 status_packages["megaraid-status"] ||= []
200 tools_packages << "megacli"
201 status_packages["megaclisas-status"] ||= []
203 tools_packages << "arcconf"
204 status_packages["aacraid-status"] ||= []
206 tools_packages << "areca"
210 node[:block_device].each do |name, attributes|
211 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
213 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
214 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
216 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
217 status_packages["cciss-vol-status"] |= [File.basename(sg)]
222 %w(hpacucli lsiutil sas2ircu megactl megacli arcconf).each do |tools_package|
223 if tools_packages.include?(tools_package)
224 package tools_package
226 package tools_package do
232 if tools_packages.include?("areca")
237 repository "git://chef.openstreetmap.org/areca.git"
242 directory "/opt/areca" do
248 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
249 if status_packages.include?(status_package)
250 package status_package
252 template "/etc/default/#{status_package}d" do
253 source "raid.default.erb"
257 variables :devices => status_packages[status_package]
260 service "#{status_package}d" do
261 action [:start, :enable]
262 supports :status => false, :restart => true, :reload => false
263 subscribes :restart, "template[/etc/default/#{status_package}d]"
266 package status_package do
270 file "/etc/default/#{status_package}d" do
278 node[:block_device].each do |name, attributes|
279 disks << { :device => name } if attributes[:vendor] == "ATA"
282 if status_packages["cciss-vol-status"] && File.exist?("/usr/sbin/cciss_vol_status")
283 status_packages["cciss-vol-status"].each do |device|
284 IO.popen(["cciss_vol_status", "-V", "/dev/#{device}"]).each do |line|
285 disks << { :device => device, :driver => "cciss", :id => Regexp.last_match[1].to_i - 1 } if line =~ / bay ([0-9]+) +HP /
290 if status_packages["megaclisas-status"]
293 Dir.glob("/sys/class/scsi_host/host*") do |host|
294 driver = File.new("#{host}/proc_name").read.chomp
296 next unless driver == "megaraid_sas"
298 bus = host.sub("/sys/class/scsi_host/host", "")
299 device = File.basename(Dir.glob("/sys/bus/scsi/devices/#{bus}:*/scsi_generic/*").first)
301 IO.popen(["megacli", "-PDList", "-a#{controller}", "-NoLog"]).each do |line|
302 disks << { :device => device, :driver => "megaraid", :id => Regexp.last_match[1] } if line =~ /^Device Id: ([0-9]+)$/
304 disks.pop if line =~ /^Firmware state: Hotspare, Spun down$/
311 if tools_packages.include?("lsiutil")
312 Dir.glob("/sys/class/scsi_host/host*") do |host|
313 driver = File.new("#{host}/proc_name").read.chomp
315 next unless driver == "mptsas"
317 bus = host.sub("/sys/class/scsi_host/host", "")
319 Dir.glob("/sys/bus/scsi/devices/#{bus}:0:*/scsi_generic/*").each do |sg|
320 disks << { :device => File.basename(sg) }
325 if status_packages["sas2ircu-status"]
326 Dir.glob("/sys/class/scsi_host/host*") do |host|
327 driver = File.new("#{host}/proc_name").read.chomp
329 next unless driver == "mpt2sas"
331 bus = host.sub("/sys/class/scsi_host/host", "")
333 Dir.glob("/sys/bus/scsi/devices/#{bus}:0:*/scsi_generic/*").each do |sg|
334 disks << { :device => File.basename(sg) }
339 if status_packages["aacraid-status"]
340 Dir.glob("/sys/class/scsi_host/host*") do |host|
341 driver = File.new("#{host}/proc_name").read.chomp
343 next unless driver == "aacraid"
345 bus = host.sub("/sys/class/scsi_host/host", "")
347 Dir.glob("/sys/bus/scsi/devices/#{bus}:1:*/scsi_generic/*").each do |sg|
348 disks << { :device => File.basename(sg) }
353 if tools_packages.include?("areca") && File.exist?("/opt/areca/x86_64/cli64")
354 device = IO.popen(["lsscsi", "-g"]).grep(%r{Areca +RAID controller .*/dev/(sg[0-9]+)}) do
358 IO.popen(["/opt/areca/x86_64/cli64", "disk", "info"]).each do |line|
359 next if line =~ /N\.A\./
361 if line =~ /^ +[0-9]+ +0*([0-9]+) +(?:Slot#|SLOT )0*([0-9]+) +/
362 enc = Regexp.last_match[1]
363 slot = Regexp.last_match[2]
365 disks << { :device => device, :driver => "areca", :id => "#{slot}/#{enc}" }
366 elsif line =~ /^ +([0-9]+) +[0-9]+ +/
367 disks << { :device => device, :driver => "areca", :id => Regexp.last_match[1] }
373 if disk[:device] =~ %r{^cciss/(.*)$}
374 id = File.read("/sys/bus/cciss/devices/#{Regexp.last_match[1]}/unique_id").chomp
376 disk[:munin] = "cciss-3#{id.downcase}"
378 disk[:munin] = disk[:device]
382 disk[:munin] = "#{disk[:munin]}-#{disk[:id].to_s.tr('/', ':')}"
385 disk[:hddtemp] = disk[:munin].tr("-:", "_")
389 package "smartmontools"
391 template "/etc/smartd.conf" do
392 source "smartd.conf.erb"
396 variables :disks => disks
397 notifies :reload, "service[smartmontools]"
400 template "/etc/default/smartmontools" do
401 source "smartmontools.erb"
405 notifies :restart, "service[smartmontools]"
408 service "smartmontools" do
409 action [:enable, :start]
410 supports :status => true, :restart => true, :reload => true
414 munin_plugin "smart_#{disk[:munin]}" do
416 conf "munin.smart.erb"
417 conf_variables :disk => disk
421 munin_plugin "hddtemp_smartctl" do
422 conf "munin.hddtemp.erb"
423 conf_variables :disks => disks
426 service "smartmontools" do
427 action [:stop, :disable]
430 munin_plugin "hddtemp_smartctl" do
435 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
436 disks.map { |d| "smart_#{d[:munin]}" }
438 plugins.each do |plugin|
439 munin_plugin plugin do
444 if File.exist?("/etc/mdadm/mdadm.conf")
445 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
446 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
451 file "/etc/mdadm/mdadm.conf" do
460 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
464 template "/etc/modules" do
471 if node[:lsb][:release].to_f <= 12.10
472 service "module-init-tools" do
473 provider Chef::Provider::Service::Upstart
475 subscribes :start, "template[/etc/modules]"
479 provider Chef::Provider::Service::Upstart
481 subscribes :start, "template[/etc/modules]"
485 if node[:hardware][:watchdog]
488 template "/etc/default/watchdog" do
489 source "watchdog.erb"
493 variables :module => node[:hardware][:watchdog]
496 service "watchdog" do
497 action [:enable, :start]
501 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
504 execute "/etc/sensors.d/chef.conf" do
506 command "/usr/bin/sensors -s"
511 template "/etc/sensors.d/chef.conf" do
512 source "sensors.conf.erb"
516 notifies :run, "execute[/etc/sensors.d/chef.conf]"