Commit 8126ad9

mo khan <mo@mokhan.ca>
2015-05-03 20:09:16
add monit recipe.
1 parent 218e95f
recipes/default.rb
@@ -0,0 +1,35 @@
+packages = [
+  "curl",
+  "libcurl3", "libcurl3-gnutls", "libcurl4-openssl-dev",
+  "git-core",
+  "python-software-properties",
+  "build-essential",
+  "tklib",
+  "zlib1g-dev",
+  "libssl-dev",
+  "libreadline-gplv2-dev",
+  "libxml2",
+  "libxml2-dev",
+  "libxslt1-dev",
+  "gawk",
+  "libreadline6-dev",
+  "libyaml-dev",
+  "libsqlite3-dev",
+  "autoconf",
+  "libgdbm-dev",
+  "libncurses5-dev",
+  "automake",
+  "libtool",
+  "bison",
+  "pkg-config",
+  "libffi-dev",
+  "vim",
+]
+
+packages.each do |item|
+  package item do
+    action :upgrade
+  end
+end
+
+include_recipe "mokhan-myface::monit"
recipes/monit.rb
@@ -0,0 +1,18 @@
+configuration = node["monit"]
+
+package "monit" do
+  action :install
+end
+
+template "/etc/monit/monitrc" do
+  source "monit/monitrc.erb"
+  user "root"
+  group "root"
+  mode "0600"
+  variables(configuration)
+  notifies :restart, "service[monit]"
+end
+
+service "monit" do
+  action [:enable, :start]
+end
spec/default_spec.rb
@@ -1,2 +1,43 @@
 describe 'mokhan-myface::default' do
+  subject do
+    ChefSpec::SoloRunner.new do |node|
+    end.converge(described_recipe)
+  end
+
+  let(:packages) do
+    [
+      "curl",
+      "libcurl3",
+      "libcurl3-gnutls",
+      "libcurl4-openssl-dev",
+      "git-core",
+      "python-software-properties",
+      "build-essential",
+      "tklib",
+      "zlib1g-dev",
+      "libssl-dev",
+      "libreadline-gplv2-dev",
+      "libxml2",
+      "libxml2-dev",
+      "libxslt1-dev",
+      "gawk",
+      "libreadline6-dev",
+      "libyaml-dev",
+      "autoconf",
+      "libgdbm-dev",
+      "libncurses5-dev",
+      "automake",
+      "libtool",
+      "bison",
+      "pkg-config",
+      "libffi-dev",
+      "vim",
+    ]
+  end
+
+  it 'installs the base packages' do
+    packages.each do |package|
+      expect(subject).to upgrade_package(package)
+    end
+  end
 end
spec/monit_spec.rb
@@ -0,0 +1,20 @@
+describe "mokhan-myface::monit" do
+  subject do
+    ChefSpec::SoloRunner.new do |node|
+    end.converge(described_recipe)
+  end
+
+  it 'installs monit' do
+    expect(subject).to install_package('monit')
+  end
+
+  it 'lays down the monitrc' do
+    expect(subject).to create_template("/etc/monit/monitrc")
+      .with_user('root')
+      .with_group('root')
+  end
+
+  it 'starts the monit service' do
+    expect(subject).to start_service('monit')
+  end
+end
templates/monit/monitrc.erb
@@ -0,0 +1,16 @@
+set daemon 30
+
+set logfile /var/log/monit.log
+set idfile /var/lib/monit/id
+set statefile /var/lib/monit/state
+
+set eventqueue
+    basedir /var/lib/monit/events
+    slots 100
+
+check system <%= @application %>
+  if loadavg(5min) > 2 for 2 cycles then alert
+  if memory > 75% for 2 cycles then alert
+  if cpu(user) > 75% for 2 cycles then alert
+
+include /etc/monit/conf.d/*