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.
22 include_recipe "munin"
23 include_recipe "prometheus"
24 include_recipe "sysfs"
25 include_recipe "tools"
27 ohai_plugin "hardware" do
28 template "ohai.rb.erb"
31 case node[:cpu][:"0"][:vendor_id]
33 package "intel-microcode"
35 package "amd64-microcode"
38 if node[:dmi] && node[:dmi][:system]
39 case node[:dmi][:system][:manufacturer]
41 manufacturer = node[:dmi][:base_board][:manufacturer]
42 product = node[:dmi][:base_board][:product_name]
44 manufacturer = node[:dmi][:system][:manufacturer]
45 product = node[:dmi][:system][:product_name]
48 manufacturer = "Unknown"
54 if node[:roles].include?("bytemark") || node[:roles].include?("exonetric") || node[:roles].include?("prgmr")
60 include_recipe "apt::management-component-pack"
64 execute "update-ilo" do
66 command "/usr/sbin/hponcfg -f /etc/ilo-defaults.xml"
70 template "/etc/ilo-defaults.xml" do
71 source "ilo-defaults.xml.erb"
75 notifies :run, "execute[update-ilo]"
78 package "hp-health" do
80 notifies :restart, "service[hp-health]"
81 only_if { platform?("ubuntu") && node[:lsb][:release].to_f < 22.04 }
84 service "hp-health" do
85 action [:enable, :start]
86 supports :status => true, :restart => true
87 only_if { platform?("ubuntu") && node[:lsb][:release].to_f < 22.04 }
90 if product.end_with?("Gen8", "Gen9")
93 notifies :restart, "service[hp-ams]"
97 action [:enable, :start]
98 supports :status => true, :restart => true
100 elsif product.end_with?("Gen10")
103 notifies :restart, "service[amsd]"
107 action [:enable, :start]
108 supports :status => true, :restart => true
112 units << if product.end_with?("Gen10")
119 when "TYAN Computer Corporation"
126 package "open-vm-tools"
128 # Remove timeSync plugin completely
129 # https://github.com/vmware/open-vm-tools/issues/302
130 file "/usr/lib/open-vm-tools/plugins/vmsvc/libtimeSync.so" do
132 notifies :restart, "service[open-vm-tools]"
135 # Attempt to tell Host we are not interested in timeSync
136 execute "vmware-toolbox-cmd-timesync-disable" do
137 command "/usr/bin/vmware-toolbox-cmd timesync disable"
141 service "open-vm-tools" do
142 action [:enable, :start]
143 supports :status => true, :restart => true
147 units.sort.uniq.each do |unit|
148 service "serial-getty@ttyS#{unit}" do
149 action [:enable, :start]
154 # if we need a different / special kernel version to make the hardware
155 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
156 # ensure that we have the package installed. the grub template will
157 # make sure that this is the default on boot.
158 if node[:hardware][:grub][:kernel]
159 kernel_version = node[:hardware][:grub][:kernel]
161 package "linux-image-#{kernel_version}-generic"
162 package "linux-image-extra-#{kernel_version}-generic"
163 package "linux-headers-#{kernel_version}-generic"
164 package "linux-tools-#{kernel_version}-generic"
166 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
167 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
168 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
173 if File.exist?("/etc/default/grub")
174 execute "update-grub" do
176 command "/usr/sbin/update-grub"
180 template "/etc/default/grub" do
185 variables :units => units, :entry => grub_entry
186 notifies :run, "execute[update-grub]"
190 package "initramfs-tools"
192 execute "update-initramfs" do
194 command "update-initramfs -u -k all"
199 template "/etc/initramfs-tools/conf.d/mdadm" do
200 source "initramfs-mdadm.erb"
204 notifies :run, "execute[update-initramfs]"
209 action [:enable, :start]
212 if node[:kernel][:modules].include?("ipmi_si")
214 package "freeipmi-tools"
216 template "/etc/prometheus/ipmi_local.yml" do
217 source "ipmi_local.yml.erb"
223 prometheus_exporter "ipmi" do
226 private_devices false
228 system_call_filter ["@system-service", "@raw-io"]
229 options "--config.file=/etc/prometheus/ipmi_local.yml"
230 subscribes :restart, "template[/etc/prometheus/ipmi_local.yml]"
236 service "irqbalance" do
237 action [:start, :enable]
238 supports :status => false, :restart => true, :reload => false
244 action [:start, :enable]
245 supports :status => true, :restart => true, :reload => true
248 ohai_plugin "lldp" do
249 template "lldp.rb.erb"
257 service "rasdaemon" do
258 action [:enable, :start]
261 prometheus_exporter "rasdaemon" do
269 if node[:virtualization][:role] != "guest" ||
270 (node[:virtualization][:system] != "lxc" &&
271 node[:virtualization][:system] != "lxd" &&
272 node[:virtualization][:system] != "openvz")
274 node[:kernel][:modules].each_key do |modname|
277 tools_packages << "ssacli"
278 status_packages["cciss-vol-status"] ||= []
280 tools_packages << "ssacli"
281 status_packages["cciss-vol-status"] ||= []
283 tools_packages << "lsiutil"
284 status_packages["mpt-status"] ||= []
285 when "mpt2sas", "mpt3sas"
286 tools_packages << "sas2ircu"
287 status_packages["sas2ircu-status"] ||= []
289 tools_packages << "megacli"
290 status_packages["megaclisas-status"] ||= []
292 tools_packages << "arcconf"
293 status_packages["aacraid-status"] ||= []
295 tools_packages << "areca"
299 node[:block_device].each do |name, attributes|
300 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
302 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
303 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
305 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
306 status_packages["cciss-vol-status"] |= [File.basename(sg)]
312 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
313 if tools_packages.include?(tools_package)
314 package tools_package
316 package tools_package do
322 if tools_packages.include?("areca")
327 repository "https://git.openstreetmap.org/private/areca.git"
334 directory "/opt/areca" do
340 include_recipe "apt::hwraid" unless status_packages.empty?
342 %w[cciss-vol-status mpt-status sas2ircu-status megaclisas-status aacraid-status].each do |status_package|
343 if status_packages.include?(status_package)
344 package status_package
346 service "#{status_package}d" do
347 action [:stop, :disable]
350 file "/etc/default/#{status_package}d" do
354 package status_package do
360 systemd_service "cciss-vol-statusd" do
364 template "/usr/local/bin/cciss-vol-statusd" do
368 disks = if node[:hardware][:disk]
369 node[:hardware][:disk][:disks]
374 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
376 nvmes = if node[:hardware][:pci]
377 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
386 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
388 if !intel_ssds.empty? || !intel_nvmes.empty?
391 sst_tool_version = "1.3"
392 sst_package_version = "#{sst_tool_version}.208-0"
394 # remote_file "#{Chef::Config[:file_cache_path]}/SST_CLI_Linux_#{sst_tool_version}.zip" do
395 # source "https://downloadmirror.intel.com/743764/SST_CLI_Linux_#{sst_tool_version}.zip"
398 execute "#{Chef::Config[:file_cache_path]}/SST_CLI_Linux_#{sst_tool_version}.zip" do
399 command "unzip SST_CLI_Linux_#{sst_tool_version}.zip sst_#{sst_package_version}_amd64.deb"
400 cwd Chef::Config[:file_cache_path]
403 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/sst_#{sst_package_version}_amd64.deb") }
406 dpkg_package "sst" do
407 version "#{sst_package_version}"
408 source "#{Chef::Config[:file_cache_path]}/sst_#{sst_package_version}_amd64.deb"
411 dpkg_package "intelmas" do
416 disks = disks.map do |disk|
417 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
419 if disk[:smart_device]
420 controller = node[:hardware][:disk][:controllers][disk[:controller]]
422 if controller && controller[:device]
423 device = controller[:device].sub("/dev/", "")
424 smart = disk[:smart_device]
426 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
427 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
428 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
429 elsif smart =~ /^.*,(\d+)$/
430 munin = "#{device}-#{Regexp.last_match(1)}"
431 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
432 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
435 device = disk[:device].sub("/dev/", "")
436 smart = disk[:smart_device]
438 if smart =~ /^.*,(\d+),(\d+),(\d+)$/
439 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
442 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
443 device = Regexp.last_match(1)
446 device = disk[:device].sub("/dev/", "")
450 next if device.nil? || munin.nil?
456 :hddtemp => munin.tr("-:", "_")
460 disks = disks.compact.uniq
462 if disks.count.positive?
463 package "smartmontools"
465 template "/etc/cron.daily/update-smart-drivedb" do
466 source "update-smart-drivedb.erb"
472 template "/usr/local/bin/smartd-mailer" do
473 source "smartd-mailer.erb"
479 template "/etc/smartd.conf" do
480 source "smartd.conf.erb"
484 variables :disks => disks
487 template "/etc/default/smartmontools" do
488 source "smartmontools.erb"
494 service "smartmontools" do
495 action [:enable, :start]
496 subscribes :reload, "template[/etc/smartd.conf]"
497 subscribes :restart, "template[/etc/default/smartmontools]"
500 template "/etc/prometheus/collectors/smart.devices" do
501 source "smart.devices.erb"
505 variables :disks => disks
508 prometheus_collector "smart" do
511 capability_bounding_set %w[CAP_DAC_OVERRIDE CAP_SYS_ADMIN CAP_SYS_RAWIO]
512 private_devices false
517 # Don't try and do munin monitoring of disks behind
518 # an Areca controller as they only allow one thing to
519 # talk to the controller at a time and smartd will
520 # throw errors if it clashes with munin
521 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
524 munin_plugin "smart_#{disk[:munin]}" do
526 conf "munin.smart.erb"
527 conf_variables :disk => disk
532 action [:stop, :disable]
536 if disks.count.positive?
537 munin_plugin "hddtemp_smartctl" do
538 conf "munin.hddtemp.erb"
539 conf_variables :disks => disks
542 munin_plugin "hddtemp_smartctl" do
544 conf "munin.hddtemp.erb"
548 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
549 disks.map { |d| "smart_#{d[:munin]}" }
551 plugins.each do |plugin|
552 munin_plugin plugin do
554 conf "munin.smart.erb"
558 if File.exist?("/etc/mdadm/mdadm.conf")
559 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
560 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
565 file "/etc/mdadm/mdadm.conf" do
572 service "mdmonitor" do
574 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
578 file "/etc/modules" do
582 node[:hardware][:modules].each do |module_name|
583 kernel_module module_name do
589 node[:hardware][:blacklisted_modules].each do |module_name|
590 kernel_module module_name do
595 if node[:hardware][:watchdog]
598 template "/etc/default/watchdog" do
599 source "watchdog.erb"
603 variables :module => node[:hardware][:watchdog]
606 service "watchdog" do
607 action [:enable, :start]
611 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
614 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
615 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
616 chip = format("coretemp-isa-%04d", cpu)
618 temps = if File.exist?("#{coretemp}/name")
619 Dir.glob("#{coretemp}/temp*_input").map do |temp|
620 File.basename(temp).sub("temp", "").sub("_input", "").to_i
623 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
624 File.basename(temp).sub("temp", "").sub("_input", "").to_i
629 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
633 temps.each_with_index do |temp, index|
634 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
638 execute "/etc/sensors.d/chef.conf" do
640 command "/usr/bin/sensors -s"
645 template "/etc/sensors.d/chef.conf" do
646 source "sensors.conf.erb"
650 notifies :run, "execute[/etc/sensors.d/chef.conf]"
654 if node[:hardware][:shm_size]
655 execute "remount-dev-shm" do
657 command "/bin/mount -o remount /dev/shm"
666 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
667 notifies :run, "execute[remount-dev-shm]"
671 prometheus_collector "ohai" do
675 capability_bounding_set %w[CAP_DAC_OVERRIDE CAP_SYS_ADMIN CAP_SYS_RAWIO]
676 private_devices false
679 protect_kernel_modules false