]> git.openstreetmap.org Git - chef.git/blob - cookbooks/hardware/recipes/default.rb
Disable installation of Intel SSD tool
[chef.git] / cookbooks / hardware / recipes / default.rb
1 #
2 # Cookbook:: 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 #     https://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 include_recipe "apt"
21 include_recipe "git"
22 include_recipe "munin"
23 include_recipe "prometheus"
24 include_recipe "sysfs"
25 include_recipe "tools"
26
27 ohai_plugin "hardware" do
28   template "ohai.rb.erb"
29 end
30
31 case node[:cpu][:"0"][:vendor_id]
32 when "GenuineIntel"
33   package "intel-microcode"
34 when "AuthenticAMD"
35   package "amd64-microcode"
36 end
37
38 if node[:dmi] && node[:dmi][:system]
39   case node[:dmi][:system][:manufacturer]
40   when "empty"
41     manufacturer = node[:dmi][:base_board][:manufacturer]
42     product = node[:dmi][:base_board][:product_name]
43   else
44     manufacturer = node[:dmi][:system][:manufacturer]
45     product = node[:dmi][:system][:product_name]
46   end
47 else
48   manufacturer = "Unknown"
49   product = "Unknown"
50 end
51
52 units = []
53
54 if node[:roles].include?("bytemark") || node[:roles].include?("exonetric") || node[:roles].include?("prgmr")
55   units << "0"
56 end
57
58 case manufacturer
59 when "HP"
60   package "hponcfg"
61
62   package "hp-health" do
63     action :install
64     notifies :restart, "service[hp-health]"
65   end
66
67   service "hp-health" do
68     action [:enable, :start]
69     supports :status => true, :restart => true
70   end
71
72   if product.end_with?("Gen8", "Gen9")
73     package "hp-ams" do
74       action :install
75       notifies :restart, "service[hp-ams]"
76     end
77
78     service "hp-ams" do
79       action [:enable, :start]
80       supports :status => true, :restart => true
81     end
82   end
83
84   units << "1"
85 when "TYAN"
86   units << "0"
87 when "TYAN Computer Corporation"
88   units << "0"
89 when "Supermicro"
90   units << "1"
91 when "IBM"
92   units << "0"
93 when "VMware, Inc."
94   package "open-vm-tools"
95
96   # Remove timeSync plugin completely
97   # https://github.com/vmware/open-vm-tools/issues/302
98   file "/usr/lib/open-vm-tools/plugins/vmsvc/libtimeSync.so" do
99     action :delete
100     notifies :restart, "service[open-vm-tools]"
101   end
102
103   # Attempt to tell Host we are not interested in timeSync
104   execute "vmware-toolbox-cmd-timesync-disable" do
105     command "/usr/bin/vmware-toolbox-cmd timesync disable"
106     ignore_failure true
107   end
108
109   service "open-vm-tools" do
110     action [:enable, :start]
111     supports :status => true, :restart => true
112   end
113 end
114
115 units.sort.uniq.each do |unit|
116   service "serial-getty@ttyS#{unit}" do
117     action [:enable, :start]
118   end
119 end
120
121 # if we need a different / special kernel version to make the hardware
122 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
123 # ensure that we have the package installed. the grub template will
124 # make sure that this is the default on boot.
125 if node[:hardware][:grub][:kernel]
126   kernel_version = node[:hardware][:grub][:kernel]
127
128   package "linux-image-#{kernel_version}-generic"
129   package "linux-image-extra-#{kernel_version}-generic"
130   package "linux-headers-#{kernel_version}-generic"
131   package "linux-tools-#{kernel_version}-generic"
132
133   boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
134   boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
135   grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
136 else
137   grub_entry = "0"
138 end
139
140 if File.exist?("/etc/default/grub")
141   execute "update-grub" do
142     action :nothing
143     command "/usr/sbin/update-grub"
144     not_if { ENV["TEST_KITCHEN"] }
145   end
146
147   template "/etc/default/grub" do
148     source "grub.erb"
149     owner "root"
150     group "root"
151     mode "644"
152     variables :units => units, :entry => grub_entry
153     notifies :run, "execute[update-grub]"
154   end
155 end
156
157 execute "update-initramfs" do
158   action :nothing
159   command "update-initramfs -u -k all"
160   user "root"
161   group "root"
162 end
163
164 template "/etc/initramfs-tools/conf.d/mdadm" do
165   source "initramfs-mdadm.erb"
166   owner "root"
167   group "root"
168   mode "644"
169   notifies :run, "execute[update-initramfs]"
170 end
171
172 package "haveged"
173 service "haveged" do
174   action [:enable, :start]
175 end
176
177 if node[:kernel][:modules].include?("ipmi_si")
178   package "ipmitool"
179   package "freeipmi-tools"
180
181   prometheus_exporter "ipmi" do
182     port 9290
183   end
184 end
185
186 package "irqbalance"
187
188 service "irqbalance" do
189   action [:start, :enable]
190   supports :status => false, :restart => true, :reload => false
191 end
192
193 # Link Layer Discovery Protocol Daemon
194 package "lldpd"
195 service "lldpd" do
196   action [:start, :enable]
197   supports :status => true, :restart => true, :reload => true
198 end
199
200 tools_packages = []
201 status_packages = {}
202
203 if node[:virtualization][:role] != "guest" ||
204    (node[:virtualization][:system] != "lxc" &&
205     node[:virtualization][:system] != "lxd" &&
206     node[:virtualization][:system] != "openvz")
207
208   node[:kernel][:modules].each_key do |modname|
209     case modname
210     when "cciss"
211       tools_packages << "ssacli"
212       status_packages["cciss-vol-status"] ||= []
213     when "hpsa"
214       tools_packages << "ssacli"
215       status_packages["cciss-vol-status"] ||= []
216     when "mptsas"
217       tools_packages << "lsiutil"
218       status_packages["mpt-status"] ||= []
219     when "mpt2sas", "mpt3sas"
220       tools_packages << "sas2ircu"
221       status_packages["sas2ircu-status"] ||= []
222     when "megaraid_mm"
223       tools_packages << "megactl"
224       status_packages["megaraid-status"] ||= []
225     when "megaraid_sas"
226       tools_packages << "megacli"
227       status_packages["megaclisas-status"] ||= []
228     when "aacraid"
229       tools_packages << "arcconf"
230       status_packages["aacraid-status"] ||= []
231     when "arcmsr"
232       tools_packages << "areca"
233     end
234   end
235
236   node[:block_device].each do |name, attributes|
237     next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
238
239     if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
240       status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
241     else
242       Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
243         status_packages["cciss-vol-status"] |= [File.basename(sg)]
244       end
245     end
246   end
247 end
248
249 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
250   if tools_packages.include?(tools_package)
251     package tools_package
252   else
253     package tools_package do
254       action :purge
255     end
256   end
257 end
258
259 if tools_packages.include?("areca")
260   include_recipe "git"
261
262   git "/opt/areca" do
263     action :sync
264     repository "https://git.openstreetmap.org/private/areca.git"
265     depth 1
266     user "root"
267     group "root"
268     not_if { ENV["TEST_KITCHEN"] }
269   end
270 else
271   directory "/opt/areca" do
272     action :delete
273     recursive true
274   end
275 end
276
277 if status_packages.include?("cciss-vol-status")
278   template "/usr/local/bin/cciss-vol-statusd" do
279     source "cciss-vol-statusd.erb"
280     owner "root"
281     group "root"
282     mode "755"
283     notifies :restart, "service[cciss-vol-statusd]"
284   end
285
286   systemd_service "cciss-vol-statusd" do
287     description "Check cciss_vol_status values in the background"
288     exec_start "/usr/local/bin/cciss-vol-statusd"
289     private_tmp true
290     protect_system "full"
291     protect_home true
292     no_new_privileges true
293     notifies :restart, "service[cciss-vol-statusd]"
294   end
295 else
296   systemd_service "cciss-vol-statusd" do
297     action :delete
298   end
299
300   template "/usr/local/bin/cciss-vol-statusd" do
301     action :delete
302   end
303 end
304
305 %w[cciss-vol-status mpt-status sas2ircu-status megaraid-status megaclisas-status aacraid-status].each do |status_package|
306   if status_packages.include?(status_package)
307     package status_package
308
309     template "/etc/default/#{status_package}d" do
310       source "raid.default.erb"
311       owner "root"
312       group "root"
313       mode "644"
314       variables :devices => status_packages[status_package]
315     end
316
317     service "#{status_package}d" do
318       action [:start, :enable]
319       supports :status => false, :restart => true, :reload => false
320       subscribes :restart, "template[/etc/default/#{status_package}d]"
321     end
322   else
323     package status_package do
324       action :purge
325     end
326
327     file "/etc/default/#{status_package}d" do
328       action :delete
329     end
330   end
331 end
332
333 disks = if node[:hardware][:disk]
334           node[:hardware][:disk][:disks]
335         else
336           []
337         end
338
339 # intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
340
341 # nvmes = if node[:hardware][:pci]
342 #           node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
343 #         else
344 #           []
345 #         end
346
347 # intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
348
349 # if !intel_ssds.empty? || !intel_nvmes.empty?
350 #   package "unzip"
351
352 #   intel_ssd_tool_version = "3.0.27"
353 #   intel_ssd_package_version = "#{intel_ssd_tool_version}.400-1"
354
355 #   remote_file "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
356 #     source "https://downloadmirror.intel.com/30065/eng/Intel_SSD_DCT_#{intel_ssd_tool_version}_Linux.zip"
357 #   end
358
359 #   execute "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
360 #     command "unzip Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip isdct_#{intel_ssd_package_version}_amd64.deb"
361 #     cwd Chef::Config[:file_cache_path]
362 #     user "root"
363 #     group "root"
364 #     not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/isdct_#{intel_ssd_package_version}_amd64.deb") }
365 #   end
366
367 #   dpkg_package "isdct" do
368 #     version "#{intel_ssd_package_version}"
369 #     source "#{Chef::Config[:file_cache_path]}/isdct_#{intel_ssd_package_version}_amd64.deb"
370 #   end
371 # end
372
373 disks = disks.map do |disk|
374   next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
375
376   if disk[:smart_device]
377     controller = node[:hardware][:disk][:controllers][disk[:controller]]
378
379     if controller && controller[:device]
380       device = controller[:device].sub("/dev/", "")
381       smart = disk[:smart_device]
382
383       if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
384         array = node[:hardware][:disk][:arrays][disk[:arrays].first]
385         munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
386       elsif smart =~ /^.*,(\d+)$/
387         munin = "#{device}-#{Regexp.last_match(1)}"
388       elsif smart =~ %r{^.*,(\d+)/(\d+)$}
389         munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
390       end
391     elsif disk[:device]
392       device = disk[:device].sub("/dev/", "")
393       smart = disk[:smart_device]
394
395       if smart =~ /^.*,(\d+),(\d+),(\d+)$/
396         munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
397       end
398     end
399   elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
400     device = Regexp.last_match(1)
401     munin = device
402   elsif disk[:device]
403     device = disk[:device].sub("/dev/", "")
404     munin = device
405   end
406
407   next if device.nil?
408
409   Hash[
410     :device => device,
411     :smart => smart,
412     :munin => munin,
413     :hddtemp => munin.tr("-:", "_")
414   ]
415 end
416
417 disks = disks.compact.uniq
418
419 if disks.count.positive?
420   package "smartmontools"
421
422   template "/etc/cron.daily/update-smart-drivedb" do
423     source "update-smart-drivedb.erb"
424     owner "root"
425     group "root"
426     mode "755"
427   end
428
429   template "/usr/local/bin/smartd-mailer" do
430     source "smartd-mailer.erb"
431     owner "root"
432     group "root"
433     mode "755"
434   end
435
436   template "/etc/smartd.conf" do
437     source "smartd.conf.erb"
438     owner "root"
439     group "root"
440     mode "644"
441     variables :disks => disks
442   end
443
444   template "/etc/default/smartmontools" do
445     source "smartmontools.erb"
446     owner "root"
447     group "root"
448     mode "644"
449   end
450
451   service "smartmontools" do
452     action [:enable, :start]
453     subscribes :reload, "template[/etc/smartd.conf]"
454     subscribes :restart, "template[/etc/default/smartmontools]"
455   end
456
457   template "/etc/prometheus/collectors/smart.devices" do
458     source "smart.devices.erb"
459     owner "root"
460     group "root"
461     mode "644"
462     variables :disks => disks
463   end
464
465   prometheus_collector "smart" do
466     interval "15m"
467   end
468
469   # Don't try and do munin monitoring of disks behind
470   # an Areca controller as they only allow one thing to
471   # talk to the controller at a time and smartd will
472   # throw errors if it clashes with munin
473   disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
474
475   disks.each do |disk|
476     munin_plugin "smart_#{disk[:munin]}" do
477       target "smart_"
478       conf "munin.smart.erb"
479       conf_variables :disk => disk
480     end
481   end
482 else
483   service "smartd" do
484     action [:stop, :disable]
485   end
486 end
487
488 if disks.count.positive?
489   munin_plugin "hddtemp_smartctl" do
490     conf "munin.hddtemp.erb"
491     conf_variables :disks => disks
492   end
493 else
494   munin_plugin "hddtemp_smartctl" do
495     action :delete
496     conf "munin.hddtemp.erb"
497   end
498 end
499
500 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
501           disks.map { |d| "smart_#{d[:munin]}" }
502
503 plugins.each do |plugin|
504   munin_plugin plugin do
505     action :delete
506     conf "munin.smart.erb"
507   end
508 end
509
510 if File.exist?("/etc/mdadm/mdadm.conf")
511   mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
512     line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
513
514     line
515   end
516
517   file "/etc/mdadm/mdadm.conf" do
518     owner "root"
519     group "root"
520     mode "644"
521     content mdadm_conf
522   end
523
524   service "mdadm" do
525     action :nothing
526     subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
527   end
528 end
529
530 template "/etc/modules" do
531   source "modules.erb"
532   owner "root"
533   group "root"
534   mode "644"
535 end
536
537 service "kmod" do
538   action :nothing
539   subscribes :start, "template[/etc/modules]"
540 end
541
542 if node[:hardware][:watchdog]
543   package "watchdog"
544
545   template "/etc/default/watchdog" do
546     source "watchdog.erb"
547     owner "root"
548     group "root"
549     mode "644"
550     variables :module => node[:hardware][:watchdog]
551   end
552
553   service "watchdog" do
554     action [:enable, :start]
555   end
556 end
557
558 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
559   package "lm-sensors"
560
561   Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
562     cpu = File.basename(coretemp).sub("coretemp.", "").to_i
563     chip = format("coretemp-isa-%04d", cpu)
564
565     temps = if File.exist?("#{coretemp}/name")
566               Dir.glob("#{coretemp}/temp*_input").map do |temp|
567                 File.basename(temp).sub("temp", "").sub("_input", "").to_i
568               end.sort
569             else
570               Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
571                 File.basename(temp).sub("temp", "").sub("_input", "").to_i
572               end.sort
573             end
574
575     if temps.first == 1
576       node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
577       temps.shift
578     end
579
580     temps.each_with_index do |temp, index|
581       node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
582     end
583   end
584
585   execute "/etc/sensors.d/chef.conf" do
586     action :nothing
587     command "/usr/bin/sensors -s"
588     user "root"
589     group "root"
590   end
591
592   template "/etc/sensors.d/chef.conf" do
593     source "sensors.conf.erb"
594     owner "root"
595     group "root"
596     mode "644"
597     notifies :run, "execute[/etc/sensors.d/chef.conf]"
598   end
599 end
600
601 if node[:hardware][:shm_size]
602   execute "remount-dev-shm" do
603     action :nothing
604     command "/bin/mount -o remount /dev/shm"
605     user "root"
606     group "root"
607   end
608
609   mount "/dev/shm" do
610     action :enable
611     device "tmpfs"
612     fstype "tmpfs"
613     options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
614     notifies :run, "execute[remount-dev-shm]"
615   end
616 end