]> git.openstreetmap.org Git - chef.git/blob - cookbooks/hardware/recipes/default.rb
Install ipmitool on machines with the ipmi_si module loaded
[chef.git] / cookbooks / hardware / recipes / default.rb
1 #
2 # Cookbook Name:: hardware
3 # Recipe:: default
4 #
5 # Copyright 2012, OpenStreetMap Foundation
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 case node[:cpu][:"0"][:vendor_id]
21 when "GenuineIntel"
22   package "intel-microcode"
23 end
24
25 if node[:dmi] and node[:dmi][:system]
26   case node[:dmi][:system][:manufacturer]
27   when "empty"
28     manufacturer = node[:dmi][:base_board][:manufacturer]
29     product = node[:dmi][:base_board][:product_name]
30   else
31     manufacturer = node[:dmi][:system][:manufacturer]
32     product = node[:dmi][:system][:product_name]
33   end
34 else
35   manufacturer = "Unknown"
36   product = "Unknown"
37 end
38
39 case manufacturer
40 when "HP"
41   package "hponcfg"
42   package "hp-health"
43   unit = "1"
44   speed = "115200"
45 when "TYAN"
46   unit = "0"
47   speed = "115200"
48 when "TYAN Computer Corporation"
49   unit = "0"
50   speed = "115200"
51 when "Supermicro"
52   case product
53   when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F"
54     unit = "1"
55     speed = "115200"
56   else
57     unit = "0"
58     speed = "115200"
59   end
60 when "IBM"
61   unit = "0"
62   speed = "115200"
63 end
64
65 if manufacturer == "HP" and node[:lsb][:release].to_f > 11.10
66   include_recipe "git"
67
68   git "/opt/hp/hp-legacy" do
69     action :sync
70     repository "git://chef.openstreetmap.org/hp-legacy.git"
71     user "root"
72     group "root"
73   end
74
75   link "/opt/hp/hp-health/bin/hpasmd" do
76     to "/opt/hp/hp-legacy/hpasmd"
77   end
78
79   link "/usr/lib/libhpasmintrfc.so.3.0" do
80     to "/opt/hp/hp-legacy/libhpasmintrfc.so.3.0"
81   end
82
83   link "/usr/lib/libhpasmintrfc.so.3" do
84     to "libhpasmintrfc.so.3.0"
85   end
86
87   link "/usr/lib/libhpasmintrfc.so" do
88     to "libhpasmintrfc.so.3.0"
89   end
90 end
91
92 unless unit.nil?
93   file "/etc/init/ttySttyS#{unit}.conf" do
94     action :delete
95   end
96
97   template "/etc/init/ttyS#{unit}.conf" do
98     source "tty.conf.erb"
99     owner "root"
100     group "root"
101     mode 0644
102     variables :unit => unit, :speed => speed
103   end
104
105   service "ttyS#{unit}" do
106     provider Chef::Provider::Service::Upstart
107     action [ :enable, :start ]
108     supports :status => true, :restart => true, :reload => false
109     subscribes :restart, "template[/etc/init/ttyS#{unit}.conf]"
110   end
111 end
112
113 if File.exist?("/etc/default/grub")
114   execute "update-grub" do
115     action :nothing
116     command "/usr/sbin/update-grub"
117   end
118
119   template "/etc/default/grub" do
120     source "grub.erb"
121     owner "root"
122     group "root"
123     mode 0644
124     variables :unit => unit, :speed => speed
125     notifies :run, "execute[update-grub]"
126   end
127 end
128
129 execute "update-initramfs" do
130   action :nothing
131   command "update-initramfs -u -k all"
132   user "root"
133   group "root"
134 end
135
136 template "/etc/initramfs-tools/conf.d/mdadm" do
137   source "initramfs-mdadm.erb"
138   owner "root"
139   group "root"
140   mode 0644
141   notifies :run, "execute[update-initramfs]"
142 end
143
144 if node[:kernel][:modules].include?("ipmi_si")
145   package "ipmitool"
146 end
147
148 tools_packages = []
149 status_packages = {}
150
151 node[:kernel][:modules].each_key do |modname|
152   case modname
153   when "cciss"
154     tools_packages << "hpacucli"
155     status_packages["cciss-vol-status"] ||= []
156   when "hpsa"
157     tools_packages << "hpacucli"
158     status_packages["cciss-vol-status"] ||= []
159   when "mptsas"
160     tools_packages << "lsiutil"
161     #status_packages["mpt-status"] ||= []
162   when "mpt2sas"
163     tools_packages << "sas2ircu"
164     status_packages["sas2ircu-status"] ||= []
165   when "megaraid_mm"
166     tools_packages << "megactl"
167     status_packages["megaraid-status"] ||= []
168   when "megaraid_sas"
169     tools_packages << "megacli"
170     status_packages["megaclisas-status"] ||= []
171   when "aacraid"
172     tools_packages << "arcconf"
173     status_packages["aacraid-status"] ||= []
174   end
175 end
176
177 node[:block_device].each do |name,attributes|
178   if attributes[:vendor] == "HP" and attributes[:model] == "LOGICAL VOLUME"
179     if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
180       status_packages["cciss-vol-status"] |= [ "cciss/#{$1}d0" ]
181     else
182       Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
183         status_packages["cciss-vol-status"] |= [ File.basename(sg) ]
184       end
185     end
186   end
187 end
188
189 ["hpacucli", "lsiutil", "sas2ircu", "megactl", "megacli", "arcconf"].each do |tools_package|
190   if tools_packages.include?(tools_package)
191     package tools_package
192   else
193     package tools_package do
194       action :purge
195     end
196   end
197 end
198
199 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
200   if status_packages.include?(status_package)
201     package status_package
202
203     template "/etc/default/#{status_package}d" do
204       source "raid.default.erb"
205       owner "root"
206       group "root"
207       mode 0644
208       variables :devices => status_packages[status_package]
209     end
210
211     service "#{status_package}d" do
212       action [ :start, :enable ]
213       supports :status => false, :restart => true, :reload => false
214       subscribes :restart, "template[/etc/default/#{status_package}d]"
215     end
216   else
217     package status_package do
218       action :purge
219     end
220
221     file "/etc/default/#{status_package}d" do
222       action :delete
223     end
224   end
225 end