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")
62 execute "update-ilo" do
64 command "/usr/sbin/hponcfg -f /etc/ilo-defaults.xml"
67 template "/etc/ilo-defaults.xml" do
68 source "ilo-defaults.xml.erb"
72 notifies :run, "execute[update-ilo]"
75 package "hp-health" do
77 notifies :restart, "service[hp-health]"
78 only_if { node[:lsb][:release].to_f < 22.04 }
81 service "hp-health" do
82 action [:enable, :start]
83 supports :status => true, :restart => true
84 only_if { node[:lsb][:release].to_f < 22.04 }
87 if product.end_with?("Gen8", "Gen9")
90 notifies :restart, "service[hp-ams]"
94 action [:enable, :start]
95 supports :status => true, :restart => true
102 when "TYAN Computer Corporation"
109 package "open-vm-tools"
111 # Remove timeSync plugin completely
112 # https://github.com/vmware/open-vm-tools/issues/302
113 file "/usr/lib/open-vm-tools/plugins/vmsvc/libtimeSync.so" do
115 notifies :restart, "service[open-vm-tools]"
118 # Attempt to tell Host we are not interested in timeSync
119 execute "vmware-toolbox-cmd-timesync-disable" do
120 command "/usr/bin/vmware-toolbox-cmd timesync disable"
124 service "open-vm-tools" do
125 action [:enable, :start]
126 supports :status => true, :restart => true
130 units.sort.uniq.each do |unit|
131 service "serial-getty@ttyS#{unit}" do
132 action [:enable, :start]
136 # if we need a different / special kernel version to make the hardware
137 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
138 # ensure that we have the package installed. the grub template will
139 # make sure that this is the default on boot.
140 if node[:hardware][:grub][:kernel]
141 kernel_version = node[:hardware][:grub][:kernel]
143 package "linux-image-#{kernel_version}-generic"
144 package "linux-image-extra-#{kernel_version}-generic"
145 package "linux-headers-#{kernel_version}-generic"
146 package "linux-tools-#{kernel_version}-generic"
148 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
149 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
150 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
155 if File.exist?("/etc/default/grub")
156 execute "update-grub" do
158 command "/usr/sbin/update-grub"
162 template "/etc/default/grub" do
167 variables :units => units, :entry => grub_entry
168 notifies :run, "execute[update-grub]"
172 execute "update-initramfs" do
174 command "update-initramfs -u -k all"
179 template "/etc/initramfs-tools/conf.d/mdadm" do
180 source "initramfs-mdadm.erb"
184 notifies :run, "execute[update-initramfs]"
189 action [:enable, :start]
192 if node[:kernel][:modules].include?("ipmi_si")
194 package "freeipmi-tools"
196 template "/etc/prometheus/ipmi_local.yml" do
197 source "ipmi_local.yml.erb"
203 prometheus_exporter "ipmi" do
205 options "--config.file=/etc/prometheus/ipmi_local.yml"
206 subscribes :restart, "template[/etc/prometheus/ipmi_local.yml]"
212 service "irqbalance" do
213 action [:start, :enable]
214 supports :status => false, :restart => true, :reload => false
220 action [:start, :enable]
221 supports :status => true, :restart => true, :reload => true
224 ohai_plugin "lldp" do
225 template "lldp.rb.erb"
233 service "rasdaemon" do
234 action [:enable, :start]
237 prometheus_exporter "rasdaemon" do
244 if node[:virtualization][:role] != "guest" ||
245 (node[:virtualization][:system] != "lxc" &&
246 node[:virtualization][:system] != "lxd" &&
247 node[:virtualization][:system] != "openvz")
249 node[:kernel][:modules].each_key do |modname|
252 tools_packages << "ssacli"
253 status_packages["cciss-vol-status"] ||= []
255 tools_packages << "ssacli"
256 status_packages["cciss-vol-status"] ||= []
258 tools_packages << "lsiutil"
259 status_packages["mpt-status"] ||= []
260 when "mpt2sas", "mpt3sas"
261 tools_packages << "sas2ircu"
262 status_packages["sas2ircu-status"] ||= []
264 tools_packages << "megacli"
265 status_packages["megaclisas-status"] ||= []
267 tools_packages << "arcconf"
268 status_packages["aacraid-status"] ||= []
270 tools_packages << "areca"
274 node[:block_device].each do |name, attributes|
275 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
277 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
278 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
280 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
281 status_packages["cciss-vol-status"] |= [File.basename(sg)]
287 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
288 if tools_packages.include?(tools_package)
289 package tools_package
291 package tools_package do
297 if tools_packages.include?("areca")
302 repository "https://git.openstreetmap.org/private/areca.git"
309 directory "/opt/areca" do
315 if status_packages.include?("cciss-vol-status")
316 template "/usr/local/bin/cciss-vol-statusd" do
317 source "cciss-vol-statusd.erb"
321 notifies :restart, "service[cciss-vol-statusd]"
324 systemd_service "cciss-vol-statusd" do
325 description "Check cciss_vol_status values in the background"
326 exec_start "/usr/local/bin/cciss-vol-statusd"
329 protect_system "full"
331 no_new_privileges true
332 notifies :restart, "service[cciss-vol-statusd]"
335 systemd_service "cciss-vol-statusd" do
339 template "/usr/local/bin/cciss-vol-statusd" do
344 %w[cciss-vol-status mpt-status sas2ircu-status megaclisas-status aacraid-status].each do |status_package|
345 if status_packages.include?(status_package)
346 package status_package
348 template "/etc/default/#{status_package}d" do
349 source "raid.default.erb"
353 variables :devices => status_packages[status_package]
356 service "#{status_package}d" do
357 action [:start, :enable]
358 supports :status => false, :restart => true, :reload => false
359 subscribes :restart, "template[/etc/default/#{status_package}d]"
362 package status_package do
366 file "/etc/default/#{status_package}d" do
372 disks = if node[:hardware][:disk]
373 node[:hardware][:disk][:disks]
378 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
380 nvmes = if node[:hardware][:pci]
381 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
390 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
392 if !intel_ssds.empty? || !intel_nvmes.empty?
395 intel_mas_tool_version = "1.10"
396 intel_mas_package_version = "#{intel_mas_tool_version}.155-0"
398 remote_file "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
399 source "https://downloadmirror.intel.com/646992/Intel_MAS_CLI_Tool_Linux_#{intel_mas_tool_version}-v2.zip"
402 execute "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
403 command "unzip Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip intelmas_#{intel_mas_package_version}_amd64.deb"
404 cwd Chef::Config[:file_cache_path]
407 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb") }
410 dpkg_package "intelmas" do
411 version "#{intel_mas_package_version}"
412 source "#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb"
415 dpkg_package "isdct" do
420 disks = disks.map do |disk|
421 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
423 if disk[:smart_device]
424 controller = node[:hardware][:disk][:controllers][disk[:controller]]
426 if controller && controller[:device]
427 device = controller[:device].sub("/dev/", "")
428 smart = disk[:smart_device]
430 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
431 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
432 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
433 elsif smart =~ /^.*,(\d+)$/
434 munin = "#{device}-#{Regexp.last_match(1)}"
435 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
436 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
439 device = disk[:device].sub("/dev/", "")
440 smart = disk[:smart_device]
442 if smart =~ /^.*,(\d+),(\d+),(\d+)$/
443 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
446 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
447 device = Regexp.last_match(1)
450 device = disk[:device].sub("/dev/", "")
460 :hddtemp => munin.tr("-:", "_")
464 disks = disks.compact.uniq
466 if disks.count.positive?
467 package "smartmontools"
469 template "/etc/cron.daily/update-smart-drivedb" do
470 source "update-smart-drivedb.erb"
476 template "/usr/local/bin/smartd-mailer" do
477 source "smartd-mailer.erb"
483 template "/etc/smartd.conf" do
484 source "smartd.conf.erb"
488 variables :disks => disks
491 template "/etc/default/smartmontools" do
492 source "smartmontools.erb"
498 service "smartmontools" do
499 action [:enable, :start]
500 subscribes :reload, "template[/etc/smartd.conf]"
501 subscribes :restart, "template[/etc/default/smartmontools]"
504 template "/etc/prometheus/collectors/smart.devices" do
505 source "smart.devices.erb"
509 variables :disks => disks
512 prometheus_collector "smart" do
516 # Don't try and do munin monitoring of disks behind
517 # an Areca controller as they only allow one thing to
518 # talk to the controller at a time and smartd will
519 # throw errors if it clashes with munin
520 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
523 munin_plugin "smart_#{disk[:munin]}" do
525 conf "munin.smart.erb"
526 conf_variables :disk => disk
531 action [:stop, :disable]
535 if disks.count.positive?
536 munin_plugin "hddtemp_smartctl" do
537 conf "munin.hddtemp.erb"
538 conf_variables :disks => disks
541 munin_plugin "hddtemp_smartctl" do
543 conf "munin.hddtemp.erb"
547 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
548 disks.map { |d| "smart_#{d[:munin]}" }
550 plugins.each do |plugin|
551 munin_plugin plugin do
553 conf "munin.smart.erb"
557 if File.exist?("/etc/mdadm/mdadm.conf")
558 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
559 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
564 file "/etc/mdadm/mdadm.conf" do
573 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
577 file "/etc/modules" do
581 node[:hardware][:modules].each do |module_name|
582 kernel_module module_name do
588 node[:hardware][:blacklisted_modules].each do |module_name|
589 kernel_module module_name do
594 if node[:hardware][:watchdog]
597 template "/etc/default/watchdog" do
598 source "watchdog.erb"
602 variables :module => node[:hardware][:watchdog]
605 service "watchdog" do
606 action [:enable, :start]
610 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
613 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
614 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
615 chip = format("coretemp-isa-%04d", cpu)
617 temps = if File.exist?("#{coretemp}/name")
618 Dir.glob("#{coretemp}/temp*_input").map do |temp|
619 File.basename(temp).sub("temp", "").sub("_input", "").to_i
622 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
623 File.basename(temp).sub("temp", "").sub("_input", "").to_i
628 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
632 temps.each_with_index do |temp, index|
633 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
637 execute "/etc/sensors.d/chef.conf" do
639 command "/usr/bin/sensors -s"
644 template "/etc/sensors.d/chef.conf" do
645 source "sensors.conf.erb"
649 notifies :run, "execute[/etc/sensors.d/chef.conf]"
653 if node[:hardware][:shm_size]
654 execute "remount-dev-shm" do
656 command "/bin/mount -o remount /dev/shm"
665 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
666 notifies :run, "execute[remount-dev-shm]"
670 prometheus_collector "ohai" do