summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-05-26 12:20:26 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-05-26 12:20:26 -0700
commit0aaab8954a2007a7bedd23a9799e76b0c03a01a4 (patch)
tree811f2bd1564fbb4a2186a20f237d682ef0f60148
parent26e36ab4cc760c032cacb4d80d65494308d29e27 (diff)
downloadchef-zero-0aaab8954a2007a7bedd23a9799e76b0c03a01a4.tar.gz
Add ability to print to other IO, fix memory store to be V2
-rw-r--r--lib/chef_zero/server.rb15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb
index be628af..7b5f59e 100644
--- a/lib/chef_zero/server.rb
+++ b/lib/chef_zero/server.rb
@@ -28,7 +28,7 @@ require 'webrick'
require 'chef_zero'
require 'chef_zero/cookbook_data'
require 'chef_zero/rest_router'
-require 'chef_zero/data_store/memory_store'
+require 'chef_zero/data_store/memory_store_v2'
require 'chef_zero/data_store/v1_to_v2_adapter'
require 'chef_zero/version'
@@ -108,7 +108,7 @@ module ChefZero
#
def data_store
@data_store ||= begin
- result = @options[:data_store] || DataStore::MemoryStore.new
+ result = @options[:data_store] || DataStore::MemoryStoreV2.new
if options[:single_org]
if result.respond_to?(:interface_version) && result.interface_version >= 2 && result.interface_version < 3
result.create_dir([ 'organizations' ], options[:single_org])
@@ -140,8 +140,8 @@ module ChefZero
# Start a Chef Zero server in the current thread. You can stop this server
# by canceling the current thread.
#
- # @param [Boolean] publish
- # publish the server information to STDOUT
+ # @param [Boolean|IO] publish
+ # publish the server information to the publish parameter or to STDOUT if it's "true"
#
# @return [nil]
# this method will block the main thread until interrupted
@@ -150,7 +150,8 @@ module ChefZero
publish = publish[:publish] if publish.is_a?(Hash) # Legacy API
if publish
- puts <<-EOH.gsub(/^ {10}/, '')
+ output = publish.respond_to?(:puts) ? publish : STDOUT
+ output.puts <<-EOH.gsub(/^ {10}/, '')
>> Starting Chef Zero (v#{ChefZero::VERSION})...
>> WEBrick (v#{WEBrick::VERSION}) on Rack (v#{Rack.release}) is listening at #{url}
>> Press CTRL+C to stop
@@ -225,9 +226,9 @@ module ChefZero
# server
#
def stop(wait = 5)
- Timeout.timeout(wait) do
+ if @thread
@server.shutdown
- @thread.join(wait) if @thread
+ @thread.join(wait)
end
rescue Timeout::Error
if @thread