Class: CloudCrowd::CommandLine
- Inherits:
-
Object
- Object
- CloudCrowd::CommandLine
- Defined in:
- lib/cloud_crowd/command_line.rb
Constant Summary collapse
- CONFIG_FILES =
Configuration files required for the
crowdcommand to function. ['config.yml', 'config.ru', 'database.yml']
- CC_ROOT =
Reference the absolute path to the root.
File.(File.dirname(__FILE__) + '/../..')
- BANNER =
Command-line banner for the usage message.
"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
-
#initialize ⇒ CommandLine
constructor
Creating a CloudCrowd::CommandLine runs from the contents of ARGV.
-
#run_console ⇒ Object
Spin up an IRB session with the CloudCrowd code loaded in, and a database connection established.
-
#run_install ⇒ Object
Install the required CloudCrowd configuration files into the specified directory, or the current one.
-
#run_load_schema ⇒ Object
Load in the database schema to the database specified in ‘database.yml’.
-
#run_node ⇒ Object
Launch a Node.
-
#run_server ⇒ Object
Convenience command for quickly spinning up the central server.
-
#usage ⇒ Object
Print
crowdusage.
Constructor Details
#initialize ⇒ CommandLine
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 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_console ⇒ Object
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_install ⇒ Object
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_schema ⇒ Object
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_node ⇒ Object
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'] = ['environment'] load_code Node.new([:port]) end |
#run_server ⇒ Object
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 [:port] ||= 9173 require 'rubygems' rackup_path = File.("#{@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 |
#usage ⇒ Object
Print crowd usage.
101 102 103 |
# File 'lib/cloud_crowd/command_line.rb', line 101 def usage puts "\n#{@option_parser}\n" end |