Module: JCluster::ExecBase

Includes:
Mongrel::Command::Base
Included in:
Restart, Start, Stop
Defined in:
lib/mongrel_jcluster/init.rb

Instance Method Summary collapse

Instance Method Details

#read_optionsObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mongrel_jcluster/init.rb', line 15

def read_options
  @options = { 
    "environment" => ENV['RAILS_ENV'] || "development",
    "port" => 3000,
    "pid_file" => "log/mongrel.pid",
    "servers" => 2, 
    "jport" => 19222,
    "jkey" => "aggfeeeeeeeeeeeeeergergwer35t45t327283428738fewgfygdsf8yesr834"
  }
  conf = YAML.load_file(@config_file)
  @options.merge! conf if conf
end

#startObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/mongrel_jcluster/init.rb', line 28

def start
  read_options
  port = @options["port"].to_i - 1
  pid = @options["pid_file"].split(".")
  puts "Starting JRuby server..."
  system("sh -c 'jrubysrv -p #{@options["jport"]} -k #{@options["jkey"]} </dev/null >jrubyserver.stdout.log 2>jrubyserver.stderr.log &'")
  sleep 1
  puts "Starting #{@options["servers"]} Mongrel servers..."
  1.upto(@options["servers"].to_i) do |i|
    argv = [ "mongrel_rails" ]
    argv << "start"
    argv << "-e #{@options["environment"]}" if @options["environment"]
    argv << "-p #{port+i}"
    argv << "-a #{@options["address"]}"  if @options["address"]
    argv << "-l #{@options["log_file"]}" if @options["log_file"]
    argv << "-P #{pid[0]}.#{port+i}.#{pid[1]}"
    argv << "-c #{@options["cwd"]}" if @options["cwd"]
    argv << "-t #{@options["timeout"]}" if @options["timeout"]
    argv << "-m #{@options["mime_map"]}" if @options["mime_map"]
    argv << "-r #{@options["docroot"]}" if @options["docroot"]
    argv << "-n #{@options["num_procs"]}" if @options["num_procs"]
    argv << "-B" if @options["debug"]
    argv << "-S #{@options["config_script"]}" if @options["config_script"]
    argv << "--user #{@options["user"]}" if @options["user"]
    argv << "--group #{@options["group"]}" if @options["group"]
    argv << "--prefix #{@options["prefix"]}" if @options["prefix"]
    cmd = argv.join " "

    puts cmd if @verbose
    output = `sh -c 'jrubycli -p #{@options["jport"]} -k #{@options["jkey"]} -S #{cmd}'`
    unless $?.success?
      puts cmd unless @verbose
      puts output
    end
  end
end

#stopObject



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/mongrel_jcluster/init.rb', line 65

def stop
  read_options
  port = @options["port"].to_i - 1
  pid = @options["pid_file"].split(".")
  puts "Stopping #{@options["servers"]} Mongrel servers..."
  output = `sh -c 'jrubycli -p #{@options["jport"]} -k #{@options["jkey"]} -t'`
  unless $?.success?
    puts cmd unless @verbose
    puts output
  end
end

#validateObject



10
11
12
13
# File 'lib/mongrel_jcluster/init.rb', line 10

def validate
  valid_exists?(@config_file, "Configuration file does not exist. Run mongrel_rails cluster::configure.")
  return @valid
end