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 \n server -d [start | stop | restart] Servers and nodes can be launched as\n node -d [start | stop | restart] daemons, then stopped or restarted.\n\nOptions:\n"
Instance Method Summary collapse
-
#initialize ⇒ CommandLine
constructor
Creating a CloudCrowd::CommandLine runs from the contents of ARGV.
-
#restart_node ⇒ Object
Restart the daemonized Node, if it exists.
-
#restart_server ⇒ Object
Restart the daemonized central server.
-
#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(subcommand) ⇒ Object
‘crowd node` can either ’start’, ‘stop’, or ‘restart’.
-
#run_server(subcommand) ⇒ Object
‘crowd server` can either ’start’, ‘stop’, or ‘restart’.
-
#start_node ⇒ Object
Launch a Node.
-
#start_server ⇒ Object
Convenience command for quickly spinning up the central server.
-
#stop_node ⇒ Object
If the daemonized Node is running, stop it.
-
#stop_server ⇒ Object
Stop the daemonized central server, if it exists.
-
#usage ⇒ Object
Print
crowdusage.
Constructor Details
#initialize ⇒ CommandLine
Creating a CloudCrowd::CommandLine runs from the contents of ARGV.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cloud_crowd/command_line.rb', line 35 def initialize command = ARGV.shift subcommand = ARGV.shift case command when 'console' then run_console when 'server' then run_server(subcommand) when 'node' then run_node(subcommand) when 'load_schema' then run_load_schema when 'install' then run_install else usage end end |
Instance Method Details
#restart_node ⇒ Object
Restart the daemonized Node, if it exists.
127 128 129 130 131 |
# File 'lib/cloud_crowd/command_line.rb', line 127 def restart_node stop_node sleep 1 start_node end |
#restart_server ⇒ Object
Restart the daemonized central server.
93 94 95 96 97 |
# File 'lib/cloud_crowd/command_line.rb', line 93 def restart_server stop_server sleep 1 start_server end |
#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.
51 52 53 54 55 56 57 58 |
# File 'lib/cloud_crowd/command_line.rb', line 51 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.
142 143 144 145 146 147 148 149 150 |
# File 'lib/cloud_crowd/command_line.rb', line 142 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’.
134 135 136 137 138 |
# File 'lib/cloud_crowd/command_line.rb', line 134 def run_load_schema load_code connect_to_database(false) require 'cloud_crowd/schema.rb' end |
#run_node(subcommand) ⇒ Object
‘crowd node` can either ’start’, ‘stop’, or ‘restart’.
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/cloud_crowd/command_line.rb', line 100 def run_node(subcommand) ensure_config load_code subcommand ||= 'start' case subcommand when 'start' then start_node when 'stop' then stop_node when 'restart' then restart_node end end |
#run_server(subcommand) ⇒ Object
‘crowd server` can either ’start’, ‘stop’, or ‘restart’.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cloud_crowd/command_line.rb', line 61 def run_server(subcommand) ensure_config load_code subcommand ||= 'start' case subcommand when 'start' then start_server when 'stop' then stop_server when 'restart' then restart_server end end |
#start_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.
113 114 115 116 117 118 119 |
# File 'lib/cloud_crowd/command_line.rb', line 113 def start_node ENV['RACK_ENV'] = ['environment'] load_code port = [:port] || Node::DEFAULT_PORT puts "Starting CloudCrowd Node on port #{port}..." Node.new(port, [:daemonize]) end |
#start_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.
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/cloud_crowd/command_line.rb', line 76 def start_server port = [:port] || 9173 daemonize = [:daemonize] ? '-d' : '' log_path = CloudCrowd.log_path('server.log') pid_path = CloudCrowd.pid_path('server.pid') rackup_path = File.("#{@options[:config_path]}/config.ru") FileUtils.mkdir_p(CloudCrowd.log_path) if [:daemonize] && !File.exists?(CloudCrowd.log_path) puts "Starting CloudCrowd Central Server on port #{port}..." exec "thin -e #{@options[:environment]} -p #{port} #{daemonize} --tag cloud-crowd-server --log #{log_path} --pid #{pid_path} -R #{rackup_path} start" end |
#stop_node ⇒ Object
If the daemonized Node is running, stop it.
122 123 124 |
# File 'lib/cloud_crowd/command_line.rb', line 122 def stop_node Thin::Server.kill CloudCrowd.pid_path('node.pid') end |
#stop_server ⇒ Object
Stop the daemonized central server, if it exists.
88 89 90 |
# File 'lib/cloud_crowd/command_line.rb', line 88 def stop_server Thin::Server.kill(CloudCrowd.pid_path('server.pid'), 0) end |
#usage ⇒ Object
Print crowd usage.
153 154 155 |
# File 'lib/cloud_crowd/command_line.rb', line 153 def usage puts "\n#{@option_parser}\n" end |