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 if status_packages.include?("cciss-vol-status")
343 template "/usr/local/bin/cciss-vol-statusd" do
344 source "cciss-vol-statusd.erb"
348 notifies :restart, "service[cciss-vol-statusd]"
351 systemd_service "cciss-vol-statusd" do
352 description "Check cciss_vol_status values in the background"
353 exec_start "/usr/local/bin/cciss-vol-statusd"
356 protect_system "full"
358 no_new_privileges true
359 notifies :restart, "service[cciss-vol-statusd]"
362 systemd_service "cciss-vol-statusd" do
366 template "/usr/local/bin/cciss-vol-statusd" do
371 %w[cciss-vol-status mpt-status sas2ircu-status megaclisas-status aacraid-status].each do |status_package|
372 if status_packages.include?(status_package)
373 package status_package
375 template "/etc/default/#{status_package}d" do
376 source "raid.default.erb"
380 variables :devices => status_packages[status_package]
383 service "#{status_package}d" do
384 action [:start, :enable]
385 supports :status => false, :restart => true, :reload => false
386 subscribes :restart, "template[/etc/default/#{status_package}d]"
389 package status_package do
393 file "/etc/default/#{status_package}d" do
399 disks = if node[:hardware][:disk]
400 node[:hardware][:disk][:disks]
405 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
407 nvmes = if node[:hardware][:pci]
408 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
417 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
419 if !intel_ssds.empty? || !intel_nvmes.empty?
422 sst_tool_version = "1.3"
423 sst_package_version = "#{sst_tool_version}.208-0"
425 # remote_file "#{Chef::Config[:file_cache_path]}/SST_CLI_Linux_#{sst_tool_version}.zip" do
426 # source "https://downloadmirror.intel.com/743764/SST_CLI_Linux_#{sst_tool_version}.zip"
429 execute "#{Chef::Config[:file_cache_path]}/SST_CLI_Linux_#{sst_tool_version}.zip" do
430 command "unzip SST_CLI_Linux_#{sst_tool_version}.zip sst_#{sst_package_version}_amd64.deb"
431 cwd Chef::Config[:file_cache_path]
434 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/sst_#{sst_package_version}_amd64.deb") }
437 dpkg_package "sst" do
438 version "#{sst_package_version}"
439 source "#{Chef::Config[:file_cache_path]}/sst_#{sst_package_version}_amd64.deb"
442 dpkg_package "intelmas" do
447 disks = disks.map do |disk|
448 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
450 if disk[:smart_device]
451 controller = node[:hardware][:disk][:controllers][disk[:controller]]
453 if controller && controller[:device]
454 device = controller[:device].sub("/dev/", "")
455 smart = disk[:smart_device]
457 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
458 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
459 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
460 elsif smart =~ /^.*,(\d+)$/
461 munin = "#{device}-#{Regexp.last_match(1)}"
462 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
463 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
466 device = disk[:device].sub("/dev/", "")
467 smart = disk[:smart_device]
469 if smart =~ /^.*,(\d+),(\d+),(\d+)$/
470 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
473 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
474 device = Regexp.last_match(1)
477 device = disk[:device].sub("/dev/", "")
481 next if device.nil? || munin.nil?
487 :hddtemp => munin.tr("-:", "_")
491 disks = disks.compact.uniq
493 if disks.count.positive?
494 package "smartmontools"
496 template "/etc/cron.daily/update-smart-drivedb" do
497 source "update-smart-drivedb.erb"
503 template "/usr/local/bin/smartd-mailer" do
504 source "smartd-mailer.erb"
510 template "/etc/smartd.conf" do
511 source "smartd.conf.erb"
515 variables :disks => disks
518 template "/etc/default/smartmontools" do
519 source "smartmontools.erb"
525 service "smartmontools" do
526 action [:enable, :start]
527 subscribes :reload, "template[/etc/smartd.conf]"
528 subscribes :restart, "template[/etc/default/smartmontools]"
531 template "/etc/prometheus/collectors/smart.devices" do
532 source "smart.devices.erb"
536 variables :disks => disks
539 prometheus_collector "smart" do
542 capability_bounding_set %w[CAP_DAC_OVERRIDE CAP_SYS_ADMIN CAP_SYS_RAWIO]
543 private_devices false
548 # Don't try and do munin monitoring of disks behind
549 # an Areca controller as they only allow one thing to
550 # talk to the controller at a time and smartd will
551 # throw errors if it clashes with munin
552 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
555 munin_plugin "smart_#{disk[:munin]}" do
557 conf "munin.smart.erb"
558 conf_variables :disk => disk
563 action [:stop, :disable]
567 if disks.count.positive?
568 munin_plugin "hddtemp_smartctl" do
569 conf "munin.hddtemp.erb"
570 conf_variables :disks => disks
573 munin_plugin "hddtemp_smartctl" do
575 conf "munin.hddtemp.erb"
579 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
580 disks.map { |d| "smart_#{d[:munin]}" }
582 plugins.each do |plugin|
583 munin_plugin plugin do
585 conf "munin.smart.erb"
589 if File.exist?("/etc/mdadm/mdadm.conf")
590 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
591 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
596 file "/etc/mdadm/mdadm.conf" do
603 service "mdmonitor" do
605 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
609 file "/etc/modules" do
613 node[:hardware][:modules].each do |module_name|
614 kernel_module module_name do
620 node[:hardware][:blacklisted_modules].each do |module_name|
621 kernel_module module_name do
626 if node[:hardware][:watchdog]
629 template "/etc/default/watchdog" do
630 source "watchdog.erb"
634 variables :module => node[:hardware][:watchdog]
637 service "watchdog" do
638 action [:enable, :start]
642 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
645 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
646 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
647 chip = format("coretemp-isa-%04d", cpu)
649 temps = if File.exist?("#{coretemp}/name")
650 Dir.glob("#{coretemp}/temp*_input").map do |temp|
651 File.basename(temp).sub("temp", "").sub("_input", "").to_i
654 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
655 File.basename(temp).sub("temp", "").sub("_input", "").to_i
660 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
664 temps.each_with_index do |temp, index|
665 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
669 execute "/etc/sensors.d/chef.conf" do
671 command "/usr/bin/sensors -s"
676 template "/etc/sensors.d/chef.conf" do
677 source "sensors.conf.erb"
681 notifies :run, "execute[/etc/sensors.d/chef.conf]"
685 if node[:hardware][:shm_size]
686 execute "remount-dev-shm" do
688 command "/bin/mount -o remount /dev/shm"
697 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
698 notifies :run, "execute[remount-dev-shm]"
702 prometheus_collector "ohai" do
706 capability_bounding_set %w[CAP_DAC_OVERRIDE CAP_SYS_ADMIN CAP_SYS_RAWIO]
707 private_devices false
710 protect_kernel_modules false