lib/cloud_crowd/command_line.rb in documentcloud-cloud-crowd-0.0.3 vs lib/cloud_crowd/command_line.rb in documentcloud-cloud-crowd-0.0.4

- old
+ new

@@ -4,11 +4,11 @@ class CommandLine # Configuration files required for the `crowd` command to function. CONFIG_FILES = ['config.yml', 'config.ru', 'database.yml'] - # Reference the absolute path to the root, because we're about to chdir. + # Reference the absolute path to the root. CC_ROOT = File.expand_path(File.dirname(__FILE__) + '/../..') # Path to the Daemons gem script which launches workers. WORKER_RUNNER = File.expand_path("#{CC_ROOT}/lib/cloud_crowd/runner.rb") @@ -56,11 +56,11 @@ # a single Thin server, if Thin is installed, otherwise the rackup defaults # (Mongrel, falling back to WEBrick). The equivalent of Rails' script/server. def run_server ensure_config require 'rubygems' - rackup_path = File.expand_path('config.ru') + rackup_path = File.expand_path("#{@options[:config_path]}/config.ru") if Gem.available? 'thin' exec "thin -e production -p #{@options[:port]} -R #{rackup_path} start" else exec "rackup -E production -p #{@options[:port]} #{rackup_path}" end @@ -104,17 +104,17 @@ # config.yml. def start_workers load_code num_workers = @options[:num_workers] || CloudCrowd.config[:num_workers] num_workers.times do - `CLOUD_CROWD_CONFIG='#{File.expand_path('config.yml')}' ruby #{WORKER_RUNNER} start` + `CLOUD_CROWD_CONFIG='#{File.expand_path(@options[:config_path] + "/config.yml")}' ruby #{WORKER_RUNNER} start` end end # For debugging, run a single worker in the current process, showing output. def run_worker - exec "CLOUD_CROWD_CONFIG='#{File.expand_path('config.yml')}' ruby #{WORKER_RUNNER} run" + exec "CLOUD_CROWD_CONFIG='#{File.expand_path(@options[:config_path] + "/config.yml")}' ruby #{WORKER_RUNNER} run" end # Stop all active workers. def stop_workers `ruby #{WORKER_RUNNER} stop` @@ -135,38 +135,34 @@ # Check for configuration files, either in the current directory, or in # the CLOUD_CROWD_CONFIG environment variable. Exit if they're not found. def ensure_config return if @config_found - Dir.chdir @options[:config_path] - CONFIG_FILES.all? {|f| File.exists? f } ? @config_dir = true : config_not_found + found = CONFIG_FILES.all? {|f| File.exists? "#{@options[:config_path]}/#{f}" } + found ? @config_dir = true : config_not_found end # Parse all options for all actions. # TODO: Think about parsing options per sub-command separately. def parse_options @options = { - :db_config => 'database.yml', :port => 9173, - :config_path => ENV['CLOUD_CROWD_CONFIG'] || '.', + :config_path => ENV['CLOUD_CROWD_CONFIG'] || '.' } @option_parser = OptionParser.new do |opts| opts.on('-c', '--config PATH', 'path to configuration directory') do |conf_path| @options[:config_path] = conf_path end - opts.on('-d', '--database-config PATH', 'path to database.yml') do |conf_path| - @options[:db_config] = conf_path - end opts.on('-n', '--num-workers NUM', OptionParser::DecimalInteger, 'number of worker processes') do |num| @options[:num_workers] = num end opts.on('-p', '--port PORT', 'central server port number') do |port_num| @options[:port] = port_num end opts.on_tail('-v', '--version', 'show version') do load_code - puts "CloudCrowd version #{CloudCrowd::VERSION}" + puts "CloudCrowd version #{VERSION}" exit end end @option_parser.banner = BANNER @option_parser.parse!(ARGV) @@ -176,17 +172,17 @@ # Not all commands require this. def load_code ensure_config require 'rubygems' require "#{CC_ROOT}/lib/cloud-crowd" - CloudCrowd.configure('config.yml') + CloudCrowd.configure("#{@options[:config_path]}/config.yml") end # Establish a connection to the central server's database. Not all commands # require this. def connect_to_database require 'cloud_crowd/models' - CloudCrowd.configure_database(@options[:db_config]) + CloudCrowd.configure_database("#{@options[:config_path]}/database.yml") end # Exit with an explanation if the configuration files couldn't be found. def config_not_found puts "`crowd` can't find the CloudCrowd configuration directory. Please either run `crowd` from inside of the configuration directory, or use `crowd -c path/to/config`" \ No newline at end of file