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"
231 if node[:virtualization][:role] != "guest" ||
232 (node[:virtualization][:system] != "lxc" &&
233 node[:virtualization][:system] != "lxd" &&
234 node[:virtualization][:system] != "openvz")
236 node[:kernel][:modules].each_key do |modname|
239 tools_packages << "ssacli"
240 status_packages["cciss-vol-status"] ||= []
242 tools_packages << "ssacli"
243 status_packages["cciss-vol-status"] ||= []
245 tools_packages << "lsiutil"
246 status_packages["mpt-status"] ||= []
247 when "mpt2sas", "mpt3sas"
248 tools_packages << "sas2ircu"
249 status_packages["sas2ircu-status"] ||= []
251 tools_packages << "megactl"
252 status_packages["megaraid-status"] ||= []
254 tools_packages << "megacli"
255 status_packages["megaclisas-status"] ||= []
257 tools_packages << "arcconf"
258 status_packages["aacraid-status"] ||= []
260 tools_packages << "areca"
264 node[:block_device].each do |name, attributes|
265 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
267 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
268 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
270 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
271 status_packages["cciss-vol-status"] |= [File.basename(sg)]
277 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
278 if tools_packages.include?(tools_package)
279 package tools_package
281 package tools_package do
287 if tools_packages.include?("areca")
292 repository "https://git.openstreetmap.org/private/areca.git"
299 directory "/opt/areca" do
305 if status_packages.include?("cciss-vol-status")
306 template "/usr/local/bin/cciss-vol-statusd" do
307 source "cciss-vol-statusd.erb"
311 notifies :restart, "service[cciss-vol-statusd]"
314 systemd_service "cciss-vol-statusd" do
315 description "Check cciss_vol_status values in the background"
316 exec_start "/usr/local/bin/cciss-vol-statusd"
318 protect_system "full"
320 no_new_privileges true
321 notifies :restart, "service[cciss-vol-statusd]"
324 systemd_service "cciss-vol-statusd" do
328 template "/usr/local/bin/cciss-vol-statusd" do
333 %w[cciss-vol-status mpt-status sas2ircu-status megaraid-status megaclisas-status aacraid-status].each do |status_package|
334 if status_packages.include?(status_package)
335 package status_package
337 template "/etc/default/#{status_package}d" do
338 source "raid.default.erb"
342 variables :devices => status_packages[status_package]
345 service "#{status_package}d" do
346 action [:start, :enable]
347 supports :status => false, :restart => true, :reload => false
348 subscribes :restart, "template[/etc/default/#{status_package}d]"
351 package status_package do
355 file "/etc/default/#{status_package}d" do
361 disks = if node[:hardware][:disk]
362 node[:hardware][:disk][:disks]
367 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
369 nvmes = if node[:hardware][:pci]
370 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
379 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
381 if !intel_ssds.empty? || !intel_nvmes.empty?
384 intel_mas_tool_version = "1.10"
385 intel_mas_package_version = "#{intel_mas_tool_version}.155-0"
387 remote_file "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
388 source "https://downloadmirror.intel.com/646992/Intel_MAS_CLI_Tool_Linux_#{intel_mas_tool_version}-v2.zip"
391 execute "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
392 command "unzip Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip intelmas_#{intel_mas_package_version}_amd64.deb"
393 cwd Chef::Config[:file_cache_path]
396 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb") }
399 dpkg_package "intelmas" do
400 version "#{intel_mas_package_version}"
401 source "#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb"
404 dpkg_package "isdct" do
409 disks = disks.map do |disk|
410 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
412 if disk[:smart_device]
413 controller = node[:hardware][:disk][:controllers][disk[:controller]]
415 if controller && controller[:device]
416 device = controller[:device].sub("/dev/", "")
417 smart = disk[:smart_device]
419 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
420 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
421 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
422 elsif smart =~ /^.*,(\d+)$/
423 munin = "#{device}-#{Regexp.last_match(1)}"
424 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
425 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
428 device = disk[:device].sub("/dev/", "")
429 smart = disk[:smart_device]
431 if smart =~ /^.*,(\d+),(\d+),(\d+)$/
432 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
435 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
436 device = Regexp.last_match(1)
439 device = disk[:device].sub("/dev/", "")
449 :hddtemp => munin.tr("-:", "_")
453 disks = disks.compact.uniq
455 if disks.count.positive?
456 package "smartmontools"
458 template "/etc/cron.daily/update-smart-drivedb" do
459 source "update-smart-drivedb.erb"
465 template "/usr/local/bin/smartd-mailer" do
466 source "smartd-mailer.erb"
472 template "/etc/smartd.conf" do
473 source "smartd.conf.erb"
477 variables :disks => disks
480 template "/etc/default/smartmontools" do
481 source "smartmontools.erb"
487 service "smartmontools" do
488 action [:enable, :start]
489 subscribes :reload, "template[/etc/smartd.conf]"
490 subscribes :restart, "template[/etc/default/smartmontools]"
493 template "/etc/prometheus/collectors/smart.devices" do
494 source "smart.devices.erb"
498 variables :disks => disks
501 prometheus_collector "smart" do
505 # Don't try and do munin monitoring of disks behind
506 # an Areca controller as they only allow one thing to
507 # talk to the controller at a time and smartd will
508 # throw errors if it clashes with munin
509 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
512 munin_plugin "smart_#{disk[:munin]}" do
514 conf "munin.smart.erb"
515 conf_variables :disk => disk
520 action [:stop, :disable]
524 if disks.count.positive?
525 munin_plugin "hddtemp_smartctl" do
526 conf "munin.hddtemp.erb"
527 conf_variables :disks => disks
530 munin_plugin "hddtemp_smartctl" do
532 conf "munin.hddtemp.erb"
536 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
537 disks.map { |d| "smart_#{d[:munin]}" }
539 plugins.each do |plugin|
540 munin_plugin plugin do
542 conf "munin.smart.erb"
546 if File.exist?("/etc/mdadm/mdadm.conf")
547 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
548 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
553 file "/etc/mdadm/mdadm.conf" do
562 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
566 file "/etc/modules" do
570 node[:hardware][:modules].each do |module_name|
571 kernel_module module_name do
577 node[:hardware][:blacklisted_modules].each do |module_name|
578 kernel_module module_name do
583 if node[:hardware][:watchdog]
586 template "/etc/default/watchdog" do
587 source "watchdog.erb"
591 variables :module => node[:hardware][:watchdog]
594 service "watchdog" do
595 action [:enable, :start]
599 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
602 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
603 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
604 chip = format("coretemp-isa-%04d", cpu)
606 temps = if File.exist?("#{coretemp}/name")
607 Dir.glob("#{coretemp}/temp*_input").map do |temp|
608 File.basename(temp).sub("temp", "").sub("_input", "").to_i
611 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
612 File.basename(temp).sub("temp", "").sub("_input", "").to_i
617 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
621 temps.each_with_index do |temp, index|
622 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
626 execute "/etc/sensors.d/chef.conf" do
628 command "/usr/bin/sensors -s"
633 template "/etc/sensors.d/chef.conf" do
634 source "sensors.conf.erb"
638 notifies :run, "execute[/etc/sensors.d/chef.conf]"
642 if node[:hardware][:shm_size]
643 execute "remount-dev-shm" do
645 command "/bin/mount -o remount /dev/shm"
654 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
655 notifies :run, "execute[remount-dev-shm]"