]> git.openstreetmap.org Git - chef.git/blob - cookbooks/hardware/recipes/default.rb
Install irqbalance + set policy hint ignore on 12.10 and above.
[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", "X9DRW"
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 package "irqbalance"
149 if node[:lsb][:release].to_f >= 12.10
150     template "/etc/default/irqbalance" do
151       source "irqbalance.erb"
152       owner "root"
153       group "root"
154       mode 0644
155     end
156
157     service "irqbalance" do
158       action [ :start, :enable ]
159       supports :status => false, :restart => true, :reload => false
160       subscribes :restart, "template[/etc/default/irqbalance]"
161     end
162 end
163
164 tools_packages = []
165 status_packages = {}
166
167 node[:kernel][:modules].each_key do |modname|
168   case modname
169   when "cciss"
170     tools_packages << "hpacucli"
171     status_packages["cciss-vol-status"] ||= []
172   when "hpsa"
173     tools_packages << "hpacucli"
174     status_packages["cciss-vol-status"] ||= []
175   when "mptsas"
176     tools_packages << "lsiutil"
177     #status_packages["mpt-status"] ||= []
178   when "mpt2sas"
179     tools_packages << "sas2ircu"
180     status_packages["sas2ircu-status"] ||= []
181   when "megaraid_mm"
182     tools_packages << "megactl"
183     status_packages["megaraid-status"] ||= []
184   when "megaraid_sas"
185     tools_packages << "megacli"
186     status_packages["megaclisas-status"] ||= []
187   when "aacraid"
188     tools_packages << "arcconf"
189     status_packages["aacraid-status"] ||= []
190   end
191 end
192
193 node[:block_device].each do |name,attributes|
194   if attributes[:vendor] == "HP" and attributes[:model] == "LOGICAL VOLUME"
195     if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
196       status_packages["cciss-vol-status"] |= [ "cciss/#{$1}d0" ]
197     else
198       Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
199         status_packages["cciss-vol-status"] |= [ File.basename(sg) ]
200       end
201     end
202   end
203 end
204
205 ["hpacucli", "lsiutil", "sas2ircu", "megactl", "megacli", "arcconf"].each do |tools_package|
206   if tools_packages.include?(tools_package)
207     package tools_package
208   else
209     package tools_package do
210       action :purge
211     end
212   end
213 end
214
215 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
216   if status_packages.include?(status_package)
217     package status_package
218
219     template "/etc/default/#{status_package}d" do
220       source "raid.default.erb"
221       owner "root"
222       group "root"
223       mode 0644
224       variables :devices => status_packages[status_package]
225     end
226
227     service "#{status_package}d" do
228       action [ :start, :enable ]
229       supports :status => false, :restart => true, :reload => false
230       subscribes :restart, "template[/etc/default/#{status_package}d]"
231     end
232   else
233     package status_package do
234       action :purge
235     end
236
237     file "/etc/default/#{status_package}d" do
238       action :delete
239     end
240   end
241 end