]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/hardware/recipes/default.rb
Use systemd to manage kmod on Ubuntu 15.10
[chef.git] / cookbooks / hardware / recipes / default.rb
index 2f8a4398e8d2805910b0eda719741a259d691244..8ba21da8bc18e491c83617786dea50b74d16251b 100644 (file)
@@ -297,10 +297,18 @@ end
   end
 end
 
-disks = node[:hardware][:disk][:disks].map do |disk|
+if node[:hardware][:disk]
+  disks = node[:hardware][:disk][:disks]
+else
+  disks = []
+end
+
+disks = disks.map do |disk|
+  next if disk[:state] == "spun_down"
+
   if disk[:smart_device]
     controller = node[:hardware][:disk][:controllers][disk[:controller]]
-    device = File.basename(controller[:device])
+    device = controller[:device].sub("/dev/", "")
     smart = disk[:smart_device]
 
     if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
@@ -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
-    device = File.basename(disk[:device])
+  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