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
103 when "TYAN Computer Corporation"
110 package "open-vm-tools"
112 # Remove timeSync plugin completely
113 # https://github.com/vmware/open-vm-tools/issues/302
114 file "/usr/lib/open-vm-tools/plugins/vmsvc/libtimeSync.so" do
116 notifies :restart, "service[open-vm-tools]"
119 # Attempt to tell Host we are not interested in timeSync
120 execute "vmware-toolbox-cmd-timesync-disable" do
121 command "/usr/bin/vmware-toolbox-cmd timesync disable"
125 service "open-vm-tools" do
126 action [:enable, :start]
127 supports :status => true, :restart => true
131 units.sort.uniq.each do |unit|
132 service "serial-getty@ttyS#{unit}" do
133 action [:enable, :start]
137 # if we need a different / special kernel version to make the hardware
138 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
139 # ensure that we have the package installed. the grub template will
140 # make sure that this is the default on boot.
141 if node[:hardware][:grub][:kernel]
142 kernel_version = node[:hardware][:grub][:kernel]
144 package "linux-image-#{kernel_version}-generic"
145 package "linux-image-extra-#{kernel_version}-generic"
146 package "linux-headers-#{kernel_version}-generic"
147 package "linux-tools-#{kernel_version}-generic"
149 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
150 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
151 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
156 if File.exist?("/etc/default/grub")
157 execute "update-grub" do
159 command "/usr/sbin/update-grub"
163 template "/etc/default/grub" do
168 variables :units => units, :entry => grub_entry
169 notifies :run, "execute[update-grub]"
173 execute "update-initramfs" do
175 command "update-initramfs -u -k all"
180 template "/etc/initramfs-tools/conf.d/mdadm" do
181 source "initramfs-mdadm.erb"
185 notifies :run, "execute[update-initramfs]"
190 action [:enable, :start]
193 if node[:kernel][:modules].include?("ipmi_si")
195 package "freeipmi-tools"
197 template "/etc/prometheus/ipmi_local.yml" do
198 source "ipmi_local.yml.erb"
204 prometheus_exporter "ipmi" do
206 options "--config.file=/etc/prometheus/ipmi_local.yml"
207 subscribes :restart, "template[/etc/prometheus/ipmi_local.yml]"
213 service "irqbalance" do
214 action [:start, :enable]
215 supports :status => false, :restart => true, :reload => false
221 action [:start, :enable]
222 supports :status => true, :restart => true, :reload => true
225 ohai_plugin "lldp" do
226 template "lldp.rb.erb"
234 service "rasdaemon" do
235 action [:enable, :start]
238 prometheus_exporter "rasdaemon" do
245 if node[:virtualization][:role] != "guest" ||
246 (node[:virtualization][:system] != "lxc" &&
247 node[:virtualization][:system] != "lxd" &&
248 node[:virtualization][:system] != "openvz")
250 node[:kernel][:modules].each_key do |modname|
253 tools_packages << "ssacli"
254 status_packages["cciss-vol-status"] ||= []
256 tools_packages << "ssacli"
257 status_packages["cciss-vol-status"] ||= []
259 tools_packages << "lsiutil"
260 status_packages["mpt-status"] ||= []
261 when "mpt2sas", "mpt3sas"
262 tools_packages << "sas2ircu"
263 status_packages["sas2ircu-status"] ||= []
265 tools_packages << "megacli"
266 status_packages["megaclisas-status"] ||= []
268 tools_packages << "arcconf"
269 status_packages["aacraid-status"] ||= []
271 tools_packages << "areca"
275 node[:block_device].each do |name, attributes|
276 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
278 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
279 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
281 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
282 status_packages["cciss-vol-status"] |= [File.basename(sg)]
288 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
289 if tools_packages.include?(tools_package)
290 package tools_package
292 package tools_package do
298 if tools_packages.include?("areca")
303 repository "https://git.openstreetmap.org/private/areca.git"
310 directory "/opt/areca" do
316 include_recipe "apt::hwraid" unless status_packages.empty?
318 if status_packages.include?("cciss-vol-status")
319 template "/usr/local/bin/cciss-vol-statusd" do
320 source "cciss-vol-statusd.erb"
324 notifies :restart, "service[cciss-vol-statusd]"
327 systemd_service "cciss-vol-statusd" do
328 description "Check cciss_vol_status values in the background"
329 exec_start "/usr/local/bin/cciss-vol-statusd"
332 protect_system "full"
334 no_new_privileges true
335 notifies :restart, "service[cciss-vol-statusd]"
338 systemd_service "cciss-vol-statusd" do
342 template "/usr/local/bin/cciss-vol-statusd" do
347 %w[cciss-vol-status mpt-status sas2ircu-status megaclisas-status aacraid-status].each do |status_package|
348 if status_packages.include?(status_package)
349 package status_package
351 template "/etc/default/#{status_package}d" do
352 source "raid.default.erb"
356 variables :devices => status_packages[status_package]
359 service "#{status_package}d" do
360 action [:start, :enable]
361 supports :status => false, :restart => true, :reload => false
362 subscribes :restart, "template[/etc/default/#{status_package}d]"
365 package status_package do
369 file "/etc/default/#{status_package}d" do
375 disks = if node[:hardware][:disk]
376 node[:hardware][:disk][:disks]
381 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
383 nvmes = if node[:hardware][:pci]
384 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
393 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
395 if !intel_ssds.empty? || !intel_nvmes.empty?
398 intel_mas_tool_version = "1.10"
399 intel_mas_package_version = "#{intel_mas_tool_version}.155-0"
401 remote_file "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
402 source "https://downloadmirror.intel.com/646992/Intel_MAS_CLI_Tool_Linux_#{intel_mas_tool_version}-v2.zip"
405 execute "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
406 command "unzip Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip intelmas_#{intel_mas_package_version}_amd64.deb"
407 cwd Chef::Config[:file_cache_path]
410 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb") }
413 dpkg_package "intelmas" do
414 version "#{intel_mas_package_version}"
415 source "#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb"
418 dpkg_package "isdct" do
423 disks = disks.map do |disk|
424 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
426 if disk[:smart_device]
427 controller = node[:hardware][:disk][:controllers][disk[:controller]]
429 if controller && controller[:device]
430 device = controller[:device].sub("/dev/", "")
431 smart = disk[:smart_device]
433 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
434 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
435 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
436 elsif smart =~ /^.*,(\d+)$/
437 munin = "#{device}-#{Regexp.last_match(1)}"
438 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
439 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
442 device = disk[:device].sub("/dev/", "")
443 smart = disk[:smart_device]
445 if smart =~ /^.*,(\d+),(\d+),(\d+)$/
446 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
449 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
450 device = Regexp.last_match(1)
453 device = disk[:device].sub("/dev/", "")
463 :hddtemp => munin.tr("-:", "_")
467 disks = disks.compact.uniq
469 if disks.count.positive?
470 package "smartmontools"
472 template "/etc/cron.daily/update-smart-drivedb" do
473 source "update-smart-drivedb.erb"
479 template "/usr/local/bin/smartd-mailer" do
480 source "smartd-mailer.erb"
486 template "/etc/smartd.conf" do
487 source "smartd.conf.erb"
491 variables :disks => disks
494 template "/etc/default/smartmontools" do
495 source "smartmontools.erb"
501 service "smartmontools" do
502 action [:enable, :start]
503 subscribes :reload, "template[/etc/smartd.conf]"
504 subscribes :restart, "template[/etc/default/smartmontools]"
507 template "/etc/prometheus/collectors/smart.devices" do
508 source "smart.devices.erb"
512 variables :disks => disks
515 prometheus_collector "smart" do
519 # Don't try and do munin monitoring of disks behind
520 # an Areca controller as they only allow one thing to
521 # talk to the controller at a time and smartd will
522 # throw errors if it clashes with munin
523 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
526 munin_plugin "smart_#{disk[:munin]}" do
528 conf "munin.smart.erb"
529 conf_variables :disk => disk
534 action [:stop, :disable]
538 if disks.count.positive?
539 munin_plugin "hddtemp_smartctl" do
540 conf "munin.hddtemp.erb"
541 conf_variables :disks => disks
544 munin_plugin "hddtemp_smartctl" do
546 conf "munin.hddtemp.erb"
550 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
551 disks.map { |d| "smart_#{d[:munin]}" }
553 plugins.each do |plugin|
554 munin_plugin plugin do
556 conf "munin.smart.erb"
560 if File.exist?("/etc/mdadm/mdadm.conf")
561 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
562 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
567 file "/etc/mdadm/mdadm.conf" do
576 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
580 file "/etc/modules" do
584 node[:hardware][:modules].each do |module_name|
585 kernel_module module_name do
591 node[:hardware][:blacklisted_modules].each do |module_name|
592 kernel_module module_name do
597 if node[:hardware][:watchdog]
600 template "/etc/default/watchdog" do
601 source "watchdog.erb"
605 variables :module => node[:hardware][:watchdog]
608 service "watchdog" do
609 action [:enable, :start]
613 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
616 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
617 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
618 chip = format("coretemp-isa-%04d", cpu)
620 temps = if File.exist?("#{coretemp}/name")
621 Dir.glob("#{coretemp}/temp*_input").map do |temp|
622 File.basename(temp).sub("temp", "").sub("_input", "").to_i
625 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
626 File.basename(temp).sub("temp", "").sub("_input", "").to_i
631 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
635 temps.each_with_index do |temp, index|
636 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
640 execute "/etc/sensors.d/chef.conf" do
642 command "/usr/bin/sensors -s"
647 template "/etc/sensors.d/chef.conf" do
648 source "sensors.conf.erb"
652 notifies :run, "execute[/etc/sensors.d/chef.conf]"
656 if node[:hardware][:shm_size]
657 execute "remount-dev-shm" do
659 command "/bin/mount -o remount /dev/shm"
668 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
669 notifies :run, "execute[remount-dev-shm]"
673 prometheus_collector "ohai" do