5 # Copyright:: 2012, OpenStreetMap Foundation
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
11 # https://www.apache.org/licenses/LICENSE-2.0
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.
21 include_recipe "munin"
22 include_recipe "prometheus"
23 include_recipe "sysfs"
24 include_recipe "tools"
26 ohai_plugin "hardware" do
27 template "ohai.rb.erb"
30 case node[:cpu][:"0"][:vendor_id]
32 package "intel-microcode"
34 package "amd64-microcode"
37 if node[:dmi] && node[:dmi][:system]
38 case node[:dmi][:system][:manufacturer]
40 manufacturer = node[:dmi][:base_board][:manufacturer]
41 product = node[:dmi][:base_board][:product_name]
43 manufacturer = node[:dmi][:system][:manufacturer]
44 product = node[:dmi][:system][:product_name]
47 manufacturer = "Unknown"
53 if node[:roles].include?("bytemark") || node[:roles].include?("exonetric") || node[:roles].include?("prgmr")
59 include_recipe "apt::management-component-pack"
63 execute "update-ilo" do
65 command "/usr/sbin/hponcfg -f /etc/ilo-defaults.xml"
68 template "/etc/ilo-defaults.xml" do
69 source "ilo-defaults.xml.erb"
73 notifies :run, "execute[update-ilo]"
76 package "hp-health" do
78 notifies :restart, "service[hp-health]"
79 only_if { node[:lsb][:release].to_f < 22.04 }
82 service "hp-health" do
83 action [:enable, :start]
84 supports :status => true, :restart => true
85 only_if { node[:lsb][:release].to_f < 22.04 }
88 if product.end_with?("Gen8", "Gen9")
91 notifies :restart, "service[hp-ams]"
95 action [:enable, :start]
96 supports :status => true, :restart => true
98 elsif product.end_with?("Gen10")
101 notifies :restart, "service[amsd]"
105 action [:enable, :start]
106 supports :status => true, :restart => true
110 units << if product.end_with?("Gen10")
117 when "TYAN Computer Corporation"
124 package "open-vm-tools"
126 # Remove timeSync plugin completely
127 # https://github.com/vmware/open-vm-tools/issues/302
128 file "/usr/lib/open-vm-tools/plugins/vmsvc/libtimeSync.so" do
130 notifies :restart, "service[open-vm-tools]"
133 # Attempt to tell Host we are not interested in timeSync
134 execute "vmware-toolbox-cmd-timesync-disable" do
135 command "/usr/bin/vmware-toolbox-cmd timesync disable"
139 service "open-vm-tools" do
140 action [:enable, :start]
141 supports :status => true, :restart => true
145 units.sort.uniq.each do |unit|
146 service "serial-getty@ttyS#{unit}" do
147 action [:enable, :start]
151 # if we need a different / special kernel version to make the hardware
152 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
153 # ensure that we have the package installed. the grub template will
154 # make sure that this is the default on boot.
155 if node[:hardware][:grub][:kernel]
156 kernel_version = node[:hardware][:grub][:kernel]
158 package "linux-image-#{kernel_version}-generic"
159 package "linux-image-extra-#{kernel_version}-generic"
160 package "linux-headers-#{kernel_version}-generic"
161 package "linux-tools-#{kernel_version}-generic"
163 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
164 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
165 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
170 if File.exist?("/etc/default/grub")
171 execute "update-grub" do
173 command "/usr/sbin/update-grub"
177 template "/etc/default/grub" do
182 variables :units => units, :entry => grub_entry
183 notifies :run, "execute[update-grub]"
187 execute "update-initramfs" do
189 command "update-initramfs -u -k all"
194 template "/etc/initramfs-tools/conf.d/mdadm" do
195 source "initramfs-mdadm.erb"
199 notifies :run, "execute[update-initramfs]"
204 action [:enable, :start]
207 if node[:kernel][:modules].include?("ipmi_si")
209 package "freeipmi-tools"
211 template "/etc/prometheus/ipmi_local.yml" do
212 source "ipmi_local.yml.erb"
218 prometheus_exporter "ipmi" do
220 options "--config.file=/etc/prometheus/ipmi_local.yml"
221 subscribes :restart, "template[/etc/prometheus/ipmi_local.yml]"
227 service "irqbalance" do
228 action [:start, :enable]
229 supports :status => false, :restart => true, :reload => false
235 action [:start, :enable]
236 supports :status => true, :restart => true, :reload => true
239 ohai_plugin "lldp" do
240 template "lldp.rb.erb"
248 service "rasdaemon" do
249 action [:enable, :start]
252 prometheus_exporter "rasdaemon" do
259 if node[:virtualization][:role] != "guest" ||
260 (node[:virtualization][:system] != "lxc" &&
261 node[:virtualization][:system] != "lxd" &&
262 node[:virtualization][:system] != "openvz")
264 node[:kernel][:modules].each_key do |modname|
267 tools_packages << "ssacli"
268 status_packages["cciss-vol-status"] ||= []
270 tools_packages << "ssacli"
271 status_packages["cciss-vol-status"] ||= []
273 tools_packages << "lsiutil"
274 status_packages["mpt-status"] ||= []
275 when "mpt2sas", "mpt3sas"
276 tools_packages << "sas2ircu"
277 status_packages["sas2ircu-status"] ||= []
279 tools_packages << "megacli"
280 status_packages["megaclisas-status"] ||= []
282 tools_packages << "arcconf"
283 status_packages["aacraid-status"] ||= []
285 tools_packages << "areca"
289 node[:block_device].each do |name, attributes|
290 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
292 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
293 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
295 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
296 status_packages["cciss-vol-status"] |= [File.basename(sg)]
302 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
303 if tools_packages.include?(tools_package)
304 package tools_package
306 package tools_package do
312 if tools_packages.include?("areca")
317 repository "https://git.openstreetmap.org/private/areca.git"
324 directory "/opt/areca" do
330 include_recipe "apt::hwraid" unless status_packages.empty?
332 if status_packages.include?("cciss-vol-status")
333 template "/usr/local/bin/cciss-vol-statusd" do
334 source "cciss-vol-statusd.erb"
338 notifies :restart, "service[cciss-vol-statusd]"
341 systemd_service "cciss-vol-statusd" do
342 description "Check cciss_vol_status values in the background"
343 exec_start "/usr/local/bin/cciss-vol-statusd"
346 protect_system "full"
348 no_new_privileges true
349 notifies :restart, "service[cciss-vol-statusd]"
352 systemd_service "cciss-vol-statusd" do
356 template "/usr/local/bin/cciss-vol-statusd" do
361 %w[cciss-vol-status mpt-status sas2ircu-status megaclisas-status aacraid-status].each do |status_package|
362 if status_packages.include?(status_package)
363 package status_package
365 template "/etc/default/#{status_package}d" do
366 source "raid.default.erb"
370 variables :devices => status_packages[status_package]
373 service "#{status_package}d" do
374 action [:start, :enable]
375 supports :status => false, :restart => true, :reload => false
376 subscribes :restart, "template[/etc/default/#{status_package}d]"
379 package status_package do
383 file "/etc/default/#{status_package}d" do
389 disks = if node[:hardware][:disk]
390 node[:hardware][:disk][:disks]
395 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
397 nvmes = if node[:hardware][:pci]
398 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
407 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
409 if !intel_ssds.empty? || !intel_nvmes.empty?
412 sst_tool_version = "1.3"
413 sst_package_version = "#{sst_tool_version}.208-0"
415 remote_file "#{Chef::Config[:file_cache_path]}/SST_CLI_Linux_#{sst_tool_version}.zip" do
416 source "https://downloadmirror.intel.com/743764/SST_CLI_Linux_#{sst_tool_version}.zip"
419 execute "#{Chef::Config[:file_cache_path]}/SST_CLI_Linux_#{sst_tool_version}.zip" do
420 command "unzip SST_CLI_Linux_#{sst_tool_version}.zip sst_#{sst_package_version}_amd64.deb"
421 cwd Chef::Config[:file_cache_path]
424 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/sst_#{sst_package_version}_amd64.deb") }
427 dpkg_package "sst" do
428 version "#{sst_package_version}"
429 source "#{Chef::Config[:file_cache_path]}/sst_#{sst_package_version}_amd64.deb"
432 dpkg_package "intelmas" do
437 disks = disks.map do |disk|
438 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
440 if disk[:smart_device]
441 controller = node[:hardware][:disk][:controllers][disk[:controller]]
443 if controller && controller[:device]
444 device = controller[:device].sub("/dev/", "")
445 smart = disk[:smart_device]
447 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
448 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
449 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
450 elsif smart =~ /^.*,(\d+)$/
451 munin = "#{device}-#{Regexp.last_match(1)}"
452 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
453 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
456 device = disk[:device].sub("/dev/", "")
457 smart = disk[:smart_device]
459 if smart =~ /^.*,(\d+),(\d+),(\d+)$/
460 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
463 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
464 device = Regexp.last_match(1)
467 device = disk[:device].sub("/dev/", "")
477 :hddtemp => munin.tr("-:", "_")
481 disks = disks.compact.uniq
483 if disks.count.positive?
484 package "smartmontools"
486 template "/etc/cron.daily/update-smart-drivedb" do
487 source "update-smart-drivedb.erb"
493 template "/usr/local/bin/smartd-mailer" do
494 source "smartd-mailer.erb"
500 template "/etc/smartd.conf" do
501 source "smartd.conf.erb"
505 variables :disks => disks
508 template "/etc/default/smartmontools" do
509 source "smartmontools.erb"
515 service "smartmontools" do
516 action [:enable, :start]
517 subscribes :reload, "template[/etc/smartd.conf]"
518 subscribes :restart, "template[/etc/default/smartmontools]"
521 template "/etc/prometheus/collectors/smart.devices" do
522 source "smart.devices.erb"
526 variables :disks => disks
529 prometheus_collector "smart" do
533 # Don't try and do munin monitoring of disks behind
534 # an Areca controller as they only allow one thing to
535 # talk to the controller at a time and smartd will
536 # throw errors if it clashes with munin
537 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
540 munin_plugin "smart_#{disk[:munin]}" do
542 conf "munin.smart.erb"
543 conf_variables :disk => disk
548 action [:stop, :disable]
552 if disks.count.positive?
553 munin_plugin "hddtemp_smartctl" do
554 conf "munin.hddtemp.erb"
555 conf_variables :disks => disks
558 munin_plugin "hddtemp_smartctl" do
560 conf "munin.hddtemp.erb"
564 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
565 disks.map { |d| "smart_#{d[:munin]}" }
567 plugins.each do |plugin|
568 munin_plugin plugin do
570 conf "munin.smart.erb"
574 if File.exist?("/etc/mdadm/mdadm.conf")
575 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
576 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
581 file "/etc/mdadm/mdadm.conf" do
590 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
594 file "/etc/modules" do
598 node[:hardware][:modules].each do |module_name|
599 kernel_module module_name do
605 node[:hardware][:blacklisted_modules].each do |module_name|
606 kernel_module module_name do
611 if node[:hardware][:watchdog]
614 template "/etc/default/watchdog" do
615 source "watchdog.erb"
619 variables :module => node[:hardware][:watchdog]
622 service "watchdog" do
623 action [:enable, :start]
627 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
630 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
631 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
632 chip = format("coretemp-isa-%04d", cpu)
634 temps = if File.exist?("#{coretemp}/name")
635 Dir.glob("#{coretemp}/temp*_input").map do |temp|
636 File.basename(temp).sub("temp", "").sub("_input", "").to_i
639 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
640 File.basename(temp).sub("temp", "").sub("_input", "").to_i
645 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
649 temps.each_with_index do |temp, index|
650 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
654 execute "/etc/sensors.d/chef.conf" do
656 command "/usr/bin/sensors -s"
661 template "/etc/sensors.d/chef.conf" do
662 source "sensors.conf.erb"
666 notifies :run, "execute[/etc/sensors.d/chef.conf]"
670 if node[:hardware][:shm_size]
671 execute "remount-dev-shm" do
673 command "/bin/mount -o remount /dev/shm"
682 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
683 notifies :run, "execute[remount-dev-shm]"
687 prometheus_collector "ohai" do