poise / poise-monit

A Chef cookbook to manage Monit.
Apache License 2.0
9 stars 17 forks source link

Poise-Monit Cookbook

Build Status Gem Version Cookbook Version Coverage Gemnasium License

A Chef cookbook to manage Monit.

Quick Start

To install Monit and configure a mail server:

include_recipe 'poise-monit'

monit_config 'mailconfig' do
  content <<-EOH
SET MAILSERVER mail.example.com
SET ALERT devoops@example.com
EOH
end

To create a service managed by Monit with a health check:

poise_service 'apache2' do
  command '/usr/sbin/apache2 -f /etc/apache2/apache2.conf -DFOREGROUND'
  stop_signal 'WINCH'
  reload_signal 'USR1'
  provider :monit
  options :monit, checks: 'if failed host localhost port 80 protocol HTTP request "/" then restart'
end

Recipes

Attributes

For example, the poise-monit recipe can be customized by setting:

override_attributes({
  'poise-monit' => {
    'recipe' => {
      'daemon_interval' => 60,
      'event_slots' => 0,
    }
  }
})

Resources

monit

The monit resource installs and configures Monit.

monit 'monit' do
  daemon_interval 60
  event_slots 1000
end

Actions

Properties

Provider Options

The monit resource uses provide options for per-provider configuration. See the poise-service documentation for more information on using provider options.

monit_config

The monit_config resource writes out a Monit configuration file to the conf.d/ directory.

monit_config 'ssh' do
  source 'monit_ssh.conf.erb'
  variables threshold: 5
end

Actions

Properties

One of source or content is required.

monit_check

The monit_check resource writes out a Monit configuration file for a service check. It is a subclass of monit_config and so inherits its actions and properties. It defaults to being a process check.

monit_check 'httpd' do
  check 'if failed port 80 protocol http request "/_status" then restart'
  extra [
    'every 5 cycles',
    'group www',
  ]
end

Actions

Properties

Monit Providers

binaries

The binaries_bitbucket provider supports installing Monit from static binaries mirrored to BitBucket. This is the default provider if you are installing on an OS that has binaries available.

monit 'monit' do
  provider :binaries
end

NOTE: If BitBucket is unavailable you can set the url provider option to https://mmonit.com/monit/dist/binary/%{version}/monit-%{version}-%{machine_label}.tar.gz to use downloads directly from mmonit.com, however this server has a relatively strict download quota system so this is not recommended.

Provider Options

system

The system provider supports installing Monit from system packages. This requires EPEL for RHEL/CentOS as they do not ship Monit in the base OS repositories. Because this is not a default provider, EPEL is not a dependency of this cookbook, you will have to add it to your run list or as a dependency of a wrapper cookbook.

monit 'monit' do
  provider :system
end

Provider Options

dummy

The dummy provider supports using the monit resource with ChefSpec or other testing frameworks to not actually install Monit. It is used by default under ChefSpec.

monit 'monit' do
  provider :dummy
end

Provider Options

Service Provider

The monit service provider is included to allow poise_service resources to use Monit as the service manager. This uses the normal sysvinit provider from poise-service to generate the init scripts, but manages service state through Monit.

poise_service 'apache2' do
  command '/usr/sbin/apache2 -f /etc/apache2/apache2.conf -DFOREGROUND'
  stop_signal 'WINCH'
  reload_signal 'USR1'
  provider :monit
  options :monit, checks: 'if failed host localhost port 80 protocol HTTP request "/" then restart'
end

To set the monit provider as the global default, use poise-sevice-monit.

The service provider has two node attributes that can used for global tuning:

Options

Upgrading From monit

Upgrading from the older monit cookbook is relatively straightforward. The node['monit'] attributes can either be converted to node['poise-monit']['recipe'] if you want to use the default recipe, or you can invoke the monit resource in your own recipe code if needed.

When switching cookbooks in-place on a server, make sure you check for any conf.d/ config files created by the old cookbook. Notably conf.d/compat.conf may interfere with the configuration generation. You can remove it:

monit_config 'compat' do
  action :delete
end

Sponsors

Development sponsored by Bloomberg.

The Poise test server infrastructure is sponsored by Rackspace.

License

Copyright 2015-2017, Noah Kantrowitz

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.