-
-
Save lusis/7cb3b37fa013fcb4ef6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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