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 "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")
61 package "hp-health" do
63 notifies :restart, "service[hp-health]"
66 service "hp-health" do
67 action [:enable, :start]
68 supports :status => true, :restart => true
71 if product.end_with?("Gen8", "Gen9")
74 notifies :restart, "service[hp-ams]"
78 action [:enable, :start]
79 supports :status => true, :restart => true
86 when "TYAN Computer Corporation"
90 when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW", "SYS-1028U-TN10RT+", "SYS-2028U-TN24R4T+", "SYS-1029P-WTRT", "Super Server"
98 package "open-vm-tools"
100 # Remove timeSync plugin completely
101 # https://github.com/vmware/open-vm-tools/issues/302
102 file "/usr/lib/open-vm-tools/plugins/vmsvc/libtimeSync.so" do
104 notifies :restart, "service[open-vm-tools]"
107 # Attempt to tell Host we are not interested in timeSync
108 execute "vmware-toolbox-cmd-timesync-disable" do
109 command "/usr/bin/vmware-toolbox-cmd timesync disable"
113 service "open-vm-tools" do
114 action [:enable, :start]
115 supports :status => true, :restart => true
119 units.sort.uniq.each do |unit|
120 service "serial-getty@ttyS#{unit}" do
121 action [:enable, :start]
125 # if we need a different / special kernel version to make the hardware
126 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
127 # ensure that we have the package installed. the grub template will
128 # make sure that this is the default on boot.
129 if node[:hardware][:grub][:kernel]
130 kernel_version = node[:hardware][:grub][:kernel]
132 package "linux-image-#{kernel_version}-generic"
133 package "linux-image-extra-#{kernel_version}-generic"
134 package "linux-headers-#{kernel_version}-generic"
135 package "linux-tools-#{kernel_version}-generic"
137 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
138 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
139 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
144 if File.exist?("/etc/default/grub")
145 execute "update-grub" do
147 command "/usr/sbin/update-grub"
150 template "/etc/default/grub" do
155 variables :units => units, :entry => grub_entry
156 notifies :run, "execute[update-grub]"
160 execute "update-initramfs" do
162 command "update-initramfs -u -k all"
167 template "/etc/initramfs-tools/conf.d/mdadm" do
168 source "initramfs-mdadm.erb"
172 notifies :run, "execute[update-initramfs]"
177 action [:enable, :start]
180 package "ipmitool" if node[:kernel][:modules].include?("ipmi_si")
184 service "irqbalance" do
185 action [:start, :enable]
186 supports :status => false, :restart => true, :reload => false
189 # Link Layer Discovery Protocol Daemon
192 action [:start, :enable]
193 supports :status => true, :restart => true, :reload => true
199 if node[:virtualization][:role] != "guest" ||
200 node[:virtualization][:system] != "lxd"
202 node[:kernel][:modules].each_key do |modname|
205 tools_packages << "ssacli"
206 status_packages["cciss-vol-status"] ||= []
208 tools_packages << "ssacli"
209 status_packages["cciss-vol-status"] ||= []
211 tools_packages << "lsiutil"
212 status_packages["mpt-status"] ||= []
213 when "mpt2sas", "mpt3sas"
214 tools_packages << "sas2ircu"
215 status_packages["sas2ircu-status"] ||= []
217 tools_packages << "megactl"
218 status_packages["megaraid-status"] ||= []
220 tools_packages << "megacli"
221 status_packages["megaclisas-status"] ||= []
223 tools_packages << "arcconf"
224 status_packages["aacraid-status"] ||= []
226 tools_packages << "areca"
230 node[:block_device].each do |name, attributes|
231 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
233 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
234 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
236 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
237 status_packages["cciss-vol-status"] |= [File.basename(sg)]
243 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
244 if tools_packages.include?(tools_package)
245 package tools_package
247 package tools_package do
253 if tools_packages.include?("areca")
258 repository "https://git.openstreetmap.org/private/areca.git"
262 not_if { ENV["TEST_KITCHEN"] }
265 directory "/opt/areca" do
271 if status_packages.include?("cciss-vol-status")
272 template "/usr/local/bin/cciss-vol-statusd" do
273 source "cciss-vol-statusd.erb"
277 notifies :restart, "service[cciss-vol-statusd]"
280 systemd_service "cciss-vol-statusd" do
281 description "Check cciss_vol_status values in the background"
282 exec_start "/usr/local/bin/cciss-vol-statusd"
284 protect_system "full"
286 no_new_privileges true
287 notifies :restart, "service[cciss-vol-statusd]"
290 systemd_service "cciss-vol-statusd" do
294 template "/usr/local/bin/cciss-vol-statusd" do
299 %w[cciss-vol-status mpt-status sas2ircu-status megaraid-status megaclisas-status aacraid-status].each do |status_package|
300 if status_packages.include?(status_package)
301 package status_package
303 template "/etc/default/#{status_package}d" do
304 source "raid.default.erb"
308 variables :devices => status_packages[status_package]
311 service "#{status_package}d" do
312 action [:start, :enable]
313 supports :status => false, :restart => true, :reload => false
314 subscribes :restart, "template[/etc/default/#{status_package}d]"
317 package status_package do
321 file "/etc/default/#{status_package}d" do
327 disks = if node[:hardware][:disk]
328 node[:hardware][:disk][:disks]
333 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
335 nvmes = if node[:hardware][:pci]
336 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
341 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
343 if !intel_ssds.empty? || !intel_nvmes.empty?
346 intel_ssd_tool_version = "3.0.24"
348 remote_file "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
349 source "https://downloadmirror.intel.com/29399/eng/Intel_SSD_DCT_#{intel_ssd_tool_version}_Linux%20.zip"
352 execute "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
353 command "unzip Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip isdct_#{intel_ssd_tool_version}-1_amd64.deb"
354 cwd Chef::Config[:file_cache_path]
357 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/isdct_#{intel_ssd_tool_version}-1_amd64.deb") }
360 dpkg_package "isdct" do
361 version "#{intel_ssd_tool_version}-1"
362 source "#{Chef::Config[:file_cache_path]}/isdct_#{intel_ssd_tool_version}-1_amd64.deb"
366 disks = disks.map do |disk|
367 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
369 if disk[:smart_device]
370 controller = node[:hardware][:disk][:controllers][disk[:controller]]
372 if controller && controller[:device]
373 device = controller[:device].sub("/dev/", "")
374 smart = disk[:smart_device]
376 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
377 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
378 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
379 elsif smart =~ /^.*,(\d+)$/
380 munin = "#{device}-#{Regexp.last_match(1)}"
381 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
382 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
385 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
386 device = Regexp.last_match(1)
389 device = disk[:device].sub("/dev/", "")
399 :hddtemp => munin.tr("-:", "_")
403 disks = disks.compact.uniq
405 if disks.count.positive?
406 package "smartmontools"
408 template "/usr/local/bin/smartd-mailer" do
409 source "smartd-mailer.erb"
415 template "/etc/smartd.conf" do
416 source "smartd.conf.erb"
420 variables :disks => disks
423 template "/etc/default/smartmontools" do
424 source "smartmontools.erb"
431 action [:enable, :start]
432 subscribes :reload, "template[/etc/smartd.conf]"
433 subscribes :restart, "template[/etc/default/smartmontools]"
436 # Don't try and do munin monitoring of disks behind
437 # an Areca controller as they only allow one thing to
438 # talk to the controller at a time and smartd will
439 # throw errors if it clashes with munin
440 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
443 munin_plugin "smart_#{disk[:munin]}" do
445 conf "munin.smart.erb"
446 conf_variables :disk => disk
451 action [:stop, :disable]
455 if disks.count.positive?
456 munin_plugin "hddtemp_smartctl" do
457 conf "munin.hddtemp.erb"
458 conf_variables :disks => disks
461 munin_plugin "hddtemp_smartctl" do
463 conf "munin.hddtemp.erb"
467 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
468 disks.map { |d| "smart_#{d[:munin]}" }
470 plugins.each do |plugin|
471 munin_plugin plugin do
473 conf "munin.smart.erb"
477 if File.exist?("/etc/mdadm/mdadm.conf")
478 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
479 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
484 file "/etc/mdadm/mdadm.conf" do
493 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
497 template "/etc/modules" do
506 subscribes :start, "template[/etc/modules]"
509 if node[:hardware][:watchdog]
512 template "/etc/default/watchdog" do
513 source "watchdog.erb"
517 variables :module => node[:hardware][:watchdog]
520 service "watchdog" do
521 action [:enable, :start]
525 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
528 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
529 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
530 chip = format("coretemp-isa-%04d", cpu)
532 temps = if File.exist?("#{coretemp}/name")
533 Dir.glob("#{coretemp}/temp*_input").map do |temp|
534 File.basename(temp).sub("temp", "").sub("_input", "").to_i
537 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
538 File.basename(temp).sub("temp", "").sub("_input", "").to_i
543 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
547 temps.each_with_index do |temp, index|
548 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
552 execute "/etc/sensors.d/chef.conf" do
554 command "/usr/bin/sensors -s"
559 template "/etc/sensors.d/chef.conf" do
560 source "sensors.conf.erb"
564 notifies :run, "execute[/etc/sensors.d/chef.conf]"
568 if node[:hardware][:shm_size]
569 execute "remount-dev-shm" do
571 command "/bin/mount -o remount /dev/shm"
580 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
581 notifies :run, "execute[remount-dev-shm]"