]> git.openstreetmap.org Git - chef.git/blob - cookbooks/hardware/recipes/default.rb
ad64ae56ba143de40a39e709415b213d231a888e
[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, resources(: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, resources(: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 tools_packages = []
145 status_packages = []
146
147 node[:kernel][:modules].each_key do |modname|
148   case modname
149   when "cciss"
150     tools_packages << "hpacucli"
151     status_packages << "cciss-vol-status"
152   when "hpsa"
153     tools_packages << "hpacucli"
154   when "mptsas"
155     tools_packages << "lsiutil"
156     status_packages << "mpt-status"
157   when "mpt2sas"
158     tools_packages << "sas2ircu"
159     status_packages << "sas2ircu-status"
160   when "megaraid_mm"
161     tools_packages << "megactl"
162     status_packages << "megaraid-status"
163   when "megaraid_sas"
164     tools_packages << "megacli"
165     status_packages << "megaclisas-status"
166   when "aacraid"
167     tools_packages << "arcconf"
168     status_packages << "aacraid-status"
169   end
170 end
171
172 ["hpacucli", "lsiutil", "sas2ircu", "megactl", "megacli", "arcconf"].each do |tools_package|
173   if tools_packages.include?(tools_package)
174     package tools_package
175   else
176     package tools_package do
177       action :purge
178     end
179   end
180 end
181
182 ["cciss-vol-status", "mpt-status", "sas2ircu-status", "megaraid-status", "megaclisas-status", "aacraid-status"].each do |status_package|
183   if status_packages.include?(status_package)
184     package status_package
185
186     template "/etc/default/#{status_package}d" do
187       source "raid.default.erb"
188       owner "root"
189       group "root"
190       mode 0644
191     end
192
193     service "#{status_package}d" do
194       action [ :start, :enable ]
195       supports :status => false, :restart => true, :reload => false
196       subscribes :restart, "template[/etc/default/#{status_package}d]"
197     end
198   else
199     package status_package do
200       action :purge
201     end
202
203     file "/etc/default/#{status_package}d" do
204       action :delete
205     end
206   end
207 end