Class: JCluster::Configure

Inherits:
Object
  • Object
show all
Includes:
Mongrel::Command::Base
Defined in:
lib/mongrel_jcluster/init.rb

Instance Method Summary collapse

Instance Method Details

#configureObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/mongrel_jcluster/init.rb', line 131

def configure 
  options [
    ["-e", "--environment ENV", "Rails environment to run as", :@environment, nil],
    ['-p', '--port PORT', "Starting port to bind to", :@port, 3000],
    ['-a', '--address ADDR', "Address to bind to", :@address, nil],
    ['-l', '--log FILE', "Where to write log messages", :@log_file, nil],
    ['-P', '--pid FILE', "Where to write the PID", :@pid_file, "log/mongrel.pid"],
    ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, nil],
    ['-t', '--timeout SECONDS', "Timeout all requests after SECONDS time", :@timeout, nil],
    ['-m', '--mime PATH', "A YAML file that lists additional MIME types", :@mime_map, nil],
    ['-r', '--root PATH', "Set the document root (default 'public')", :@docroot, nil],
    ['-n', '--num-procs INT', "Number of processor threads to use", :@num_procs, nil],
    ['-B', '--debug', "Enable debugging mode", :@debug, nil],
    ['-S', '--script PATH', "Load the given file as an extra config script.", :@config_script, nil],
    ['-N', '--num-servers INT', "Number of Mongrel servers", :@servers, 2],
    ['-C', '--config PATH', "Path to cluster configuration file", :@config_file, "config/mongrel_jcluster.yml"],
    ['-R', '--jport PORT', "Local port where JRuby server should run", :@jport, 19222],
    ['-K', '--jkey KEY', "Key to use for connecting to JRuby server", :@jkey, nil],
    ['', '--user USER', "User to run as", :@user, nil],
    ['', '--group GROUP', "Group to run as", :@group, nil],
    ['', '--prefix PREFIX', "Rails prefix to use", :@prefix, nil]
  ]
end

#runObject



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/mongrel_jcluster/init.rb', line 164

def run
  @options = { 
    "port" => @port,
    "servers" => @servers,
    "pid_file" => @pid_file
  }
  
  @options["log_file"] = @log_file if @log_file
  @options["debug"] = @debug if @debug
  @options["num_procs"] = @num_procs if @num_procs
  @options["docroot"] = @docroot if @docroots
  @options["address"] = @address if @address
  @options["timeout"] = @timeout if @timeout
  @options["environment"] = @environment if @environment
  @options["mime_map"] = @mime_map if @mime_map
  @options["config_script"] = @config_script if @config_script
  @options["cwd"] = @cwd if @cwd
  @options["user"] = @user if @user
  @options["group"] = @group if @group
  @options["prefix"] = @prefix if @prefix
  @options["jkey"] = @jkey if @jkey
  @options["jport"] = @jport if @jport
  
  puts "Writing configuration file to #{@config_file}."
  File.open(@config_file,"w") {|f| f.write(@options.to_yaml)}
end

#validateObject



155
156
157
158
159
160
161
162
# File 'lib/mongrel_jcluster/init.rb', line 155

def validate
  @servers = @servers.to_i
  
  valid?(@servers > 0, "Must give a valid number of servers")
  valid_dir? File.dirname(@config_file), "Path to config file not valid: #{@config_file}"
  
  return @valid
end