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 package "hp-health" do
64 notifies :restart, "service[hp-health]"
67 service "hp-health" do
68 action [:enable, :start]
69 supports :status => true, :restart => true
72 if product.end_with?("Gen8", "Gen9")
75 notifies :restart, "service[hp-ams]"
79 action [:enable, :start]
80 supports :status => true, :restart => true
87 when "TYAN Computer Corporation"
94 package "open-vm-tools"
96 # Remove timeSync plugin completely
97 # https://github.com/vmware/open-vm-tools/issues/302
98 file "/usr/lib/open-vm-tools/plugins/vmsvc/libtimeSync.so" do
100 notifies :restart, "service[open-vm-tools]"
103 # Attempt to tell Host we are not interested in timeSync
104 execute "vmware-toolbox-cmd-timesync-disable" do
105 command "/usr/bin/vmware-toolbox-cmd timesync disable"
109 service "open-vm-tools" do
110 action [:enable, :start]
111 supports :status => true, :restart => true
115 units.sort.uniq.each do |unit|
116 service "serial-getty@ttyS#{unit}" do
117 action [:enable, :start]
121 # if we need a different / special kernel version to make the hardware
122 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
123 # ensure that we have the package installed. the grub template will
124 # make sure that this is the default on boot.
125 if node[:hardware][:grub][:kernel]
126 kernel_version = node[:hardware][:grub][:kernel]
128 package "linux-image-#{kernel_version}-generic"
129 package "linux-image-extra-#{kernel_version}-generic"
130 package "linux-headers-#{kernel_version}-generic"
131 package "linux-tools-#{kernel_version}-generic"
133 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
134 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
135 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
140 if File.exist?("/etc/default/grub")
141 execute "update-grub" do
143 command "/usr/sbin/update-grub"
144 not_if { ENV["TEST_KITCHEN"] }
147 template "/etc/default/grub" do
152 variables :units => units, :entry => grub_entry
153 notifies :run, "execute[update-grub]"
157 execute "update-initramfs" do
159 command "update-initramfs -u -k all"
164 template "/etc/initramfs-tools/conf.d/mdadm" do
165 source "initramfs-mdadm.erb"
169 notifies :run, "execute[update-initramfs]"
174 action [:enable, :start]
177 if node[:kernel][:modules].include?("ipmi_si")
179 package "freeipmi-tools"
181 template "/etc/prometheus/ipmi_local.yml" do
182 source "ipmi_local.yml.erb"
188 prometheus_exporter "ipmi" do
190 options "--config.file=/etc/prometheus/ipmi_local.yml"
191 subscribes :restart, "template[/etc/prometheus/ipmi_local.yml]"
197 service "irqbalance" do
198 action [:start, :enable]
199 supports :status => false, :restart => true, :reload => false
202 # Link Layer Discovery Protocol Daemon
205 action [:start, :enable]
206 supports :status => true, :restart => true, :reload => true
212 if node[:virtualization][:role] != "guest" ||
213 (node[:virtualization][:system] != "lxc" &&
214 node[:virtualization][:system] != "lxd" &&
215 node[:virtualization][:system] != "openvz")
217 node[:kernel][:modules].each_key do |modname|
220 tools_packages << "ssacli"
221 status_packages["cciss-vol-status"] ||= []
223 tools_packages << "ssacli"
224 status_packages["cciss-vol-status"] ||= []
226 tools_packages << "lsiutil"
227 status_packages["mpt-status"] ||= []
228 when "mpt2sas", "mpt3sas"
229 tools_packages << "sas2ircu"
230 status_packages["sas2ircu-status"] ||= []
232 tools_packages << "megactl"
233 status_packages["megaraid-status"] ||= []
235 tools_packages << "megacli"
236 status_packages["megaclisas-status"] ||= []
238 tools_packages << "arcconf"
239 status_packages["aacraid-status"] ||= []
241 tools_packages << "areca"
245 node[:block_device].each do |name, attributes|
246 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
248 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
249 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
251 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
252 status_packages["cciss-vol-status"] |= [File.basename(sg)]
258 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
259 if tools_packages.include?(tools_package)
260 package tools_package
262 package tools_package do
268 if tools_packages.include?("areca")
273 repository "https://git.openstreetmap.org/private/areca.git"
277 not_if { ENV["TEST_KITCHEN"] }
280 directory "/opt/areca" do
286 if status_packages.include?("cciss-vol-status")
287 template "/usr/local/bin/cciss-vol-statusd" do
288 source "cciss-vol-statusd.erb"
292 notifies :restart, "service[cciss-vol-statusd]"
295 systemd_service "cciss-vol-statusd" do
296 description "Check cciss_vol_status values in the background"
297 exec_start "/usr/local/bin/cciss-vol-statusd"
299 protect_system "full"
301 no_new_privileges true
302 notifies :restart, "service[cciss-vol-statusd]"
305 systemd_service "cciss-vol-statusd" do
309 template "/usr/local/bin/cciss-vol-statusd" do
314 %w[cciss-vol-status mpt-status sas2ircu-status megaraid-status megaclisas-status aacraid-status].each do |status_package|
315 if status_packages.include?(status_package)
316 package status_package
318 template "/etc/default/#{status_package}d" do
319 source "raid.default.erb"
323 variables :devices => status_packages[status_package]
326 service "#{status_package}d" do
327 action [:start, :enable]
328 supports :status => false, :restart => true, :reload => false
329 subscribes :restart, "template[/etc/default/#{status_package}d]"
332 package status_package do
336 file "/etc/default/#{status_package}d" do
342 disks = if node[:hardware][:disk]
343 node[:hardware][:disk][:disks]
348 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
350 nvmes = if node[:hardware][:pci]
351 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
356 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
358 if !intel_ssds.empty? || !intel_nvmes.empty?
361 intel_mas_tool_version = "1.9"
362 intel_mas_package_version = "#{intel_mas_tool_version}.147-0"
364 remote_file "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
365 source "https://downloadmirror.intel.com/30556/eng/Intel%C2%AE_MAS_CLI_Tool_Linux_#{intel_mas_tool_version}.zip"
368 execute "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
369 command "unzip Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip intelmas_#{intel_mas_package_version}_amd64.deb"
370 cwd Chef::Config[:file_cache_path]
373 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb") }
376 dpkg_package "intelmas" do
377 version "#{intel_mas_package_version}"
378 source "#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb"
381 dpkg_package "isdct" do
386 disks = disks.map do |disk|
387 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
389 if disk[:smart_device]
390 controller = node[:hardware][:disk][:controllers][disk[:controller]]
392 if controller && controller[:device]
393 device = controller[:device].sub("/dev/", "")
394 smart = disk[:smart_device]
396 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
397 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
398 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
399 elsif smart =~ /^.*,(\d+)$/
400 munin = "#{device}-#{Regexp.last_match(1)}"
401 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
402 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
405 device = disk[:device].sub("/dev/", "")
406 smart = disk[:smart_device]
408 if smart =~ /^.*,(\d+),(\d+),(\d+)$/
409 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
412 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
413 device = Regexp.last_match(1)
416 device = disk[:device].sub("/dev/", "")
426 :hddtemp => munin.tr("-:", "_")
430 disks = disks.compact.uniq
432 if disks.count.positive?
433 package "smartmontools"
435 template "/etc/cron.daily/update-smart-drivedb" do
436 source "update-smart-drivedb.erb"
442 template "/usr/local/bin/smartd-mailer" do
443 source "smartd-mailer.erb"
449 template "/etc/smartd.conf" do
450 source "smartd.conf.erb"
454 variables :disks => disks
457 template "/etc/default/smartmontools" do
458 source "smartmontools.erb"
464 service "smartmontools" do
465 action [:enable, :start]
466 subscribes :reload, "template[/etc/smartd.conf]"
467 subscribes :restart, "template[/etc/default/smartmontools]"
470 template "/etc/prometheus/collectors/smart.devices" do
471 source "smart.devices.erb"
475 variables :disks => disks
478 prometheus_collector "smart" do
482 # Don't try and do munin monitoring of disks behind
483 # an Areca controller as they only allow one thing to
484 # talk to the controller at a time and smartd will
485 # throw errors if it clashes with munin
486 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
489 munin_plugin "smart_#{disk[:munin]}" do
491 conf "munin.smart.erb"
492 conf_variables :disk => disk
497 action [:stop, :disable]
501 if disks.count.positive?
502 munin_plugin "hddtemp_smartctl" do
503 conf "munin.hddtemp.erb"
504 conf_variables :disks => disks
507 munin_plugin "hddtemp_smartctl" do
509 conf "munin.hddtemp.erb"
513 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
514 disks.map { |d| "smart_#{d[:munin]}" }
516 plugins.each do |plugin|
517 munin_plugin plugin do
519 conf "munin.smart.erb"
523 if File.exist?("/etc/mdadm/mdadm.conf")
524 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
525 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
530 file "/etc/mdadm/mdadm.conf" do
539 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
543 template "/etc/modules" do
552 subscribes :start, "template[/etc/modules]"
555 if node[:hardware][:watchdog]
558 template "/etc/default/watchdog" do
559 source "watchdog.erb"
563 variables :module => node[:hardware][:watchdog]
566 service "watchdog" do
567 action [:enable, :start]
571 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
574 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
575 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
576 chip = format("coretemp-isa-%04d", cpu)
578 temps = if File.exist?("#{coretemp}/name")
579 Dir.glob("#{coretemp}/temp*_input").map do |temp|
580 File.basename(temp).sub("temp", "").sub("_input", "").to_i
583 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
584 File.basename(temp).sub("temp", "").sub("_input", "").to_i
589 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
593 temps.each_with_index do |temp, index|
594 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
598 execute "/etc/sensors.d/chef.conf" do
600 command "/usr/bin/sensors -s"
605 template "/etc/sensors.d/chef.conf" do
606 source "sensors.conf.erb"
610 notifies :run, "execute[/etc/sensors.d/chef.conf]"
614 if node[:hardware][:shm_size]
615 execute "remount-dev-shm" do
617 command "/bin/mount -o remount /dev/shm"
626 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
627 notifies :run, "execute[remount-dev-shm]"