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 template "/etc/default/irqbalance" do
185 source "irqbalance.erb"
191 service "irqbalance" do
192 action [:start, :enable]
193 supports :status => false, :restart => true, :reload => false
194 subscribes :restart, "template[/etc/default/irqbalance]"
197 # Link Layer Discovery Protocol Daemon
200 action [:start, :enable]
201 supports :status => true, :restart => true, :reload => true
207 node[:kernel][:modules].each_key do |modname|
210 tools_packages << "ssacli"
211 status_packages["cciss-vol-status"] ||= []
213 tools_packages << "ssacli"
214 status_packages["cciss-vol-status"] ||= []
216 tools_packages << "lsiutil"
217 status_packages["mpt-status"] ||= []
218 when "mpt2sas", "mpt3sas"
219 tools_packages << "sas2ircu"
220 status_packages["sas2ircu-status"] ||= []
222 tools_packages << "megactl"
223 status_packages["megaraid-status"] ||= []
225 tools_packages << "megacli"
226 status_packages["megaclisas-status"] ||= []
228 tools_packages << "arcconf"
229 status_packages["aacraid-status"] ||= []
231 tools_packages << "areca"
235 node[:block_device].each do |name, attributes|
236 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
238 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
239 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
241 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
242 status_packages["cciss-vol-status"] |= [File.basename(sg)]
247 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
248 if tools_packages.include?(tools_package)
249 package tools_package
251 package tools_package do
257 if tools_packages.include?("areca")
262 repository "https://git.openstreetmap.org/private/areca.git"
266 not_if { ENV["TEST_KITCHEN"] }
269 directory "/opt/areca" do
275 if status_packages.include?("cciss-vol-status")
276 template "/usr/local/bin/cciss-vol-statusd" do
277 source "cciss-vol-statusd.erb"
281 notifies :restart, "service[cciss-vol-statusd]"
284 systemd_service "cciss-vol-statusd" do
285 description "Check cciss_vol_status values in the background"
286 exec_start "/usr/local/bin/cciss-vol-statusd"
288 protect_system "full"
290 no_new_privileges true
291 notifies :restart, "service[cciss-vol-statusd]"
295 %w[cciss-vol-status mpt-status sas2ircu-status megaraid-status megaclisas-status aacraid-status].each do |status_package|
296 if status_packages.include?(status_package)
297 package status_package
299 template "/etc/default/#{status_package}d" do
300 source "raid.default.erb"
304 variables :devices => status_packages[status_package]
307 service "#{status_package}d" do
308 action [:start, :enable]
309 supports :status => false, :restart => true, :reload => false
310 subscribes :restart, "template[/etc/default/#{status_package}d]"
313 package status_package do
317 file "/etc/default/#{status_package}d" do
323 disks = if node[:hardware][:disk]
324 node[:hardware][:disk][:disks]
329 # intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
331 # nvmes = if node[:hardware][:pci]
332 # node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
337 # intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
339 # if !intel_ssds.empty? || !intel_nvmes.empty?
342 # intel_ssd_tool_version = "3.0.21"
344 # remote_file "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
345 # source "https://downloadmirror.intel.com/29115/eng/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip"
348 # execute "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
349 # command "unzip Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip isdct_#{intel_ssd_tool_version}-1_amd64.deb"
350 # cwd Chef::Config[:file_cache_path]
353 # not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct_#{intel_ssd_tool_version}-1_amd64.deb") }
356 # dpkg_package "isdct" do
357 # version "#{intel_ssd_tool_version}-1"
358 # source "#{Chef::Config[:file_cache_path]}/isdct_#{intel_ssd_tool_version}-1_amd64.deb"
362 disks = disks.map do |disk|
363 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
365 if disk[:smart_device]
366 controller = node[:hardware][:disk][:controllers][disk[:controller]]
368 if controller && controller[:device]
369 device = controller[:device].sub("/dev/", "")
370 smart = disk[:smart_device]
372 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
373 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
374 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
375 elsif smart =~ /^.*,(\d+)$/
376 munin = "#{device}-#{Regexp.last_match(1)}"
377 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
378 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
381 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
382 device = Regexp.last_match(1)
385 device = disk[:device].sub("/dev/", "")
395 :hddtemp => munin.tr("-:", "_")
399 disks = disks.compact.uniq
401 if disks.count.positive?
402 package "smartmontools"
404 template "/usr/local/bin/smartd-mailer" do
405 source "smartd-mailer.erb"
411 template "/etc/smartd.conf" do
412 source "smartd.conf.erb"
416 variables :disks => disks
419 template "/etc/default/smartmontools" do
420 source "smartmontools.erb"
427 action [:enable, :start]
428 subscribes :reload, "template[/etc/smartd.conf]"
429 subscribes :restart, "template[/etc/default/smartmontools]"
432 # Don't try and do munin monitoring of disks behind
433 # an Areca controller as they only allow one thing to
434 # talk to the controller at a time and smartd will
435 # throw errors if it clashes with munin
436 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
439 munin_plugin "smart_#{disk[:munin]}" do
441 conf "munin.smart.erb"
442 conf_variables :disk => disk
447 action [:stop, :disable]
451 if disks.count.positive?
452 munin_plugin "hddtemp_smartctl" do
453 conf "munin.hddtemp.erb"
454 conf_variables :disks => disks
457 munin_plugin "hddtemp_smartctl" do
459 conf "munin.hddtemp.erb"
463 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
464 disks.map { |d| "smart_#{d[:munin]}" }
466 plugins.each do |plugin|
467 munin_plugin plugin do
469 conf "munin.smart.erb"
473 if File.exist?("/etc/mdadm/mdadm.conf")
474 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
475 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
480 file "/etc/mdadm/mdadm.conf" do
489 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
493 template "/etc/modules" do
502 subscribes :start, "template[/etc/modules]"
505 if node[:hardware][:watchdog]
508 template "/etc/default/watchdog" do
509 source "watchdog.erb"
513 variables :module => node[:hardware][:watchdog]
516 service "watchdog" do
517 action [:enable, :start]
521 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
524 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
525 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
526 chip = format("coretemp-isa-%04d", cpu)
528 temps = if File.exist?("#{coretemp}/name")
529 Dir.glob("#{coretemp}/temp*_input").map do |temp|
530 File.basename(temp).sub("temp", "").sub("_input", "").to_i
533 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
534 File.basename(temp).sub("temp", "").sub("_input", "").to_i
539 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
543 temps.each_with_index do |temp, index|
544 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
548 execute "/etc/sensors.d/chef.conf" do
550 command "/usr/bin/sensors -s"
555 template "/etc/sensors.d/chef.conf" do
556 source "sensors.conf.erb"
560 notifies :run, "execute[/etc/sensors.d/chef.conf]"
564 if node[:hardware][:shm_size]
565 execute "remount-dev-shm" do
567 command "/bin/mount -o remount /dev/shm"
576 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
577 notifies :run, "execute[remount-dev-shm]"