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 case node[:cpu][:"0"][:vendor_id]
 
  22   package "intel-microcode"
 
  25 case node[:cpu][:"0"][:vendor_id]
 
  27   if node[:lsb][:release].to_f >= 14.04
 
  28     package "amd64-microcode"
 
  32 if node[:dmi] && node[:dmi][:system]
 
  33   case node[:dmi][:system][:manufacturer]
 
  35     manufacturer = node[:dmi][:base_board][:manufacturer]
 
  36     product = node[:dmi][:base_board][:product_name]
 
  38     manufacturer = node[:dmi][:system][:manufacturer]
 
  39     product = node[:dmi][:system][:product_name]
 
  42   manufacturer = "Unknown"
 
  55 when "TYAN Computer Corporation"
 
  60   when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW"
 
  72 if manufacturer == "HP" && node[:lsb][:release].to_f > 11.10
 
  75   git "/opt/hp/hp-legacy" do
 
  77     repository "git://chef.openstreetmap.org/hp-legacy.git"
 
  82   link "/opt/hp/hp-health/bin/hpasmd" do
 
  83     to "/opt/hp/hp-legacy/hpasmd"
 
  86   link "/usr/lib/libhpasmintrfc.so.3.0" do
 
  87     to "/opt/hp/hp-legacy/libhpasmintrfc.so.3.0"
 
  90   link "/usr/lib/libhpasmintrfc.so.3" do
 
  91     to "libhpasmintrfc.so.3.0"
 
  94   link "/usr/lib/libhpasmintrfc.so" do
 
  95     to "libhpasmintrfc.so.3.0"
 
 100   file "/etc/init/ttySttyS#{unit}.conf" do
 
 104   template "/etc/init/ttyS#{unit}.conf" do
 
 105     source "tty.conf.erb"
 
 109     variables :unit => unit, :speed => speed
 
 112   service "ttyS#{unit}" do
 
 113     provider Chef::Provider::Service::Upstart
 
 114     action [:enable, :start]
 
 115     supports :status => true, :restart => true, :reload => false
 
 116     subscribes :restart, "template[/etc/init/ttyS#{unit}.conf]"
 
 120 if File.exist?("/etc/default/grub")
 
 121   execute "update-grub" do
 
 123     command "/usr/sbin/update-grub"
 
 126   template "/etc/default/grub" do
 
 131     variables :unit => unit, :speed => speed
 
 132     notifies :run, "execute[update-grub]"
 
 136 execute "update-initramfs" do
 
 138   command "update-initramfs -u -k all"
 
 143 template "/etc/initramfs-tools/conf.d/mdadm" do
 
 144   source "initramfs-mdadm.erb"
 
 148   notifies :run, "execute[update-initramfs]"
 
 153   action [:enable, :start]
 
 156 if node[:kernel][:modules].include?("ipmi_si")
 
 160 if node[:lsb][:release].to_f >= 12.10
 
 163   template "/etc/default/irqbalance" do
 
 164     source "irqbalance.erb"
 
 170   service "irqbalance" do
 
 171     action [:start, :enable]
 
 172     supports :status => false, :restart => true, :reload => false
 
 173     subscribes :restart, "template[/etc/default/irqbalance]"
 
 180 node[:kernel][:modules].each_key do |modname|
 
 183     tools_packages << "hpacucli"
 
 184     status_packages["cciss-vol-status"] ||= []
 
 186     tools_packages << "hpacucli"
 
 187     status_packages["cciss-vol-status"] ||= []
 
 189     tools_packages << "lsiutil"
 
 190     # status_packages["mpt-status"] ||= []
 
 192     tools_packages << "sas2ircu"
 
 193     status_packages["sas2ircu-status"] ||= []
 
 195     tools_packages << "megactl"
 
 196     status_packages["megaraid-status"] ||= []
 
 198     tools_packages << "megacli"
 
 199     status_packages["megaclisas-status"] ||= []
 
 201     tools_packages << "arcconf"
 
 202     status_packages["aacraid-status"] ||= []
 
 204     tools_packages << "areca"
 
 208 node[:block_device].each do |name, attributes|
 
 209   next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
 
 211   if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
 
 212     status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
 
 214     Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
 
 215       status_packages["cciss-vol-status"] |= [File.basename(sg)]
 
 220 %w(hpacucli lsiutil sas2ircu megactl megacli arcconf).each do |tools_package|
 
 221   if tools_packages.include?(tools_package)
 
 222     package tools_package
 
 224     package tools_package do
 
 230 if tools_packages.include?("areca")
 
 235     repository "git://chef.openstreetmap.org/areca.git"
 
 240   directory "/opt/areca" do
 
 246 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
 
 247   if status_packages.include?(status_package)
 
 248     package status_package
 
 250     template "/etc/default/#{status_package}d" do
 
 251       source "raid.default.erb"
 
 255       variables :devices => status_packages[status_package]
 
 258     service "#{status_package}d" do
 
 259       action [:start, :enable]
 
 260       supports :status => false, :restart => true, :reload => false
 
 261       subscribes :restart, "template[/etc/default/#{status_package}d]"
 
 264     package status_package do
 
 268     file "/etc/default/#{status_package}d" do
 
 276 node[:block_device].each do |name, attributes|
 
 277   disks << { :device => name } if attributes[:vendor] == "ATA"
 
 280 if status_packages["cciss-vol-status"]
 
 281   status_packages["cciss-vol-status"].each do |device|
 
 282     IO.popen(["cciss_vol_status", "-V", "/dev/#{device}"]).each do |line|
 
 283       disks << { :device => device, :driver => "cciss", :id => Regexp.last_match[1].to_i - 1 } if line =~ / bay ([0-9]+) +HP /
 
 288 if status_packages["megaclisas-status"]
 
 291   Dir.glob("/sys/class/scsi_host/host*") do |host|
 
 292     driver = File.new("#{host}/proc_name").read.chomp
 
 294     next unless driver == "megaraid_sas"
 
 296     bus = host.sub("/sys/class/scsi_host/host", "")
 
 297     device = File.basename(Dir.glob("/sys/bus/scsi/devices/#{bus}:*/scsi_generic/*").first)
 
 299     IO.popen(["megacli", "-PDList", "-a#{controller}", "-NoLog"]).each do |line|
 
 300       disks << { :device => device, :driver => "megaraid",  :id => Regexp.last_match[1] } if line =~ /^Device Id: ([0-9]+)$/
 
 302       disks.pop if line =~ /^Firmware state: Hotspare, Spun down$/
 
 309 if tools_packages.include?("lsiutil")
 
 310   Dir.glob("/sys/class/scsi_host/host*") do |host|
 
 311     driver = File.new("#{host}/proc_name").read.chomp
 
 313     next unless driver == "mptsas"
 
 315     bus = host.sub("/sys/class/scsi_host/host", "")
 
 317     Dir.glob("/sys/bus/scsi/devices/#{bus}:0:*/scsi_generic/*").each do |sg|
 
 318       disks << { :device => File.basename(sg) }
 
 323 if status_packages["sas2ircu-status"]
 
 324   Dir.glob("/sys/class/scsi_host/host*") do |host|
 
 325     driver = File.new("#{host}/proc_name").read.chomp
 
 327     next unless driver == "mpt2sas"
 
 329     bus = host.sub("/sys/class/scsi_host/host", "")
 
 331     Dir.glob("/sys/bus/scsi/devices/#{bus}:0:*/scsi_generic/*").each do |sg|
 
 332       disks << { :device => File.basename(sg) }
 
 337 if status_packages["aacraid-status"]
 
 338   Dir.glob("/sys/class/scsi_host/host*") do |host|
 
 339     driver = File.new("#{host}/proc_name").read.chomp
 
 341     next unless driver == "aacraid"
 
 343     bus = host.sub("/sys/class/scsi_host/host", "")
 
 345     Dir.glob("/sys/bus/scsi/devices/#{bus}:1:*/scsi_generic/*").each do |sg|
 
 346       disks << { :device => File.basename(sg) }
 
 351 if tools_packages.include?("areca")
 
 352   device = IO.popen(["lsscsi", "-g"]).grep(%r{Areca +RAID controller .*/dev/(sg[0-9]+)}) do
 
 356   IO.popen(["/opt/areca/x86_64/cli64", "disk", "info"]).each do |line|
 
 357     next if line =~ /N\.A\./
 
 359     if line =~ /^ +[0-9]+ +0*([0-9]+) +(?:Slot#|SLOT )0*([0-9]+) +/
 
 360       enc = Regexp.last_match[1]
 
 361       slot = Regexp.last_match[2]
 
 363       disks << { :device => device, :driver => "areca", :id => "#{slot}/#{enc}" }
 
 364     elsif line =~ /^ +([0-9]+) +[0-9]+ +/
 
 365       disks << { :device => device, :driver => "areca", :id => Regexp.last_match[1] }
 
 371   if disk[:device] =~ /^cciss\/(.*)$/
 
 372     id = File.read("/sys/bus/cciss/devices/#{Regexp.last_match[1]}/unique_id").chomp
 
 374     disk[:munin] = "cciss-3#{id.downcase}"
 
 376     disk[:munin] = disk[:device]
 
 380     disk[:munin] = "#{disk[:munin]}-#{disk[:id].to_s.tr('/', ':')}"
 
 383   disk[:hddtemp] = disk[:munin].tr("-:", "_")
 
 387   package "smartmontools"
 
 389   template "/etc/smartd.conf" do
 
 390     source "smartd.conf.erb"
 
 394     variables :disks => disks
 
 395     notifies :reload, "service[smartmontools]"
 
 398   template "/etc/default/smartmontools" do
 
 399     source "smartmontools.erb"
 
 403     notifies :restart, "service[smartmontools]"
 
 406   service "smartmontools" do
 
 407     action [:enable, :start]
 
 408     supports :status => true, :restart => true, :reload => true
 
 412     munin_plugin "smart_#{disk[:munin]}" do
 
 414       conf "munin.smart.erb"
 
 415       conf_variables :disk => disk
 
 419   munin_plugin "hddtemp_smartctl" do
 
 420     conf "munin.hddtemp.erb"
 
 421     conf_variables :disks => disks
 
 424   service "smartmontools" do
 
 425     action [:stop, :disable]
 
 428   munin_plugin "hddtemp_smartctl" do
 
 433 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
 
 434           disks.map { |d| "smart_#{d[:munin]}" }
 
 436 plugins.each do |plugin|
 
 437   munin_plugin plugin do
 
 442 if File.exist?("/etc/mdadm/mdadm.conf")
 
 443   mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
 
 444     line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
 
 449   file "/etc/mdadm/mdadm.conf" do
 
 458     subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
 
 462 template "/etc/modules" do
 
 469 if node[:lsb][:release].to_f <= 12.10
 
 470   service "module-init-tools" do
 
 471     provider Chef::Provider::Service::Upstart
 
 473     subscribes :start, "template[/etc/modules]"
 
 477     provider Chef::Provider::Service::Upstart
 
 479     subscribes :start, "template[/etc/modules]"
 
 483 if node[:hardware][:watchdog]
 
 486   template "/etc/default/watchdog" do
 
 487     source "watchdog.erb"
 
 491     variables :module => node[:hardware][:watchdog]
 
 494   service "watchdog" do
 
 495     action [:enable, :start]
 
 499 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
 
 502   execute "/etc/sensors.d/chef.conf" do
 
 504     command "/usr/bin/sensors -s"
 
 509   template "/etc/sensors.d/chef.conf" do
 
 510     source "sensors.conf.erb"
 
 514     notifies :run, "execute[/etc/sensors.d/chef.conf]"