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"
228 %w[bus cache dimm iomca page socket-memory unknown].each do |trigger|
229 file "/etc/mcelog/#{trigger}-error-trigger.local" do
235 action [:stop, :disable]
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 if status_packages.include?("cciss-vol-status")
317 template "/usr/local/bin/cciss-vol-statusd" do
318 source "cciss-vol-statusd.erb"
322 notifies :restart, "service[cciss-vol-statusd]"
325 systemd_service "cciss-vol-statusd" do
326 description "Check cciss_vol_status values in the background"
327 exec_start "/usr/local/bin/cciss-vol-statusd"
330 protect_system "full"
332 no_new_privileges true
333 notifies :restart, "service[cciss-vol-statusd]"
336 systemd_service "cciss-vol-statusd" do
340 template "/usr/local/bin/cciss-vol-statusd" do
345 %w[cciss-vol-status mpt-status sas2ircu-status megaclisas-status aacraid-status].each do |status_package|
346 if status_packages.include?(status_package)
347 package status_package
349 template "/etc/default/#{status_package}d" do
350 source "raid.default.erb"
354 variables :devices => status_packages[status_package]
357 service "#{status_package}d" do
358 action [:start, :enable]
359 supports :status => false, :restart => true, :reload => false
360 subscribes :restart, "template[/etc/default/#{status_package}d]"
363 package status_package do
367 file "/etc/default/#{status_package}d" do
373 disks = if node[:hardware][:disk]
374 node[:hardware][:disk][:disks]
379 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
381 nvmes = if node[:hardware][:pci]
382 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
391 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
393 if !intel_ssds.empty? || !intel_nvmes.empty?
396 intel_mas_tool_version = "1.10"
397 intel_mas_package_version = "#{intel_mas_tool_version}.155-0"
399 remote_file "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
400 source "https://downloadmirror.intel.com/646992/Intel_MAS_CLI_Tool_Linux_#{intel_mas_tool_version}-v2.zip"
403 execute "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
404 command "unzip Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip intelmas_#{intel_mas_package_version}_amd64.deb"
405 cwd Chef::Config[:file_cache_path]
408 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb") }
411 dpkg_package "intelmas" do
412 version "#{intel_mas_package_version}"
413 source "#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb"
416 dpkg_package "isdct" do
421 disks = disks.map do |disk|
422 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
424 if disk[:smart_device]
425 controller = node[:hardware][:disk][:controllers][disk[:controller]]
427 if controller && controller[:device]
428 device = controller[:device].sub("/dev/", "")
429 smart = disk[:smart_device]
431 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
432 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
433 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
434 elsif smart =~ /^.*,(\d+)$/
435 munin = "#{device}-#{Regexp.last_match(1)}"
436 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
437 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
440 device = disk[:device].sub("/dev/", "")
441 smart = disk[:smart_device]
443 if smart =~ /^.*,(\d+),(\d+),(\d+)$/
444 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
447 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
448 device = Regexp.last_match(1)
451 device = disk[:device].sub("/dev/", "")
461 :hddtemp => munin.tr("-:", "_")
465 disks = disks.compact.uniq
467 if disks.count.positive?
468 package "smartmontools"
470 template "/etc/cron.daily/update-smart-drivedb" do
471 source "update-smart-drivedb.erb"
477 template "/usr/local/bin/smartd-mailer" do
478 source "smartd-mailer.erb"
484 template "/etc/smartd.conf" do
485 source "smartd.conf.erb"
489 variables :disks => disks
492 template "/etc/default/smartmontools" do
493 source "smartmontools.erb"
499 service "smartmontools" do
500 action [:enable, :start]
501 subscribes :reload, "template[/etc/smartd.conf]"
502 subscribes :restart, "template[/etc/default/smartmontools]"
505 template "/etc/prometheus/collectors/smart.devices" do
506 source "smart.devices.erb"
510 variables :disks => disks
513 prometheus_collector "smart" do
517 # Don't try and do munin monitoring of disks behind
518 # an Areca controller as they only allow one thing to
519 # talk to the controller at a time and smartd will
520 # throw errors if it clashes with munin
521 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
524 munin_plugin "smart_#{disk[:munin]}" do
526 conf "munin.smart.erb"
527 conf_variables :disk => disk
532 action [:stop, :disable]
536 if disks.count.positive?
537 munin_plugin "hddtemp_smartctl" do
538 conf "munin.hddtemp.erb"
539 conf_variables :disks => disks
542 munin_plugin "hddtemp_smartctl" do
544 conf "munin.hddtemp.erb"
548 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
549 disks.map { |d| "smart_#{d[:munin]}" }
551 plugins.each do |plugin|
552 munin_plugin plugin do
554 conf "munin.smart.erb"
558 if File.exist?("/etc/mdadm/mdadm.conf")
559 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
560 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
565 file "/etc/mdadm/mdadm.conf" do
574 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
578 file "/etc/modules" do
582 node[:hardware][:modules].each do |module_name|
583 kernel_module module_name do
589 node[:hardware][:blacklisted_modules].each do |module_name|
590 kernel_module module_name do
595 if node[:hardware][:watchdog]
598 template "/etc/default/watchdog" do
599 source "watchdog.erb"
603 variables :module => node[:hardware][:watchdog]
606 service "watchdog" do
607 action [:enable, :start]
611 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
614 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
615 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
616 chip = format("coretemp-isa-%04d", cpu)
618 temps = if File.exist?("#{coretemp}/name")
619 Dir.glob("#{coretemp}/temp*_input").map do |temp|
620 File.basename(temp).sub("temp", "").sub("_input", "").to_i
623 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
624 File.basename(temp).sub("temp", "").sub("_input", "").to_i
629 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
633 temps.each_with_index do |temp, index|
634 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
638 execute "/etc/sensors.d/chef.conf" do
640 command "/usr/bin/sensors -s"
645 template "/etc/sensors.d/chef.conf" do
646 source "sensors.conf.erb"
650 notifies :run, "execute[/etc/sensors.d/chef.conf]"
654 if node[:hardware][:shm_size]
655 execute "remount-dev-shm" do
657 command "/bin/mount -o remount /dev/shm"
666 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
667 notifies :run, "execute[remount-dev-shm]"
671 prometheus_collector "ohai" do