Class: CloudCrowd::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud_crowd/command_line.rb

Constant Summary collapse

CONFIG_FILES =

Configuration files required for the crowd command to function.

['config.yml', 'config.ru', 'database.yml']
CC_ROOT =

Reference the absolute path to the root.

File.expand_path(File.dirname(__FILE__) + '/../..')
"CloudCrowd is a MapReduce-inspired Parallel Processing System for Ruby.\n\nWiki: http://wiki.github.com/documentcloud/cloud-crowd\nRdoc: http://rdoc.info/projects/documentcloud/cloud-crowd\n\nUsage: crowd COMMAND OPTIONS\n\nCommands:\n  install       Install the CloudCrowd configuration files to the specified directory\n  server        Start up the central server (requires a database)\n  node          Start up a worker node (only one node per machine, please)\n  console       Launch a CloudCrowd console, connected to the central database\n  load_schema   Load the schema into the database specified by database.yml\n\nOptions:\n"

Instance Method Summary collapse

Constructor Details

#initializeCommandLine

Creating a CloudCrowd::CommandLine runs from the contents of ARGV.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cloud_crowd/command_line.rb', line 32

def initialize
  parse_options
  command = ARGV.shift
  case command
  when 'console'      then run_console
  when 'server'       then run_server
  when 'node'         then run_node
  when 'load_schema'  then run_load_schema
  when 'install'      then run_install
  else                     usage
  end
end

Instance Method Details

#run_consoleObject

Spin up an IRB session with the CloudCrowd code loaded in, and a database connection established. The equivalent of Rails’ script/console.



47
48
49
50
51
52
53
54
# File 'lib/cloud_crowd/command_line.rb', line 47

def run_console
  require 'irb'
  require 'irb/completion'
  require 'pp'
  load_code
  connect_to_database(true)
  IRB.start
end

#run_installObject

Install the required CloudCrowd configuration files into the specified directory, or the current one.



90
91
92
93
94
95
96
97
98
# File 'lib/cloud_crowd/command_line.rb', line 90

def run_install
  require 'fileutils'
  install_path = ARGV.shift || '.'
  FileUtils.mkdir_p install_path unless File.exists?(install_path)
  install_file "#{CC_ROOT}/config/config.example.yml", "#{install_path}/config.yml"
  install_file "#{CC_ROOT}/config/config.example.ru", "#{install_path}/config.ru"
  install_file "#{CC_ROOT}/config/database.example.yml", "#{install_path}/database.yml"
  install_file "#{CC_ROOT}/actions", "#{install_path}/actions", true
end

#run_load_schemaObject

Load in the database schema to the database specified in ‘database.yml’.



82
83
84
85
86
# File 'lib/cloud_crowd/command_line.rb', line 82

def run_load_schema
  load_code
  connect_to_database(false)
  require 'cloud_crowd/schema.rb'
end

#run_nodeObject

Launch a Node. Please only run a single node per machine. The Node process will be long-lived, although its workers will come and go.



75
76
77
78
79
# File 'lib/cloud_crowd/command_line.rb', line 75

def run_node
  ENV['RACK_ENV'] = @options['environment']
  load_code
  Node.new(@options[:port])
end

#run_serverObject

Convenience command for quickly spinning up the central server. More sophisticated deployments, load-balancing across multiple app servers, should use the config.ru rackup file directly. This method will start a single Thin server, if Thin is installed, otherwise the rackup defaults (Mongrel, falling back to WEBrick). The equivalent of Rails’ script/server.



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/cloud_crowd/command_line.rb', line 61

def run_server
  ensure_config
  @options[:port] ||= 9173
  require 'rubygems'
  rackup_path = File.expand_path("#{@options[:config_path]}/config.ru")
  if Gem.available? 'thin'
    exec "thin -e #{@options[:environment]} -p #{@options[:port]} -R #{rackup_path} start"
  else
    exec "rackup -E #{@options[:environment]} -p #{@options[:port]} #{rackup_path}"
  end
end

#usageObject

Print crowd usage.



101
102
103
# File 'lib/cloud_crowd/command_line.rb', line 101

def usage
  puts "\n#{@option_parser}\n"
end