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.
20 include_recipe "tools"
21 include_recipe "munin"
23 ohai_plugin "hardware" do
24 template "ohai.rb.erb"
27 case node[:cpu][:"0"][:vendor_id]
29 package "intel-microcode"
31 package "amd64-microcode"
34 if node[:dmi] && node[:dmi][:system]
35 case node[:dmi][:system][:manufacturer]
37 manufacturer = node[:dmi][:base_board][:manufacturer]
38 product = node[:dmi][:base_board][:product_name]
40 manufacturer = node[:dmi][:system][:manufacturer]
41 product = node[:dmi][:system][:product_name]
44 manufacturer = "Unknown"
50 if node[:roles].include?("bytemark") || node[:roles].include?("exonetric")
58 package "hp-health" do
60 notifies :restart, "service[hp-health]"
63 service "hp-health" do
64 action [:enable, :start]
65 supports :status => true, :restart => true
68 if product.end_with?("Gen8", "Gen9")
71 notifies :restart, "service[hp-ams]"
75 action [:enable, :start]
76 supports :status => true, :restart => true
83 when "TYAN Computer Corporation"
87 when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW", "SYS-1028U-TN10RT+", "SYS-2028U-TN24R4T+", "SYS-1029P-WTRT", "Super Server"
95 package "open-vm-tools"
97 service "open-vm-tools" do
98 action [:enable, :start]
99 supports :status => true, :restart => true
102 # May need additional work per:
103 # https://github.com/vmware/open-vm-tools/issues/302
104 execute "vmware-toolbox-cmd-timesync-disable" do
105 command "/usr/bin/vmware-toolbox-cmd timesync disable"
109 units.sort.uniq.each do |unit|
110 service "serial-getty@ttyS#{unit}" do
111 action [:enable, :start]
115 # if we need a different / special kernel version to make the hardware
116 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
117 # ensure that we have the package installed. the grub template will
118 # make sure that this is the default on boot.
119 if node[:hardware][:grub][:kernel]
120 kernel_version = node[:hardware][:grub][:kernel]
122 package "linux-image-#{kernel_version}-generic"
123 package "linux-image-extra-#{kernel_version}-generic"
124 package "linux-headers-#{kernel_version}-generic"
125 package "linux-tools-#{kernel_version}-generic"
127 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
128 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
129 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
134 if File.exist?("/etc/default/grub")
135 execute "update-grub" do
137 command "/usr/sbin/update-grub"
140 template "/etc/default/grub" do
145 variables :units => units, :entry => grub_entry
146 notifies :run, "execute[update-grub]"
150 execute "update-initramfs" do
152 command "update-initramfs -u -k all"
157 template "/etc/initramfs-tools/conf.d/mdadm" do
158 source "initramfs-mdadm.erb"
162 notifies :run, "execute[update-initramfs]"
167 action [:enable, :start]
170 package "ipmitool" if node[:kernel][:modules].include?("ipmi_si")
174 template "/etc/default/irqbalance" do
175 source "irqbalance.erb"
181 service "irqbalance" do
182 action [:start, :enable]
183 supports :status => false, :restart => true, :reload => false
184 subscribes :restart, "template[/etc/default/irqbalance]"
187 # Link Layer Discovery Protocol Daemon
190 action [:start, :enable]
191 supports :status => true, :restart => true, :reload => true
197 node[:kernel][:modules].each_key do |modname|
200 tools_packages << "ssacli"
201 status_packages["cciss-vol-status"] ||= []
203 tools_packages << "ssacli"
204 status_packages["cciss-vol-status"] ||= []
206 tools_packages << "lsiutil"
207 status_packages["mpt-status"] ||= []
208 when "mpt2sas", "mpt3sas"
209 tools_packages << "sas2ircu"
210 status_packages["sas2ircu-status"] ||= []
212 tools_packages << "megactl"
213 status_packages["megaraid-status"] ||= []
215 tools_packages << "megacli"
216 status_packages["megaclisas-status"] ||= []
218 tools_packages << "arcconf"
219 status_packages["aacraid-status"] ||= []
221 tools_packages << "areca"
225 node[:block_device].each do |name, attributes|
226 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
228 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
229 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
231 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
232 status_packages["cciss-vol-status"] |= [File.basename(sg)]
237 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
238 if tools_packages.include?(tools_package)
239 package tools_package
241 package tools_package do
247 if tools_packages.include?("areca")
252 repository "https://git.openstreetmap.org/private/areca.git"
257 directory "/opt/areca" do
263 if status_packages.include?("cciss-vol-status")
264 template "/usr/local/bin/cciss-vol-statusd" do
265 source "cciss-vol-statusd.erb"
269 notifies :restart, "service[cciss-vol-statusd]"
272 systemd_service "cciss-vol-statusd" do
273 description "Check cciss_vol_status values in the background"
274 exec_start "/usr/local/bin/cciss-vol-statusd"
276 protect_system "full"
278 no_new_privileges true
279 notifies :restart, "service[cciss-vol-statusd]"
283 %w[cciss-vol-status mpt-status sas2ircu-status megaraid-status megaclisas-status aacraid-status].each do |status_package|
284 if status_packages.include?(status_package)
285 package status_package
287 template "/etc/default/#{status_package}d" do
288 source "raid.default.erb"
292 variables :devices => status_packages[status_package]
295 service "#{status_package}d" do
296 action [:start, :enable]
297 supports :status => false, :restart => true, :reload => false
298 subscribes :restart, "template[/etc/default/#{status_package}d]"
301 package status_package do
305 file "/etc/default/#{status_package}d" do
311 disks = if node[:hardware][:disk]
312 node[:hardware][:disk][:disks]
317 # intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
319 # nvmes = if node[:hardware][:pci]
320 # node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
325 # intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
327 # if !intel_ssds.empty? || !intel_nvmes.empty?
330 # intel_ssd_tool_version = "3.0.21"
332 # remote_file "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
333 # source "https://downloadmirror.intel.com/29115/eng/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip"
336 # execute "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
337 # command "unzip Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip isdct_#{intel_ssd_tool_version}-1_amd64.deb"
338 # cwd Chef::Config[:file_cache_path]
341 # not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct_#{intel_ssd_tool_version}-1_amd64.deb") }
344 # dpkg_package "isdct" do
345 # version "#{intel_ssd_tool_version}-1"
346 # source "#{Chef::Config[:file_cache_path]}/isdct_#{intel_ssd_tool_version}-1_amd64.deb"
350 disks = disks.map do |disk|
351 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
353 if disk[:smart_device]
354 controller = node[:hardware][:disk][:controllers][disk[:controller]]
356 if controller && controller[:device]
357 device = controller[:device].sub("/dev/", "")
358 smart = disk[:smart_device]
360 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
361 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
362 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
363 elsif smart =~ /^.*,(\d+)$/
364 munin = "#{device}-#{Regexp.last_match(1)}"
365 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
366 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
369 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
370 device = Regexp.last_match(1)
373 device = disk[:device].sub("/dev/", "")
383 :hddtemp => munin.tr("-:", "_")
387 disks = disks.compact.uniq
389 if disks.count.positive?
390 package "smartmontools"
392 template "/usr/local/bin/smartd-mailer" do
393 source "smartd-mailer.erb"
399 template "/etc/smartd.conf" do
400 source "smartd.conf.erb"
404 variables :disks => disks
407 template "/etc/default/smartmontools" do
408 source "smartmontools.erb"
415 action [:enable, :start]
416 subscribes :reload, "template[/etc/smartd.conf]"
417 subscribes :restart, "template[/etc/default/smartmontools]"
420 # Don't try and do munin monitoring of disks behind
421 # an Areca controller as they only allow one thing to
422 # talk to the controller at a time and smartd will
423 # throw errors if it clashes with munin
424 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
427 munin_plugin "smart_#{disk[:munin]}" do
429 conf "munin.smart.erb"
430 conf_variables :disk => disk
435 action [:stop, :disable]
439 if disks.count.positive?
440 munin_plugin "hddtemp_smartctl" do
441 conf "munin.hddtemp.erb"
442 conf_variables :disks => disks
445 munin_plugin "hddtemp_smartctl" do
447 conf "munin.hddtemp.erb"
451 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
452 disks.map { |d| "smart_#{d[:munin]}" }
454 plugins.each do |plugin|
455 munin_plugin plugin do
457 conf "munin.smart.erb"
461 if File.exist?("/etc/mdadm/mdadm.conf")
462 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
463 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
468 file "/etc/mdadm/mdadm.conf" do
477 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
481 template "/etc/modules" do
490 subscribes :start, "template[/etc/modules]"
493 if node[:hardware][:watchdog]
496 template "/etc/default/watchdog" do
497 source "watchdog.erb"
501 variables :module => node[:hardware][:watchdog]
504 service "watchdog" do
505 action [:enable, :start]
509 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
512 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
513 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
514 chip = format("coretemp-isa-%04d", cpu)
516 temps = if File.exist?("#{coretemp}/name")
517 Dir.glob("#{coretemp}/temp*_input").map do |temp|
518 File.basename(temp).sub("temp", "").sub("_input", "").to_i
521 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
522 File.basename(temp).sub("temp", "").sub("_input", "").to_i
527 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
531 temps.each_with_index do |temp, index|
532 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
536 execute "/etc/sensors.d/chef.conf" do
538 command "/usr/bin/sensors -s"
543 template "/etc/sensors.d/chef.conf" do
544 source "sensors.conf.erb"
548 notifies :run, "execute[/etc/sensors.d/chef.conf]"
552 if node[:hardware][:shm_size]
553 execute "remount-dev-shm" do
555 command "/bin/mount -o remount /dev/shm"
564 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
565 notifies :run, "execute[remount-dev-shm]"