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"
69 template "/etc/ilo-defaults.xml" do
70 source "ilo-defaults.xml.erb"
74 notifies :run, "execute[update-ilo]"
77 package "hp-health" do
79 notifies :restart, "service[hp-health]"
80 only_if { node[:lsb][:release].to_f < 22.04 }
83 service "hp-health" do
84 action [:enable, :start]
85 supports :status => true, :restart => true
86 only_if { node[:lsb][:release].to_f < 22.04 }
89 if product.end_with?("Gen8", "Gen9")
92 notifies :restart, "service[hp-ams]"
96 action [:enable, :start]
97 supports :status => true, :restart => true
99 elsif product.end_with?("Gen10")
102 notifies :restart, "service[amsd]"
106 action [:enable, :start]
107 supports :status => true, :restart => true
111 units << if product.end_with?("Gen10")
118 when "TYAN Computer Corporation"
125 package "open-vm-tools"
127 # Remove timeSync plugin completely
128 # https://github.com/vmware/open-vm-tools/issues/302
129 file "/usr/lib/open-vm-tools/plugins/vmsvc/libtimeSync.so" do
131 notifies :restart, "service[open-vm-tools]"
134 # Attempt to tell Host we are not interested in timeSync
135 execute "vmware-toolbox-cmd-timesync-disable" do
136 command "/usr/bin/vmware-toolbox-cmd timesync disable"
140 service "open-vm-tools" do
141 action [:enable, :start]
142 supports :status => true, :restart => true
146 units.sort.uniq.each do |unit|
147 service "serial-getty@ttyS#{unit}" do
148 action [:enable, :start]
153 # if we need a different / special kernel version to make the hardware
154 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
155 # ensure that we have the package installed. the grub template will
156 # make sure that this is the default on boot.
157 if node[:hardware][:grub][:kernel]
158 kernel_version = node[:hardware][:grub][:kernel]
160 package "linux-image-#{kernel_version}-generic"
161 package "linux-image-extra-#{kernel_version}-generic"
162 package "linux-headers-#{kernel_version}-generic"
163 package "linux-tools-#{kernel_version}-generic"
165 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
166 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
167 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
172 if File.exist?("/etc/default/grub")
173 execute "update-grub" do
175 command "/usr/sbin/update-grub"
179 template "/etc/default/grub" do
184 variables :units => units, :entry => grub_entry
185 notifies :run, "execute[update-grub]"
189 package "initramfs-tools"
191 execute "update-initramfs" do
193 command "update-initramfs -u -k all"
198 template "/etc/initramfs-tools/conf.d/mdadm" do
199 source "initramfs-mdadm.erb"
203 notifies :run, "execute[update-initramfs]"
208 action [:enable, :start]
211 if node[:kernel][:modules].include?("ipmi_si")
213 package "freeipmi-tools"
215 template "/etc/prometheus/ipmi_local.yml" do
216 source "ipmi_local.yml.erb"
222 prometheus_exporter "ipmi" do
225 private_devices false
227 system_call_filter ["@system-service", "@raw-io"]
228 options "--config.file=/etc/prometheus/ipmi_local.yml"
229 subscribes :restart, "template[/etc/prometheus/ipmi_local.yml]"
235 service "irqbalance" do
236 action [:start, :enable]
237 supports :status => false, :restart => true, :reload => false
243 action [:start, :enable]
244 supports :status => true, :restart => true, :reload => true
247 ohai_plugin "lldp" do
248 template "lldp.rb.erb"
256 service "rasdaemon" do
257 action [:enable, :start]
260 prometheus_exporter "rasdaemon" do
268 if node[:virtualization][:role] != "guest" ||
269 (node[:virtualization][:system] != "lxc" &&
270 node[:virtualization][:system] != "lxd" &&
271 node[:virtualization][:system] != "openvz")
273 node[:kernel][:modules].each_key do |modname|
276 tools_packages << "ssacli"
277 status_packages["cciss-vol-status"] ||= []
279 tools_packages << "ssacli"
280 status_packages["cciss-vol-status"] ||= []
282 tools_packages << "lsiutil"
283 status_packages["mpt-status"] ||= []
284 when "mpt2sas", "mpt3sas"
285 tools_packages << "sas2ircu"
286 status_packages["sas2ircu-status"] ||= []
288 tools_packages << "megacli"
289 status_packages["megaclisas-status"] ||= []
291 tools_packages << "arcconf"
292 status_packages["aacraid-status"] ||= []
294 tools_packages << "areca"
298 node[:block_device].each do |name, attributes|
299 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
301 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
302 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
304 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
305 status_packages["cciss-vol-status"] |= [File.basename(sg)]
311 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
312 if tools_packages.include?(tools_package)
313 package tools_package
315 package tools_package do
321 if tools_packages.include?("areca")
326 repository "https://git.openstreetmap.org/private/areca.git"
333 directory "/opt/areca" do
339 include_recipe "apt::hwraid" unless status_packages.empty?
341 if status_packages.include?("cciss-vol-status")
342 template "/usr/local/bin/cciss-vol-statusd" do
343 source "cciss-vol-statusd.erb"
347 notifies :restart, "service[cciss-vol-statusd]"
350 systemd_service "cciss-vol-statusd" do
351 description "Check cciss_vol_status values in the background"
352 exec_start "/usr/local/bin/cciss-vol-statusd"
355 protect_system "full"
357 no_new_privileges true
358 notifies :restart, "service[cciss-vol-statusd]"
361 systemd_service "cciss-vol-statusd" do
365 template "/usr/local/bin/cciss-vol-statusd" do
370 %w[cciss-vol-status mpt-status sas2ircu-status megaclisas-status aacraid-status].each do |status_package|
371 if status_packages.include?(status_package)
372 package status_package
374 template "/etc/default/#{status_package}d" do
375 source "raid.default.erb"
379 variables :devices => status_packages[status_package]
382 service "#{status_package}d" do
383 action [:start, :enable]
384 supports :status => false, :restart => true, :reload => false
385 subscribes :restart, "template[/etc/default/#{status_package}d]"
388 package status_package do
392 file "/etc/default/#{status_package}d" do
398 disks = if node[:hardware][:disk]
399 node[:hardware][:disk][:disks]
404 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
406 nvmes = if node[:hardware][:pci]
407 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
416 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
418 if !intel_ssds.empty? || !intel_nvmes.empty?
421 sst_tool_version = "1.3"
422 sst_package_version = "#{sst_tool_version}.208-0"
424 # remote_file "#{Chef::Config[:file_cache_path]}/SST_CLI_Linux_#{sst_tool_version}.zip" do
425 # source "https://downloadmirror.intel.com/743764/SST_CLI_Linux_#{sst_tool_version}.zip"
428 execute "#{Chef::Config[:file_cache_path]}/SST_CLI_Linux_#{sst_tool_version}.zip" do
429 command "unzip SST_CLI_Linux_#{sst_tool_version}.zip sst_#{sst_package_version}_amd64.deb"
430 cwd Chef::Config[:file_cache_path]
433 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/sst_#{sst_package_version}_amd64.deb") }
436 dpkg_package "sst" do
437 version "#{sst_package_version}"
438 source "#{Chef::Config[:file_cache_path]}/sst_#{sst_package_version}_amd64.deb"
441 dpkg_package "intelmas" do
446 disks = disks.map do |disk|
447 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
449 if disk[:smart_device]
450 controller = node[:hardware][:disk][:controllers][disk[:controller]]
452 if controller && controller[:device]
453 device = controller[:device].sub("/dev/", "")
454 smart = disk[:smart_device]
456 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
457 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
458 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
459 elsif smart =~ /^.*,(\d+)$/
460 munin = "#{device}-#{Regexp.last_match(1)}"
461 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
462 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
465 device = disk[:device].sub("/dev/", "")
466 smart = disk[:smart_device]
468 if smart =~ /^.*,(\d+),(\d+),(\d+)$/
469 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
472 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
473 device = Regexp.last_match(1)
476 device = disk[:device].sub("/dev/", "")
480 next if device.nil? || munin.nil?
486 :hddtemp => munin.tr("-:", "_")
490 disks = disks.compact.uniq
492 if disks.count.positive?
493 package "smartmontools"
495 template "/etc/cron.daily/update-smart-drivedb" do
496 source "update-smart-drivedb.erb"
502 template "/usr/local/bin/smartd-mailer" do
503 source "smartd-mailer.erb"
509 template "/etc/smartd.conf" do
510 source "smartd.conf.erb"
514 variables :disks => disks
517 template "/etc/default/smartmontools" do
518 source "smartmontools.erb"
524 service "smartmontools" do
525 action [:enable, :start]
526 subscribes :reload, "template[/etc/smartd.conf]"
527 subscribes :restart, "template[/etc/default/smartmontools]"
530 template "/etc/prometheus/collectors/smart.devices" do
531 source "smart.devices.erb"
535 variables :disks => disks
538 prometheus_collector "smart" do
541 capability_bounding_set %w[CAP_DAC_OVERRIDE CAP_SYS_ADMIN CAP_SYS_RAWIO]
542 private_devices false
547 # Don't try and do munin monitoring of disks behind
548 # an Areca controller as they only allow one thing to
549 # talk to the controller at a time and smartd will
550 # throw errors if it clashes with munin
551 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
554 munin_plugin "smart_#{disk[:munin]}" do
556 conf "munin.smart.erb"
557 conf_variables :disk => disk
562 action [:stop, :disable]
566 if disks.count.positive?
567 munin_plugin "hddtemp_smartctl" do
568 conf "munin.hddtemp.erb"
569 conf_variables :disks => disks
572 munin_plugin "hddtemp_smartctl" do
574 conf "munin.hddtemp.erb"
578 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
579 disks.map { |d| "smart_#{d[:munin]}" }
581 plugins.each do |plugin|
582 munin_plugin plugin do
584 conf "munin.smart.erb"
588 if File.exist?("/etc/mdadm/mdadm.conf")
589 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
590 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
595 file "/etc/mdadm/mdadm.conf" do
602 service "mdmonitor" do
604 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
608 file "/etc/modules" do
612 node[:hardware][:modules].each do |module_name|
613 kernel_module module_name do
619 node[:hardware][:blacklisted_modules].each do |module_name|
620 kernel_module module_name do
625 if node[:hardware][:watchdog]
628 template "/etc/default/watchdog" do
629 source "watchdog.erb"
633 variables :module => node[:hardware][:watchdog]
636 service "watchdog" do
637 action [:enable, :start]
641 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
644 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
645 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
646 chip = format("coretemp-isa-%04d", cpu)
648 temps = if File.exist?("#{coretemp}/name")
649 Dir.glob("#{coretemp}/temp*_input").map do |temp|
650 File.basename(temp).sub("temp", "").sub("_input", "").to_i
653 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
654 File.basename(temp).sub("temp", "").sub("_input", "").to_i
659 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
663 temps.each_with_index do |temp, index|
664 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
668 execute "/etc/sensors.d/chef.conf" do
670 command "/usr/bin/sensors -s"
675 template "/etc/sensors.d/chef.conf" do
676 source "sensors.conf.erb"
680 notifies :run, "execute[/etc/sensors.d/chef.conf]"
684 if node[:hardware][:shm_size]
685 execute "remount-dev-shm" do
687 command "/bin/mount -o remount /dev/shm"
696 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
697 notifies :run, "execute[remount-dev-shm]"
701 prometheus_collector "ohai" do
705 capability_bounding_set %w[CAP_DAC_OVERRIDE CAP_SYS_ADMIN CAP_SYS_RAWIO]
706 private_devices false
709 protect_kernel_modules false