X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/08c435b987e0d5035af9cfa6480e8c04b7466303..1482fd1105597fca4262ace6ef2a9016aa228a24:/cookbooks/hardware/recipes/default.rb?ds=sidebyside diff --git a/cookbooks/hardware/recipes/default.rb b/cookbooks/hardware/recipes/default.rb index c29185248..8342a9ac3 100644 --- a/cookbooks/hardware/recipes/default.rb +++ b/cookbooks/hardware/recipes/default.rb @@ -297,7 +297,15 @@ end end end -disks = node[:hardware][:disk][:disks].map do |disk| +disks = if node[:hardware][:disk] + node[:hardware][:disk][:disks] + else + [] + end + +disks = disks.map do |disk| + next if disk[:state] == "spun_down" + if disk[:smart_device] controller = node[:hardware][:disk][:controllers][disk[:controller]] device = controller[:device].sub("/dev/", "") @@ -311,11 +319,13 @@ disks = node[:hardware][:disk][:disks].map do |disk| elsif smart =~ %r{^.*,(\d+)/(\d+)$} munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}" end - else + elsif disk[:device] device = disk[:device].sub("/dev/", "") munin = device end + next if device.nil? + Hash[ :device => device, :smart => smart, @@ -324,6 +334,8 @@ disks = node[:hardware][:disk][:disks].map do |disk| ] end +disks = disks.compact + if disks.count > 0 package "smartmontools" @@ -431,7 +443,11 @@ if node[:lsb][:release].to_f <= 12.10 end else service "kmod" do - provider Chef::Provider::Service::Upstart + if node[:lsb][:release].to_f >= 15.10 + provider Chef::Provider::Service::Systemd + else + provider Chef::Provider::Service::Upstart + end action :nothing subscribes :start, "template[/etc/modules]" end @@ -460,15 +476,15 @@ unless Dir.glob("/sys/class/hwmon/hwmon*").empty? cpu = File.basename(coretemp).sub("coretemp.", "").to_i chip = format("coretemp-isa-%04d", cpu) - if File.exist?("#{coretemp}/name") - temps = Dir.glob("#{coretemp}/temp*_input").map do |temp| - File.basename(temp).sub("temp", "").sub("_input", "").to_i - end.sort - else - temps = Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp| - File.basename(temp).sub("temp", "").sub("_input", "").to_i - end.sort - end + temps = if File.exist?("#{coretemp}/name") + Dir.glob("#{coretemp}/temp*_input").map do |temp| + File.basename(temp).sub("temp", "").sub("_input", "").to_i + end.sort + else + Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp| + File.basename(temp).sub("temp", "").sub("_input", "").to_i + end.sort + end if temps.first == 1 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"