]> git.openstreetmap.org Git - chef.git/commitdiff
Add hardware cookbook
authorTom Hughes <tom@compton.nu>
Wed, 2 Oct 2013 21:43:48 +0000 (22:43 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 2 Oct 2013 21:43:48 +0000 (22:43 +0100)
cookbooks/hardware/README.rdoc [new file with mode: 0644]
cookbooks/hardware/attributes/default.rb [new file with mode: 0644]
cookbooks/hardware/metadata.rb [new file with mode: 0644]
cookbooks/hardware/recipes/default.rb [new file with mode: 0644]
cookbooks/hardware/templates/default/grub.erb [new file with mode: 0644]
cookbooks/hardware/templates/default/initramfs-mdadm.erb [new file with mode: 0644]
cookbooks/hardware/templates/default/tty.conf.erb [new file with mode: 0644]

diff --git a/cookbooks/hardware/README.rdoc b/cookbooks/hardware/README.rdoc
new file mode 100644 (file)
index 0000000..3de2ec7
--- /dev/null
@@ -0,0 +1,8 @@
+= DESCRIPTION:
+
+= REQUIREMENTS:
+
+= ATTRIBUTES:
+
+= USAGE:
+
diff --git a/cookbooks/hardware/attributes/default.rb b/cookbooks/hardware/attributes/default.rb
new file mode 100644 (file)
index 0000000..73940d9
--- /dev/null
@@ -0,0 +1,16 @@
+if node[:dmi] and node[:dmi][:system]
+  case dmi.system.manufacturer
+  when "HP"
+    if node[:lsb][:release].to_f <= 11.10
+      default[:apt][:sources] |= [ "proliant-support-pack" ]
+    else
+      default[:apt][:sources] |= [ "management-component-pack" ]
+    end
+  end
+end
+
+if node[:kernel] and node[:kernel][:modules]
+  if node[:kernel][:modules].include?("mpt2sas")
+    default[:apt][:sources] |= [ "hwraid" ]
+  end
+end
diff --git a/cookbooks/hardware/metadata.rb b/cookbooks/hardware/metadata.rb
new file mode 100644 (file)
index 0000000..8136046
--- /dev/null
@@ -0,0 +1,6 @@
+maintainer        "OpenStreetMap Administrators"
+maintainer_email  "admins@openstreetmap.org"
+license           "Apache 2.0"
+description       "Configures hardware"
+long_description  IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
+version           "1.0.0"
diff --git a/cookbooks/hardware/recipes/default.rb b/cookbooks/hardware/recipes/default.rb
new file mode 100644 (file)
index 0000000..e1b58c0
--- /dev/null
@@ -0,0 +1,146 @@
+#
+# Cookbook Name:: hardware
+# Recipe:: default
+#
+# Copyright 2012, OpenStreetMap Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+case node[:cpu][:"0"][:vendor_id]
+when "GenuineIntel"
+  package "intel-microcode"
+end
+
+if node[:dmi] and node[:dmi][:system]
+  case node[:dmi][:system][:manufacturer]
+  when "empty"
+    manufacturer = node[:dmi][:base_board][:manufacturer]
+    product = node[:dmi][:base_board][:product_name]
+  else
+    manufacturer = node[:dmi][:system][:manufacturer]
+    product = node[:dmi][:system][:product_name]
+  end
+else
+  manufacturer = "Unknown"
+  product = "Unknown"
+end
+
+case manufacturer
+when "HP"
+  package "hponcfg"
+  package "hp-health"
+  package "hpacucli"
+  unit = "1"
+  speed = "115200"
+when "TYAN"
+  unit = "0"
+  speed = "115200"
+when "TYAN Computer Corporation"
+  unit = "0"
+  speed = "115200"
+when "Supermicro"
+  case product
+  when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F"
+    unit = "1"
+    speed = "115200"
+  else
+    unit = "0"
+    speed = "115200"
+  end
+when "IBM"
+  unit = "0"
+  speed = "115200"
+end
+
+if manufacturer == "HP" and node[:lsb][:release].to_f > 11.10
+  git "/opt/hp/hp-legacy" do
+    action :sync
+    repository "git://chef.openstreetmap.org/hp-legacy.git"
+    user "root"
+    group "root"
+  end
+
+  link "/opt/hp/hp-health/bin/hpasmd" do
+    to "/opt/hp/hp-legacy/hpasmd"
+  end
+
+  link "/usr/lib/libhpasmintrfc.so.3.0" do
+    to "/opt/hp/hp-legacy/libhpasmintrfc.so.3.0"
+  end
+
+  link "/usr/lib/libhpasmintrfc.so.3" do
+    to "libhpasmintrfc.so.3.0"
+  end
+
+  link "/usr/lib/libhpasmintrfc.so" do
+    to "libhpasmintrfc.so.3.0"
+  end
+end
+
+unless unit.nil?
+  file "/etc/init/ttySttyS#{unit}.conf" do
+    action :delete
+  end
+
+  template "/etc/init/ttyS#{unit}.conf" do
+    source "tty.conf.erb"
+    owner "root"
+    group "root"
+    mode 0644
+    variables :unit => unit, :speed => speed
+  end
+
+  service "ttyS#{unit}" do
+    provider Chef::Provider::Service::Upstart
+    action [ :enable, :start ]
+    supports :status => true, :restart => true, :reload => false
+    subscribes :restart, resources(:template => "/etc/init/ttyS#{unit}.conf")
+  end
+end
+
+if File.exist?("/etc/default/grub")
+  execute "update-grub" do
+    action :nothing
+    command "/usr/sbin/update-grub"
+  end
+
+  template "/etc/default/grub" do
+    source "grub.erb"
+    owner "root"
+    group "root"
+    mode 0644
+    variables :unit => unit, :speed => speed
+    notifies :run, resources(:execute => "update-grub")
+  end
+end
+
+execute "update-initramfs" do
+  action :nothing
+  command "update-initramfs -u -k all"
+  user "root"
+  group "root"
+end
+
+template "/etc/initramfs-tools/conf.d/mdadm" do
+  source "initramfs-mdadm.erb"
+  owner "root"
+  group "root"
+  mode 0644
+  notifies :run, "execute[update-initramfs]"
+end
+
+if node[:kernel][:modules].include?("mpt2sas")
+  package "sas2ircu"
+  package "sas2ircu-status"
+end
diff --git a/cookbooks/hardware/templates/default/grub.erb b/cookbooks/hardware/templates/default/grub.erb
new file mode 100644 (file)
index 0000000..49343e9
--- /dev/null
@@ -0,0 +1,40 @@
+# DO NOT EDIT - This file is being maintained by Chef
+
+# Boot the first entry by default
+GRUB_DEFAULT="0"
+
+# Wait two seconds before booting the default entry
+GRUB_TIMEOUT="2"
+
+# Display the menu straight away
+GRUB_HIDDEN_TIMEOUT="0"
+GRUB_HIDDEN_TIMEOUT_QUIET="true"
+
+# Set the distribution name
+GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
+
+# Arguments to add to the kernel command line (all entries)
+<% if @unit.nil? -%>
+GRUB_CMDLINE_LINUX="nomodeset"
+<% else -%>
+GRUB_CMDLINE_LINUX="console=tty0 console=ttyS<%= @unit %>,115200n8 nomodeset"
+<% end -%>
+
+# Arguments to add to the kernel command line (except recovery entries)
+GRUB_CMDLINE_LINUX_DEFAULT=""
+
+<% if @unit.nil? -%>
+# Send console output to the screen
+GRUB_TERMINAL="console"
+<% else -%>
+<% if node[:lsb][:release].to_f >= 12.04 -%>
+# Send console output to the screen and serial port
+GRUB_TERMINAL="console serial"
+<% else -%>
+# Send console output to the serial port
+GRUB_TERMINAL="serial"
+<% end -%>
+
+# Configure the serial console
+GRUB_SERIAL_COMMAND="serial --speed=<%= @speed %> --unit=<%= @unit %> --word=8 --parity=no --stop=1"
+<% end -%>
diff --git a/cookbooks/hardware/templates/default/initramfs-mdadm.erb b/cookbooks/hardware/templates/default/initramfs-mdadm.erb
new file mode 100644 (file)
index 0000000..4ac2de5
--- /dev/null
@@ -0,0 +1,20 @@
+# DO NOT EDIT - This file is being maintained by Chef
+
+# mdadm boot_degraded configuration
+#
+# You can run 'dpkg-reconfigure mdadm' to modify the values in this file, if
+# you want. You can also change the values here and changes will be preserved.
+# Do note that only the values are preserved; the rest of the file is
+# rewritten.
+#
+# BOOT_DEGRADED:
+# Do you want to boot your system if a RAID providing your root filesystem
+# becomes degraded?
+#
+# Running a system with a degraded RAID could result in permanent data loss
+# if it suffers another hardware fault.
+#
+# However, you might answer "yes" if this system is a server, expected to
+# tolerate hardware faults and boot unattended.
+
+BOOT_DEGRADED=true
diff --git a/cookbooks/hardware/templates/default/tty.conf.erb b/cookbooks/hardware/templates/default/tty.conf.erb
new file mode 100644 (file)
index 0000000..896e8c3
--- /dev/null
@@ -0,0 +1,12 @@
+# DO NOT EDIT - This file is being maintained by Chef
+
+# ttyS<%= @unit %> - getty
+#
+# This service maintains a getty on ttyS<%= @unit %> from the point the system is
+# started until it is shut down again.
+
+start on stopped rc RUNLEVEL=[2345]
+stop on runlevel [!2345]
+
+respawn
+exec /sbin/getty -L <%= @speed %> ttyS<%= @unit %> vt102