Skip to content

Instantly share code, notes, and snippets.

@lusis
Created June 13, 2011 06:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lusis/7cb3b37fa013fcb4ef6e to your computer and use it in GitHub Desktop.
Save lusis/7cb3b37fa013fcb4ef6e to your computer and use it in GitHub Desktop.
require 'eventmachine'
require 'chef'
require 'chef/application/client'
class EM::ChefClient
include EM::Deferrable
def initialize
@client = Chef::Application::Client.new
end
def run_client
@client.run
end
end
module NoahChefClient
def post_init
puts "-- INCOMING!!!!"
@client = EM::ChefClient.new
end
def receive_data(data)
send_data "Starting a Chef Client Run\n"
@client.callback {
puts "Work's done...."
}
Thread.new {
@client.run_client
}
close_connection_after_writing
end
def unbind
puts "-- Disconnected"
end
end
EM.run do
at_exit { EM.run { puts "Restarting server...."; EM::start_server "127.0.0.1", 9090, NoahChefClient } }
puts "Starting up Chef Client. Ping me on port 9090"
EM::start_server "127.0.0.1", 9090, NoahChefClient
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment