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
100 units << if product.end_with?("Gen10")
107 when "TYAN Computer Corporation"
114 package "open-vm-tools"
116 # Remove timeSync plugin completely
117 # https://github.com/vmware/open-vm-tools/issues/302
118 file "/usr/lib/open-vm-tools/plugins/vmsvc/libtimeSync.so" do
120 notifies :restart, "service[open-vm-tools]"
123 # Attempt to tell Host we are not interested in timeSync
124 execute "vmware-toolbox-cmd-timesync-disable" do
125 command "/usr/bin/vmware-toolbox-cmd timesync disable"
129 service "open-vm-tools" do
130 action [:enable, :start]
131 supports :status => true, :restart => true
135 units.sort.uniq.each do |unit|
136 service "serial-getty@ttyS#{unit}" do
137 action [:enable, :start]
141 # if we need a different / special kernel version to make the hardware
142 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
143 # ensure that we have the package installed. the grub template will
144 # make sure that this is the default on boot.
145 if node[:hardware][:grub][:kernel]
146 kernel_version = node[:hardware][:grub][:kernel]
148 package "linux-image-#{kernel_version}-generic"
149 package "linux-image-extra-#{kernel_version}-generic"
150 package "linux-headers-#{kernel_version}-generic"
151 package "linux-tools-#{kernel_version}-generic"
153 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
154 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
155 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
160 if File.exist?("/etc/default/grub")
161 execute "update-grub" do
163 command "/usr/sbin/update-grub"
167 template "/etc/default/grub" do
172 variables :units => units, :entry => grub_entry
173 notifies :run, "execute[update-grub]"
177 execute "update-initramfs" do
179 command "update-initramfs -u -k all"
184 template "/etc/initramfs-tools/conf.d/mdadm" do
185 source "initramfs-mdadm.erb"
189 notifies :run, "execute[update-initramfs]"
194 action [:enable, :start]
197 if node[:kernel][:modules].include?("ipmi_si")
199 package "freeipmi-tools"
201 template "/etc/prometheus/ipmi_local.yml" do
202 source "ipmi_local.yml.erb"
208 prometheus_exporter "ipmi" do
210 options "--config.file=/etc/prometheus/ipmi_local.yml"
211 subscribes :restart, "template[/etc/prometheus/ipmi_local.yml]"
217 service "irqbalance" do
218 action [:start, :enable]
219 supports :status => false, :restart => true, :reload => false
225 action [:start, :enable]
226 supports :status => true, :restart => true, :reload => true
229 ohai_plugin "lldp" do
230 template "lldp.rb.erb"
238 service "rasdaemon" do
239 action [:enable, :start]
242 prometheus_exporter "rasdaemon" do
249 if node[:virtualization][:role] != "guest" ||
250 (node[:virtualization][:system] != "lxc" &&
251 node[:virtualization][:system] != "lxd" &&
252 node[:virtualization][:system] != "openvz")
254 node[:kernel][:modules].each_key do |modname|
257 tools_packages << "ssacli"
258 status_packages["cciss-vol-status"] ||= []
260 tools_packages << "ssacli"
261 status_packages["cciss-vol-status"] ||= []
263 tools_packages << "lsiutil"
264 status_packages["mpt-status"] ||= []
265 when "mpt2sas", "mpt3sas"
266 tools_packages << "sas2ircu"
267 status_packages["sas2ircu-status"] ||= []
269 tools_packages << "megacli"
270 status_packages["megaclisas-status"] ||= []
272 tools_packages << "arcconf"
273 status_packages["aacraid-status"] ||= []
275 tools_packages << "areca"
279 node[:block_device].each do |name, attributes|
280 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
282 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
283 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
285 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
286 status_packages["cciss-vol-status"] |= [File.basename(sg)]
292 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
293 if tools_packages.include?(tools_package)
294 package tools_package
296 package tools_package do
302 if tools_packages.include?("areca")
307 repository "https://git.openstreetmap.org/private/areca.git"
314 directory "/opt/areca" do
320 include_recipe "apt::hwraid" unless status_packages.empty?
322 if status_packages.include?("cciss-vol-status")
323 template "/usr/local/bin/cciss-vol-statusd" do
324 source "cciss-vol-statusd.erb"
328 notifies :restart, "service[cciss-vol-statusd]"
331 systemd_service "cciss-vol-statusd" do
332 description "Check cciss_vol_status values in the background"
333 exec_start "/usr/local/bin/cciss-vol-statusd"
336 protect_system "full"
338 no_new_privileges true
339 notifies :restart, "service[cciss-vol-statusd]"
342 systemd_service "cciss-vol-statusd" do
346 template "/usr/local/bin/cciss-vol-statusd" do
351 %w[cciss-vol-status mpt-status sas2ircu-status megaclisas-status aacraid-status].each do |status_package|
352 if status_packages.include?(status_package)
353 package status_package
355 template "/etc/default/#{status_package}d" do
356 source "raid.default.erb"
360 variables :devices => status_packages[status_package]
363 service "#{status_package}d" do
364 action [:start, :enable]
365 supports :status => false, :restart => true, :reload => false
366 subscribes :restart, "template[/etc/default/#{status_package}d]"
369 package status_package do
373 file "/etc/default/#{status_package}d" do
379 disks = if node[:hardware][:disk]
380 node[:hardware][:disk][:disks]
385 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
387 nvmes = if node[:hardware][:pci]
388 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
397 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
399 if !intel_ssds.empty? || !intel_nvmes.empty?
402 sst_tool_version = "1.3"
403 sst_package_version = "#{sst_tool_version}.208-0"
405 remote_file "#{Chef::Config[:file_cache_path]}/SST_CLI_Linux_#{sst_tool_version}.zip" do
406 source "https://downloadmirror.intel.com/743764/SST_CLI_Linux_#{sst_tool_version}.zip"
409 execute "#{Chef::Config[:file_cache_path]}/SST_CLI_Linux_#{sst_tool_version}.zip" do
410 command "unzip SST_CLI_Linux_#{sst_tool_version}.zip sst_#{sst_package_version}_amd64.deb"
411 cwd Chef::Config[:file_cache_path]
414 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/sst_#{sst_package_version}_amd64.deb") }
417 dpkg_package "sst" do
418 version "#{sst_package_version}"
419 source "#{Chef::Config[:file_cache_path]}/sst_#{sst_package_version}_amd64.deb"
422 dpkg_package "intelmas" do
427 disks = disks.map do |disk|
428 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
430 if disk[:smart_device]
431 controller = node[:hardware][:disk][:controllers][disk[:controller]]
433 if controller && controller[:device]
434 device = controller[:device].sub("/dev/", "")
435 smart = disk[:smart_device]
437 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
438 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
439 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
440 elsif smart =~ /^.*,(\d+)$/
441 munin = "#{device}-#{Regexp.last_match(1)}"
442 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
443 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
446 device = disk[:device].sub("/dev/", "")
447 smart = disk[:smart_device]
449 if smart =~ /^.*,(\d+),(\d+),(\d+)$/
450 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
453 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
454 device = Regexp.last_match(1)
457 device = disk[:device].sub("/dev/", "")
467 :hddtemp => munin.tr("-:", "_")
471 disks = disks.compact.uniq
473 if disks.count.positive?
474 package "smartmontools"
476 template "/etc/cron.daily/update-smart-drivedb" do
477 source "update-smart-drivedb.erb"
483 template "/usr/local/bin/smartd-mailer" do
484 source "smartd-mailer.erb"
490 template "/etc/smartd.conf" do
491 source "smartd.conf.erb"
495 variables :disks => disks
498 template "/etc/default/smartmontools" do
499 source "smartmontools.erb"
505 service "smartmontools" do
506 action [:enable, :start]
507 subscribes :reload, "template[/etc/smartd.conf]"
508 subscribes :restart, "template[/etc/default/smartmontools]"
511 template "/etc/prometheus/collectors/smart.devices" do
512 source "smart.devices.erb"
516 variables :disks => disks
519 prometheus_collector "smart" do
523 # Don't try and do munin monitoring of disks behind
524 # an Areca controller as they only allow one thing to
525 # talk to the controller at a time and smartd will
526 # throw errors if it clashes with munin
527 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
530 munin_plugin "smart_#{disk[:munin]}" do
532 conf "munin.smart.erb"
533 conf_variables :disk => disk
538 action [:stop, :disable]
542 if disks.count.positive?
543 munin_plugin "hddtemp_smartctl" do
544 conf "munin.hddtemp.erb"
545 conf_variables :disks => disks
548 munin_plugin "hddtemp_smartctl" do
550 conf "munin.hddtemp.erb"
554 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
555 disks.map { |d| "smart_#{d[:munin]}" }
557 plugins.each do |plugin|
558 munin_plugin plugin do
560 conf "munin.smart.erb"
564 if File.exist?("/etc/mdadm/mdadm.conf")
565 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
566 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
571 file "/etc/mdadm/mdadm.conf" do
580 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
584 file "/etc/modules" do
588 node[:hardware][:modules].each do |module_name|
589 kernel_module module_name do
595 node[:hardware][:blacklisted_modules].each do |module_name|
596 kernel_module module_name do
601 if node[:hardware][:watchdog]
604 template "/etc/default/watchdog" do
605 source "watchdog.erb"
609 variables :module => node[:hardware][:watchdog]
612 service "watchdog" do
613 action [:enable, :start]
617 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
620 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
621 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
622 chip = format("coretemp-isa-%04d", cpu)
624 temps = if File.exist?("#{coretemp}/name")
625 Dir.glob("#{coretemp}/temp*_input").map do |temp|
626 File.basename(temp).sub("temp", "").sub("_input", "").to_i
629 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
630 File.basename(temp).sub("temp", "").sub("_input", "").to_i
635 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
639 temps.each_with_index do |temp, index|
640 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
644 execute "/etc/sensors.d/chef.conf" do
646 command "/usr/bin/sensors -s"
651 template "/etc/sensors.d/chef.conf" do
652 source "sensors.conf.erb"
656 notifies :run, "execute[/etc/sensors.d/chef.conf]"
660 if node[:hardware][:shm_size]
661 execute "remount-dev-shm" do
663 command "/bin/mount -o remount /dev/shm"
672 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
673 notifies :run, "execute[remount-dev-shm]"
677 prometheus_collector "ohai" do