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 "prometheus"
23 include_recipe "sysfs"
24 include_recipe "tools"
26 ohai_plugin "hardware" do
27 template "ohai.rb.erb"
30 if platform?("debian")
31 package "firmware-linux"
34 if node[:cpu] && node[:cpu][:"0"] && node[:cpu][:"0"][:vendor_id]
35 case node[:cpu][:"0"][:vendor_id]
37 package "intel-microcode"
39 package "amd64-microcode"
43 if node[:dmi] && node[:dmi][:system]
44 case node[:dmi][:system][:manufacturer]
46 manufacturer = node[:dmi][:base_board][:manufacturer]
47 product = node[:dmi][:base_board][:product_name]
49 manufacturer = node[:dmi][:system][:manufacturer]
50 product = node[:dmi][:system][:product_name]
53 manufacturer = "Unknown"
59 if node[:roles].include?("bytemark")
65 include_recipe "apt::management-component-pack"
69 execute "update-ilo" do
71 command "/usr/sbin/hponcfg -f /etc/ilo-defaults.xml"
75 template "/etc/ilo-defaults.xml" do
76 source "ilo-defaults.xml.erb"
80 notifies :run, "execute[update-ilo]"
83 unless product.end_with?("G6", "G7") # iLO4+ Only
84 execute "update-ilo-network" do
86 command "/usr/sbin/hponcfg -f /etc/ilo-network.xml"
90 template "/etc/ilo-network.xml" do
91 source "ilo-network.xml.erb"
95 notifies :run, "execute[update-ilo-network]"
99 package "hp-health" do
101 notifies :restart, "service[hp-health]"
102 only_if { platform?("ubuntu") && node[:lsb][:release].to_f < 22.04 }
105 service "hp-health" do
106 action [:enable, :start]
107 supports :status => true, :restart => true
108 only_if { platform?("ubuntu") && node[:lsb][:release].to_f < 22.04 }
111 if product.end_with?("Gen8", "Gen9")
114 notifies :restart, "service[hp-ams]"
118 action [:enable, :start]
119 supports :status => true, :restart => true
121 elsif product.end_with?("Gen10") || product.end_with?("Gen10 Plus")
124 notifies :restart, "service[amsd]"
125 only_if { node[:hostname] != "quetzal" } # amsd is broken on quetzal, no SAS controller
129 action [:enable, :start]
130 supports :status => true, :restart => true
131 only_if { node[:hostname] != "quetzal" } # amsd is broken on quetzal, no SAS controller
135 units << if product.end_with?("Gen10") || product.end_with?("Gen10 Plus")
142 when "TYAN Computer Corporation"
149 package "open-vm-tools"
151 # Remove timeSync plugin completely
152 # https://github.com/vmware/open-vm-tools/issues/302
153 file "/usr/lib/open-vm-tools/plugins/vmsvc/libtimeSync.so" do
155 notifies :restart, "service[open-vm-tools]"
158 # Attempt to tell Host we are not interested in timeSync
159 execute "vmware-toolbox-cmd-timesync-disable" do
160 command "/usr/bin/vmware-toolbox-cmd timesync disable"
164 service "open-vm-tools" do
165 action [:enable, :start]
166 supports :status => true, :restart => true
170 units.sort.uniq.each do |unit|
171 service "serial-getty@ttyS#{unit}" do
172 action [:enable, :start]
177 # if we need a different / special kernel version to make the hardware
178 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
179 # ensure that we have the package installed. the grub template will
180 # make sure that this is the default on boot.
181 if node[:hardware][:grub][:kernel]
182 kernel_version = node[:hardware][:grub][:kernel]
184 package "linux-image-#{kernel_version}-generic"
185 package "linux-image-extra-#{kernel_version}-generic"
186 package "linux-headers-#{kernel_version}-generic"
187 package "linux-tools-#{kernel_version}-generic"
189 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
190 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
191 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
196 if File.exist?("/etc/default/grub")
197 execute "update-grub" do
199 command "/usr/sbin/update-grub"
203 template "/etc/default/grub" do
208 variables :units => units, :entry => grub_entry
209 notifies :run, "execute[update-grub]"
213 package "initramfs-tools"
215 execute "update-initramfs" do
217 command "update-initramfs -u -k all"
222 template "/etc/initramfs-tools/conf.d/mdadm" do
223 source "initramfs-mdadm.erb"
227 notifies :run, "execute[update-initramfs]"
230 # haveged is only required on older kernels
231 # /dev/random is not blocking anymore in 5.15+
232 if Chef::Util.compare_versions(node[:kernel][:release], [5, 15]).negative?
235 action [:enable, :start]
239 action [:stop, :disable]
246 watchdog_module = %w[hpwdt sp5100_tco].find do |module_name|
247 node[:hardware][:pci]&.any? { |_, pci| pci[:modules]&.any?(module_name) }
250 if node[:kernel][:modules].include?("ipmi_si")
252 package "freeipmi-tools"
254 template "/etc/prometheus/ipmi_local.yml" do
255 source "ipmi_local.yml.erb"
261 prometheus_exporter "ipmi" do
264 private_devices false
266 system_call_filter ["@system-service", "@raw-io"]
267 options "--config.file=/etc/prometheus/ipmi_local.yml"
268 subscribes :restart, "template[/etc/prometheus/ipmi_local.yml]"
271 watchdog_module ||= "ipmi_watchdog"
276 service "irqbalance" do
277 action [:start, :enable]
278 supports :status => false, :restart => true, :reload => false
284 action [:start, :enable]
285 supports :status => true, :restart => true, :reload => true
288 ohai_plugin "lldp" do
289 template "lldp.rb.erb"
297 service "rasdaemon" do
298 action [:enable, :start]
301 prometheus_exporter "rasdaemon" do
308 if node[:virtualization][:role] != "guest" ||
309 (node[:virtualization][:system] != "lxc" &&
310 node[:virtualization][:system] != "lxd" &&
311 node[:virtualization][:system] != "openvz")
313 node[:kernel][:modules].each_key do |modname|
316 tools_packages << "ssacli"
318 tools_packages << "sas2ircu"
320 tools_packages << "megacli"
325 include_recipe "apt::hwraid" unless tools_packages.empty?
327 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
328 if tools_packages.include?(tools_package)
329 package tools_package
331 package tools_package do
337 disks = if node[:hardware][:disk]
338 node[:hardware][:disk][:disks]
343 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
345 nvmes = if node[:hardware][:pci]
346 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
355 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
357 if !intel_ssds.empty? || !intel_nvmes.empty?
360 sst_tool_version = "3-1"
361 sst_package_version = "3.1.346-0"
363 remote_file "#{Chef::Config[:file_cache_path]}/sst-cli-linux-deb--#{sst_tool_version}.zip" do
364 source "https://sdmsdfwdriver.blob.core.windows.net/files/kba-gcc/drivers-downloads/ka-00085/sst--#{sst_tool_version}/sst-cli-linux-deb--#{sst_tool_version}.zip"
367 archive_file "#{Chef::Config[:file_cache_path]}/sst-cli-linux-deb--#{sst_tool_version}.zip" do
368 destination Chef::Config[:file_cache_path]
372 subscribes :create, "remote_file[#{Chef::Config[:file_cache_path]}/sst-cli-linux-deb--#{sst_tool_version}.zip]"
375 dpkg_package "sst" do
376 version sst_package_version
377 source "#{Chef::Config[:file_cache_path]}/sst-cli-linux-deb--#{sst_tool_version}/sst_#{sst_package_version}_amd64.deb"
380 dpkg_package "intelmas" do
385 disks = disks.map do |disk|
386 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
388 if disk[:smart_device]
389 controller = node[:hardware][:disk][:controllers][disk[:controller]]
391 if controller && controller[:device]
392 device = controller[:device].sub("/dev/", "")
393 smart = disk[:smart_device]
395 device = disk[:device].sub("/dev/", "")
396 smart = disk[:smart_device]
398 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
399 device = Regexp.last_match(1)
401 device = disk[:device].sub("/dev/", "")
412 disks = disks.compact.uniq
415 package "smartmontools"
417 template "/etc/cron.daily/update-smart-drivedb" do
418 source "update-smart-drivedb.erb"
424 template "/usr/local/bin/smartd-mailer" do
425 source "smartd-mailer.erb"
431 template "/etc/smartd.conf" do
432 source "smartd.conf.erb"
436 variables :disks => disks
439 template "/etc/default/smartmontools" do
440 source "smartmontools.erb"
446 service "smartmontools" do
447 action [:enable, :start]
448 subscribes :reload, "template[/etc/smartd.conf]"
449 subscribes :restart, "template[/etc/default/smartmontools]"
452 template "/etc/prometheus/collectors/smart.devices" do
453 source "smart.devices.erb"
457 variables :disks => disks
460 prometheus_collector "smart" do
463 capability_bounding_set %w[CAP_DAC_OVERRIDE CAP_SYS_ADMIN CAP_SYS_RAWIO]
464 private_devices false
470 action [:stop, :disable]
474 if File.exist?("/etc/mdadm/mdadm.conf")
475 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
476 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
481 file "/etc/mdadm/mdadm.conf" do
488 service "mdmonitor" do
490 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
494 file "/etc/modules" do
498 node[:hardware][:modules].each do |module_name|
499 kernel_module module_name do
505 node[:hardware][:blacklisted_modules].each do |module_name|
506 kernel_module module_name do
512 kernel_module watchdog_module do
516 directory "/etc/systemd/system.conf.d" do
522 template "/etc/systemd/system.conf.d/watchdog.conf" do
523 source "watchdog.conf.erb"
529 execute "systemctl-reload" do
531 command "systemctl daemon-reload"
534 subscribes :run, "template[/etc/systemd/system.conf.d/watchdog.conf]"
538 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
541 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
542 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
543 chip = format("coretemp-isa-%04d", cpu)
545 temps = if File.exist?("#{coretemp}/name")
546 Dir.glob("#{coretemp}/temp*_input").map do |temp|
547 File.basename(temp).sub("temp", "").sub("_input", "").to_i
550 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
551 File.basename(temp).sub("temp", "").sub("_input", "").to_i
556 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
560 temps.each_with_index do |temp, index|
561 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
565 execute "/etc/sensors.d/chef.conf" do
567 command "/usr/bin/sensors -s"
572 template "/etc/sensors.d/chef.conf" do
573 source "sensors.conf.erb"
577 notifies :run, "execute[/etc/sensors.d/chef.conf]"
581 if node[:hardware][:shm_size]
582 execute "remount-dev-shm" do
584 command "/bin/mount -o remount /dev/shm"
593 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
594 notifies :run, "execute[remount-dev-shm]"
598 prometheus_collector "ohai" do
602 capability_bounding_set %w[CAP_DAC_OVERRIDE CAP_SYS_ADMIN CAP_SYS_RAWIO]
603 private_devices false
606 protect_kernel_modules false