Skip to content

Commit

Permalink
new cookbook: fb_smartmon (#203)
Browse files Browse the repository at this point in the history
Summary:
This is a very simple cookbook to install and configure smartmontools.

This was primarily written by infcted

Pull Request resolved: #203

Test Plan: Potentially usable internally (we don't yet have a dedicated smartmon cookbook beyond engenv_smartd FWICT, but for now this would be an example on our open-source repo and not in use.

Differential Revision: D66516318

fbshipit-source-id: d1742fa753665cfdecd317354f0d69cd7f8d5005
  • Loading branch information
jaymzh authored and facebook-github-bot committed Dec 6, 2024
1 parent cc8e178 commit 53432dc
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions cookbooks/fb_init_sample/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
'fb_screen',
'fb_sdparm',
'fb_securetty',
'fb_smartmon',
'fb_storage',
'fb_stunnel',
'fb_sudo',
Expand Down
1 change: 1 addition & 0 deletions cookbooks/fb_init_sample/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
end
include_recipe 'fb_motd'
include_recipe 'fb_profile'
include_recipe 'fb_smartmon'

if node.firstboot_tier?
include_recipe 'fb_init_sample::firstboot'
Expand Down
29 changes: 29 additions & 0 deletions cookbooks/fb_smartmon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
fb_smartmon Cookbook
====================
This cookbook manages the package `smartmontools` and `smartctl`
as well as the server `smartd`

Requirements
------------

Attributes
----------
* node['fb_smartmon']['enable']
* node['fb_smartmon']['config'][$DIRECTIVE][$CONFIG]

Usage
-----
By default this cookbook will install the `smartmontools` package
which allows the `smartctl` command to be used.

By default `node['fb_smartmon']['enable']` is set to false which
disables the `smartd` service

Setting `node['fb_smartmon']['enable']` to `true` will enable the
`smartd` service

`node['fb_smartmon']['config'][$DIRECTIVE][$CONFIG]` controls
the `/etc/smartd.conf` config. The `$DIRECTIVE` can be a device
device such as `/dev/sda` - or a command such as `DEVICESCAN`
or `DEFAULT`. `$CONFIG` can be used to specify an options the
directive takes (see smartd.conf man pages).
34 changes: 34 additions & 0 deletions cookbooks/fb_smartmon/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# vim: syntax=ruby:expandtab:shiftwidth=2:softtabstop=2:tabstop=2
#
# Copyright (c) 2022-present, Vicarious, Inc.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

return unless node.linux?

if node['block_device'].keys.any? { |x| x.start_with?('nvme') }
devicetype = 'nvme'
else
devicetype = 'auto'
end

default['fb_smartmon'] = {
'enable' => false,
'config' => {
'devicescan' => {
'-d' => devicetype,
},
},
}
11 changes: 11 additions & 0 deletions cookbooks/fb_smartmon/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2022-present, Viarious, Inc.
name 'fb_smartmon'
maintainer 'Facebook'
maintainer_email 'noreply@facebook.com'
license 'All Rights Reserved'
source_url 'https://github.com/facebook/chef-cookbooks/'
description 'Installs/Configures fb_smartmon'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
# never EVER change this number, ever.
version '0.1.0'
depends 'fb_helpers'
40 changes: 40 additions & 0 deletions cookbooks/fb_smartmon/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Cookbook:: fb_smartmon
# Recipe:: default
#
# Copyright (c) 2016-present, Facebook, Inc.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

package 'smartmontools' do
action :upgrade
end

template '/etc/smartd.conf' do
owner 'root'
group 'root'
mode '0644'
end

service 'smartd' do
only_if { node['fb_smartmon']['enable'] }
action [:enable, :start]
end

service 'disable smartd' do
service_name 'smartd'
not_if { node['fb_smartmon']['enable'] }
action [:stop, :disable]
end
5 changes: 5 additions & 0 deletions cookbooks/fb_smartmon/templates/smartd.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file is controlled by Chef, do not modify!
<% node.default['fb_smartmon']['config'].each do |section, config| %>
<%= section.upcase %> <%= config.to_a.flatten.join(' ') %>

<% end %>

0 comments on commit 53432dc

Please sign in to comment.