Chef::Handler::Serf

A chef handler to publish serf events upon resource updates

Installation

gem install 'chef-handler-serf'

Usage

Configure chef client to use serf handler for publishing serf events when a particular resource is updated.

require 'chef/event_dispatch/serf'
event_handlers << Chef::EventDispatch::Serf.new(
  subscribe: ['service[apache2]']
  )

Now, whenever service apache2 is updated (stopped, started, restarted, reloaded etc),a new serf 'resource_updated' user event will be published with a payload encapsulating resource name and action as json. A remote server can consume the event with a handler.

require 'serfx/utils/handler'
require 'json'

include Serfx::Utils::Handler

on :user, 'resource_updated' do |event|
  data = JSON.parse(event.payload)
  if data['resource'] == 'service[apache2]'
    # do something
  end
end

run

Additional Options

chef handler for serf can be configured to ignore failures when serf node is down (Errno::ECONNREFUSED).

event_handlers << Chef::EventDispatch::Serf.new(ignore_failure: true)

Resource updated events can also be published as serf events using the publish meta attribute, introduced by chef-handler-serf.

template '/etc/haproxy.cfg' do
  publish true
  variables(foo: 'bar')
  notifies :restart, 'service[haproxy]'
end

Contributing

  1. Fork it ( https://github.com/PagerDuty/chef-handler-serf/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request