]> git.openstreetmap.org Git - chef.git/commitdiff
Enable smartd for directly connected disks and HP arrays
authorTom Hughes <tom@compton.nu>
Thu, 12 Mar 2015 23:00:44 +0000 (23:00 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 12 Mar 2015 23:17:53 +0000 (23:17 +0000)
cookbooks/hardware/recipes/default.rb
cookbooks/hardware/templates/default/smartd.conf.erb [new file with mode: 0644]
cookbooks/hardware/templates/default/smartmontools.erb [new file with mode: 0644]

index dd2d8015727afc1ccc716fb234eace7cbae45065..2e99eb21d94707805859b8dbec347cbd461c12b3 100644 (file)
@@ -253,6 +253,49 @@ end
   end
 end
 
+disks = []
+
+node[:block_device].each do |name, attributes|
+  disks << { :device => name } if attributes[:vendor] == "ATA"
+end
+
+if status_packages["cciss-vol-status"]
+  status_packages["cciss-vol-status"].each do |device|
+    IO.popen(["cciss_vol_status", "-V", "/dev/#{device}"]).each do |line|
+      disks << { :device => device, :driver => "cciss", :id => Regexp.last_match[1].to_i - 1 } if line =~ / bay ([0-9]+) /
+    end
+  end
+end
+
+if disks.count > 0
+  package "smartmontools"
+
+  template "/etc/smartd.conf" do
+    source "smartd.conf.erb"
+    owner "root"
+    group "root"
+    mode 0644
+    variables :disks => disks
+    notifies :reload, "service[smartmontools]"
+  end
+
+  template "/etc/default/smartmontools" do
+    source "smartmontools.erb"
+    owner "root"
+    group "root"
+    mode 0644
+    notifies :restart, "service[smartmontools]"
+  end
+
+  service "smartmontools" do
+    action [:enable, :start]
+  end
+else
+  service "smartmontools" do
+    action [:stop, :disable]
+  end
+end
+
 if File.exist?("/etc/mdadm/mdadm.conf")
   mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
     line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
diff --git a/cookbooks/hardware/templates/default/smartd.conf.erb b/cookbooks/hardware/templates/default/smartd.conf.erb
new file mode 100644 (file)
index 0000000..3f79317
--- /dev/null
@@ -0,0 +1,9 @@
+# DO NOT EDIT - This file is being maintained by Chef
+  
+<% @disks.each do |disk| -%>
+<% if disk[:driver] -%>
+/dev/<%= disk[:device] %> -d <%= disk[:driver] %>,<%= disk[:id] %> -m admins@openstreetmap.org
+<% else -%>
+/dev/<%= disk[:device] %> -m admins@openstreetmap.org
+<% end -%>
+<% end -%>
diff --git a/cookbooks/hardware/templates/default/smartmontools.erb b/cookbooks/hardware/templates/default/smartmontools.erb
new file mode 100644 (file)
index 0000000..6526ede
--- /dev/null
@@ -0,0 +1,4 @@
+# DO NOT EDIT - This file is being maintained by Chef
+  
+# Enable smartd
+start_smartd=yes