From: Tom Hughes Date: Thu, 12 Mar 2015 23:00:44 +0000 (+0000) Subject: Enable smartd for directly connected disks and HP arrays X-Git-Url: https://git.openstreetmap.org/chef.git/commitdiff_plain/58eafe5641c36922c5d8422e1b0fcd6443a9b5be Enable smartd for directly connected disks and HP arrays --- diff --git a/cookbooks/hardware/recipes/default.rb b/cookbooks/hardware/recipes/default.rb index dd2d80157..2e99eb21d 100644 --- a/cookbooks/hardware/recipes/default.rb +++ b/cookbooks/hardware/recipes/default.rb @@ -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 index 000000000..3f793175a --- /dev/null +++ b/cookbooks/hardware/templates/default/smartd.conf.erb @@ -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 index 000000000..6526edefc --- /dev/null +++ b/cookbooks/hardware/templates/default/smartmontools.erb @@ -0,0 +1,4 @@ +# DO NOT EDIT - This file is being maintained by Chef + +# Enable smartd +start_smartd=yes