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 execute "update-initramfs" do
191 command "update-initramfs -u -k all"
196 template "/etc/initramfs-tools/conf.d/mdadm" do
197 source "initramfs-mdadm.erb"
201 notifies :run, "execute[update-initramfs]"
206 action [:enable, :start]
209 if node[:kernel][:modules].include?("ipmi_si")
211 package "freeipmi-tools"
213 template "/etc/prometheus/ipmi_local.yml" do
214 source "ipmi_local.yml.erb"
220 prometheus_exporter "ipmi" do
222 options "--config.file=/etc/prometheus/ipmi_local.yml"
223 subscribes :restart, "template[/etc/prometheus/ipmi_local.yml]"
229 service "irqbalance" do
230 action [:start, :enable]
231 supports :status => false, :restart => true, :reload => false
237 action [:start, :enable]
238 supports :status => true, :restart => true, :reload => true
241 ohai_plugin "lldp" do
242 template "lldp.rb.erb"
250 service "rasdaemon" do
251 action [:enable, :start]
254 prometheus_exporter "rasdaemon" do
261 if node[:virtualization][:role] != "guest" ||
262 (node[:virtualization][:system] != "lxc" &&
263 node[:virtualization][:system] != "lxd" &&
264 node[:virtualization][:system] != "openvz")
266 node[:kernel][:modules].each_key do |modname|
269 tools_packages << "ssacli"
270 status_packages["cciss-vol-status"] ||= []
272 tools_packages << "ssacli"
273 status_packages["cciss-vol-status"] ||= []
275 tools_packages << "lsiutil"
276 status_packages["mpt-status"] ||= []
277 when "mpt2sas", "mpt3sas"
278 tools_packages << "sas2ircu"
279 status_packages["sas2ircu-status"] ||= []
281 tools_packages << "megacli"
282 status_packages["megaclisas-status"] ||= []
284 tools_packages << "arcconf"
285 status_packages["aacraid-status"] ||= []
287 tools_packages << "areca"
291 node[:block_device].each do |name, attributes|
292 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
294 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
295 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
297 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
298 status_packages["cciss-vol-status"] |= [File.basename(sg)]
304 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
305 if tools_packages.include?(tools_package)
306 package tools_package
308 package tools_package do
314 if tools_packages.include?("areca")
319 repository "https://git.openstreetmap.org/private/areca.git"
326 directory "/opt/areca" do
332 include_recipe "apt::hwraid" unless status_packages.empty?
334 if status_packages.include?("cciss-vol-status")
335 template "/usr/local/bin/cciss-vol-statusd" do
336 source "cciss-vol-statusd.erb"
340 notifies :restart, "service[cciss-vol-statusd]"
343 systemd_service "cciss-vol-statusd" do
344 description "Check cciss_vol_status values in the background"
345 exec_start "/usr/local/bin/cciss-vol-statusd"
348 protect_system "full"
350 no_new_privileges true
351 notifies :restart, "service[cciss-vol-statusd]"
354 systemd_service "cciss-vol-statusd" do
358 template "/usr/local/bin/cciss-vol-statusd" do
363 %w[cciss-vol-status mpt-status sas2ircu-status megaclisas-status aacraid-status].each do |status_package|
364 if status_packages.include?(status_package)
365 package status_package
367 template "/etc/default/#{status_package}d" do
368 source "raid.default.erb"
372 variables :devices => status_packages[status_package]
375 service "#{status_package}d" do
376 action [:start, :enable]
377 supports :status => false, :restart => true, :reload => false
378 subscribes :restart, "template[/etc/default/#{status_package}d]"
381 package status_package do
385 file "/etc/default/#{status_package}d" do
391 disks = if node[:hardware][:disk]
392 node[:hardware][:disk][:disks]
397 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
399 nvmes = if node[:hardware][:pci]
400 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
409 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
411 if !intel_ssds.empty? || !intel_nvmes.empty?
414 sst_tool_version = "1.3"
415 sst_package_version = "#{sst_tool_version}.208-0"
417 # remote_file "#{Chef::Config[:file_cache_path]}/SST_CLI_Linux_#{sst_tool_version}.zip" do
418 # source "https://downloadmirror.intel.com/743764/SST_CLI_Linux_#{sst_tool_version}.zip"
421 execute "#{Chef::Config[:file_cache_path]}/SST_CLI_Linux_#{sst_tool_version}.zip" do
422 command "unzip SST_CLI_Linux_#{sst_tool_version}.zip sst_#{sst_package_version}_amd64.deb"
423 cwd Chef::Config[:file_cache_path]
426 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/sst_#{sst_package_version}_amd64.deb") }
429 dpkg_package "sst" do
430 version "#{sst_package_version}"
431 source "#{Chef::Config[:file_cache_path]}/sst_#{sst_package_version}_amd64.deb"
434 dpkg_package "intelmas" do
439 disks = disks.map do |disk|
440 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
442 if disk[:smart_device]
443 controller = node[:hardware][:disk][:controllers][disk[:controller]]
445 if controller && controller[:device]
446 device = controller[:device].sub("/dev/", "")
447 smart = disk[:smart_device]
449 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
450 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
451 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
452 elsif smart =~ /^.*,(\d+)$/
453 munin = "#{device}-#{Regexp.last_match(1)}"
454 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
455 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
458 device = disk[:device].sub("/dev/", "")
459 smart = disk[:smart_device]
461 if smart =~ /^.*,(\d+),(\d+),(\d+)$/
462 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
465 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
466 device = Regexp.last_match(1)
469 device = disk[:device].sub("/dev/", "")
479 :hddtemp => munin.tr("-:", "_")
483 disks = disks.compact.uniq
485 if disks.count.positive?
486 package "smartmontools"
488 template "/etc/cron.daily/update-smart-drivedb" do
489 source "update-smart-drivedb.erb"
495 template "/usr/local/bin/smartd-mailer" do
496 source "smartd-mailer.erb"
502 template "/etc/smartd.conf" do
503 source "smartd.conf.erb"
507 variables :disks => disks
510 template "/etc/default/smartmontools" do
511 source "smartmontools.erb"
517 service "smartmontools" do
518 action [:enable, :start]
519 subscribes :reload, "template[/etc/smartd.conf]"
520 subscribes :restart, "template[/etc/default/smartmontools]"
523 template "/etc/prometheus/collectors/smart.devices" do
524 source "smart.devices.erb"
528 variables :disks => disks
531 prometheus_collector "smart" do
535 # Don't try and do munin monitoring of disks behind
536 # an Areca controller as they only allow one thing to
537 # talk to the controller at a time and smartd will
538 # throw errors if it clashes with munin
539 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
542 munin_plugin "smart_#{disk[:munin]}" do
544 conf "munin.smart.erb"
545 conf_variables :disk => disk
550 action [:stop, :disable]
554 if disks.count.positive?
555 munin_plugin "hddtemp_smartctl" do
556 conf "munin.hddtemp.erb"
557 conf_variables :disks => disks
560 munin_plugin "hddtemp_smartctl" do
562 conf "munin.hddtemp.erb"
566 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
567 disks.map { |d| "smart_#{d[:munin]}" }
569 plugins.each do |plugin|
570 munin_plugin plugin do
572 conf "munin.smart.erb"
576 if File.exist?("/etc/mdadm/mdadm.conf")
577 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
578 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
583 file "/etc/mdadm/mdadm.conf" do
590 service "mdmonitor" do
592 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
596 file "/etc/modules" do
600 node[:hardware][:modules].each do |module_name|
601 kernel_module module_name do
607 node[:hardware][:blacklisted_modules].each do |module_name|
608 kernel_module module_name do
613 if node[:hardware][:watchdog]
616 template "/etc/default/watchdog" do
617 source "watchdog.erb"
621 variables :module => node[:hardware][:watchdog]
624 service "watchdog" do
625 action [:enable, :start]
629 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
632 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
633 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
634 chip = format("coretemp-isa-%04d", cpu)
636 temps = if File.exist?("#{coretemp}/name")
637 Dir.glob("#{coretemp}/temp*_input").map do |temp|
638 File.basename(temp).sub("temp", "").sub("_input", "").to_i
641 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
642 File.basename(temp).sub("temp", "").sub("_input", "").to_i
647 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
651 temps.each_with_index do |temp, index|
652 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
656 execute "/etc/sensors.d/chef.conf" do
658 command "/usr/bin/sensors -s"
663 template "/etc/sensors.d/chef.conf" do
664 source "sensors.conf.erb"
668 notifies :run, "execute[/etc/sensors.d/chef.conf]"
672 if node[:hardware][:shm_size]
673 execute "remount-dev-shm" do
675 command "/bin/mount -o remount /dev/shm"
684 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
685 notifies :run, "execute[remount-dev-shm]"
689 prometheus_collector "ohai" do