From eee918711444ec8414ac795345e5c6b38864118e Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 2 Oct 2013 22:43:48 +0100 Subject: [PATCH] Add hardware cookbook --- cookbooks/hardware/README.rdoc | 8 + cookbooks/hardware/attributes/default.rb | 16 ++ cookbooks/hardware/metadata.rb | 6 + cookbooks/hardware/recipes/default.rb | 146 ++++++++++++++++++ cookbooks/hardware/templates/default/grub.erb | 40 +++++ .../templates/default/initramfs-mdadm.erb | 20 +++ .../hardware/templates/default/tty.conf.erb | 12 ++ 7 files changed, 248 insertions(+) create mode 100644 cookbooks/hardware/README.rdoc create mode 100644 cookbooks/hardware/attributes/default.rb create mode 100644 cookbooks/hardware/metadata.rb create mode 100644 cookbooks/hardware/recipes/default.rb create mode 100644 cookbooks/hardware/templates/default/grub.erb create mode 100644 cookbooks/hardware/templates/default/initramfs-mdadm.erb create mode 100644 cookbooks/hardware/templates/default/tty.conf.erb diff --git a/cookbooks/hardware/README.rdoc b/cookbooks/hardware/README.rdoc new file mode 100644 index 000000000..3de2ec7a3 --- /dev/null +++ b/cookbooks/hardware/README.rdoc @@ -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 index 000000000..73940d9b7 --- /dev/null +++ b/cookbooks/hardware/attributes/default.rb @@ -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 index 000000000..813604617 --- /dev/null +++ b/cookbooks/hardware/metadata.rb @@ -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 index 000000000..e1b58c0f3 --- /dev/null +++ b/cookbooks/hardware/recipes/default.rb @@ -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 index 000000000..49343e9b0 --- /dev/null +++ b/cookbooks/hardware/templates/default/grub.erb @@ -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 index 000000000..4ac2de52d --- /dev/null +++ b/cookbooks/hardware/templates/default/initramfs-mdadm.erb @@ -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 index 000000000..896e8c3df --- /dev/null +++ b/cookbooks/hardware/templates/default/tty.conf.erb @@ -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 -- 2.43.2