mongrel_cluster 0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -1,6 +1,6 @@
1
1
  == Mongrel Cluster Plugin
2
2
 
3
- Tool to help start/stop/restart multiple mongrel servers to use behind a load balancer like Pound or Balance. This plugin adds an option to specify a number of Mongrel servers to launch, a range of ports, and a configuration file for the cluster. Use "-h" to see command syntax.
3
+ Tool to help start/stop/restart multiple mongrel servers to use behind a load balancer like Pound, Pen or Balance. This plugin adds an option to specify a number of Mongrel servers to launch, a range of ports, and a configuration file for the cluster. Use "-h" to see command syntax.
4
4
 
5
5
  Configure cluster and write configuration file:
6
6
  mongrel_rails cluster::configure
@@ -15,3 +15,26 @@ Stop cluster:
15
15
  mongrel_rails cluster::stop
16
16
 
17
17
 
18
+ Capistrano Recipe
19
+
20
+ Add to deploy.rb:
21
+ require 'mongrel_cluster/recipes'
22
+
23
+ Example usage:
24
+ cap -a configure_mongrel_cluster
25
+
26
+ Variables
27
+ mongrel_servers: Number of Mongrel servers to start.
28
+ mongrel_port: Starting port to bind to.
29
+ mongrel_address: Address to bind to.
30
+ mongrel_environment: Rails environment to run as.
31
+ mongrel_config: Path to config file.
32
+ use_sudo: Whether or not tasks that can use sudo, ought to use sudo. Capistrano defaults to true.
33
+
34
+ Tasks (performed on :app role)
35
+ configure_mongrel_cluster: Configure the cluster with variables. Uses sudo if use_sudo is true.
36
+ start_mongrel_cluster: Start Mongrel processes on the app server. Uses sudo if use_sudo is true.
37
+ stop_mongrel_cluster: Stop the Mongrel processes on the app server. Uses sudo if use_sudo is true.
38
+ restart_mongrel_cluster: Restart the Mongrel processes on the app server. Uses sudo if use_sudo is true.
39
+ restart: Calls restart_mongrel_cluster to allow Mongrel to be used with the standard Capistrano deploy task.
40
+ spinner: Calls start_mongrel_cluster to allow Mongrel to be used with the standard Capistrano cold_deploy task.
data/Rakefile CHANGED
@@ -15,16 +15,17 @@ setup_rdoc ['README', 'LICENSE', 'COPYING', 'lib/**/*.rb', 'doc/**/*.rdoc']
15
15
  desc "Does a full compile, test run"
16
16
  task :default => [:test, :package]
17
17
 
18
- version="0.1"
18
+ version="0.1.1"
19
19
  name="mongrel_cluster"
20
20
 
21
21
  setup_gem(name, version) do |spec|
22
- spec.summary = "The mongrel_cluster GemPlugin"
22
+ spec.summary = "Mongrel plugin that provides commands and Capistrano tasks for managing multiple Mongrel processes."
23
23
  spec.description = spec.summary
24
24
  spec.author="Bradley Taylor"
25
25
  spec.add_dependency('gem_plugin', '>= 0.2.1')
26
- spec.add_dependency('mongrel', '>= 0.3.12.2')
26
+ spec.add_dependency('mongrel', '>= 0.3.12.4')
27
27
  spec.files += Dir.glob("resources/**/*")
28
+ spec.has_rdoc = false
28
29
  end
29
30
 
30
31
 
@@ -8,7 +8,7 @@ module Cluster
8
8
  include Mongrel::Command::Base
9
9
 
10
10
  def configure
11
- options [['-C', '--config PATH', "Path to configuraion file", :@config_file, "config/mongrel_cluster.yml"]]
11
+ options [['-C', '--config PATH', "Path to configuration file", :@config_file, "config/mongrel_cluster.yml"]]
12
12
  end
13
13
 
14
14
  def validate
@@ -18,10 +18,7 @@ module Cluster
18
18
 
19
19
  def run
20
20
  @options = {
21
- "environment" => ENV['RAILS_ENV'] || "development",
22
21
  "port" => 3000,
23
- "address" => "0.0.0.0",
24
- "log_file" => "log/mongrel.log",
25
22
  "pid_file" => "log/mongrel.pid",
26
23
  "servers" => 2
27
24
  }
@@ -35,16 +32,16 @@ module Cluster
35
32
  argv = [ "mongrel_rails" ]
36
33
  argv << "start"
37
34
  argv << "-d"
38
- argv << "-e #{@options["environment"]}"
35
+ argv << "-e #{@options["environment"]}" if @options["environment"]
39
36
  argv << "-p #{port+i}"
40
- argv << "-a #{@options["address"]}"
41
- argv << "-l #{@options["log_file"]}"
42
- argv << "-P #{pid[0]}-#{i}.#{pid[1]}"
43
- argv << "-c #{@options["cwd"]}"
44
- argv << "-t #{@options["timeout"]}"
37
+ argv << "-a #{@options["address"]}" if @options["address"]
38
+ argv << "-l #{@options["log_file"]}" if @options["log_file"]
39
+ argv << "-P #{pid[0]}.#{port+i}.#{pid[1]}"
40
+ argv << "-c #{@options["cwd"]}" if @options["cwd"]
41
+ argv << "-t #{@options["timeout"]}" if @options["timeout"]
45
42
  argv << "-m #{@options["mime_map"]}" if @options["mime_map"]
46
- argv << "-r #{@options["docroot"]}"
47
- argv << "-n #{@options["num-procs"]}"
43
+ argv << "-r #{@options["docroot"]}" if @options["docroot"]
44
+ argv << "-n #{@options["num_procs"]}" if @options["num_procs"]
48
45
  argv << "-B" if @options["debug"]
49
46
  argv << "-S #{@options["config_script"]}" if @options["config_script"]
50
47
  cmd = argv.join " "
@@ -74,18 +71,22 @@ module Cluster
74
71
  @options = {
75
72
  "environment" => ENV['RAILS_ENV'] || "development",
76
73
  "port" => 3000,
77
- "address" => "0.0.0.0",
78
- "log_file" => "log/mongrel.log",
79
74
  "pid_file" => "log/mongrel.pid",
80
75
  "servers" => 2
81
76
  }
82
77
 
83
78
  @conf_options = YAML.load_file(@config_file)
84
79
  @options.merge! @conf_options if @conf_options
80
+ port = @options["port"].to_i - 1
85
81
  pid = @options["pid_file"].split(".")
86
82
  puts "Stopping #{@options["servers"]} Mongrel servers..."
87
83
  1.upto(@options["servers"].to_i) do |i|
88
- cmd = "mongrel_rails stop -P #{pid[0]}-#{i}.#{pid[1]} -c #{@options["cwd"]} #{"-f" if @force }"
84
+ argv = [ "mongrel_rails" ]
85
+ argv << "stop"
86
+ argv << "-P #{pid[0]}.#{port+i}.#{pid[1]}"
87
+ argv << "-c #{@options["cwd"]}" if @options["cwd"]
88
+ argv << "-f" if @force
89
+ cmd = argv.join " "
89
90
  puts cmd
90
91
  status = `#{cmd}`
91
92
  puts status
@@ -110,20 +111,23 @@ module Cluster
110
111
 
111
112
  def run
112
113
  @options = {
113
- "environment" => ENV['RAILS_ENV'] || "development",
114
114
  "port" => 3000,
115
- "address" => "0.0.0.0",
116
- "log_file" => "log/mongrel.log",
117
115
  "pid_file" => "log/mongrel.pid",
118
116
  "servers" => 2
119
117
  }
120
118
 
121
119
  @conf_options = YAML.load_file(@config_file)
122
120
  @options.merge! @conf_options if @conf_options
121
+ port = @options["port"].to_i - 1
123
122
  pid = @options["pid_file"].split(".")
124
123
  puts "Restarting #{@options["servers"]} Mongrel servers..."
125
124
  1.upto(@options["servers"].to_i) do |i|
126
- cmd = "mongrel_rails restart -P #{pid[0]}-#{i}.#{pid[1]} -c #{@options["cwd"]} #{"-s" if @soft }"
125
+ argv = [ "mongrel_rails" ]
126
+ argv << "restart"
127
+ argv << "-P #{pid[0]}.#{port+i}.#{pid[1]}"
128
+ argv << "-c #{@options["cwd"]}" if @options["cwd"]
129
+ argv << "-s" if @soft
130
+ cmd = argv.join " "
127
131
  puts cmd
128
132
  status = `#{cmd}`
129
133
  puts status
@@ -136,17 +140,17 @@ module Cluster
136
140
 
137
141
  def configure
138
142
  options [
139
- ["-e", "--environment ENV", "Rails environment to run as", :@environment, ENV['RAILS_ENV'] || "development"],
143
+ ["-e", "--environment ENV", "Rails environment to run as", :@environment, nil],
140
144
  ['-p', '--port PORT', "Starting port to bind to", :@port, 3000],
141
- ['-a', '--address ADDR', "Address to bind to", :@address, "0.0.0.0"],
142
- ['-l', '--log FILE', "Where to write log messages", :@log_file, "log/mongrel.log"],
145
+ ['-a', '--address ADDR', "Address to bind to", :@address, nil],
146
+ ['-l', '--log FILE', "Where to write log messages", :@log_file, nil],
143
147
  ['-P', '--pid FILE', "Where to write the PID", :@pid_file, "log/mongrel.pid"],
144
- ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, Dir.pwd],
145
- ['-t', '--timeout SECONDS', "Timeout all requests after SECONDS time", :@timeout, 120],
148
+ ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, nil],
149
+ ['-t', '--timeout SECONDS', "Timeout all requests after SECONDS time", :@timeout, nil],
146
150
  ['-m', '--mime PATH', "A YAML file that lists additional MIME types", :@mime_map, nil],
147
- ['-r', '--root PATH', "Set the document root (default 'public')", :@docroot, "public"],
148
- ['-n', '--num-procs INT', "Number of processor threads to use", :@num_procs, 1024],
149
- ['-B', '--debug', "Enable debugging mode", :@debug, false],
151
+ ['-r', '--root PATH', "Set the document root (default 'public')", :@docroot, nil],
152
+ ['-n', '--num-procs INT', "Number of processor threads to use", :@num_procs, nil],
153
+ ['-B', '--debug', "Enable debugging mode", :@debug, nil],
150
154
  ['-S', '--script PATH', "Load the given file as an extra config script.", :@config_script, nil],
151
155
  ['-N', '--num-servers INT', "Number of Mongrel servers", :@servers, 2],
152
156
  ['-C', '--config PATH', "Path to config file", :@config_file, "config/mongrel_cluster.yml"]
@@ -155,43 +159,34 @@ module Cluster
155
159
 
156
160
  def validate
157
161
  @servers = @servers.to_i
158
- @port = @port.to_i
159
- @timeout = @timeout.to_i
160
162
 
161
- @cwd = File.expand_path(@cwd)
162
- valid_dir? @cwd, "Invalid path to change to during daemon mode: #{@cwd}"
163
163
  valid?(@servers > 0, "Must give a valid number of servers")
164
- valid?(@port > 0, "Must give a valid starting port")
165
- valid?(@timeout > 0, "Must give a valid timeout for requests")
166
-
167
- valid_dir? File.dirname(@log_file), "Path to log file not valid: #{@log_file}"
168
- valid_dir? File.dirname(@pid_file), "Path to pid file not valid: #{@pid_file}"
169
164
  valid_dir? File.dirname(@config_file), "Path to config file not valid: #{@config_file}"
170
165
 
171
- valid_dir? File.dirname(@docroot), "Path to docroot not valid: #{@docroot}"
172
- valid_exists? @mime_map, "MIME mapping file does not exist: #{@mime_map}" if @mime_map
173
-
174
166
  return @valid
175
167
  end
176
168
 
177
169
  def run
178
170
  @options = {
179
- "environment" => @environment,
180
171
  "port" => @port,
181
- "address" => @address,
182
- "log_file" => @log_file,
183
- "pid_file" => @pid_file,
184
172
  "servers" => @servers,
185
- "cwd" => @cwd,
186
- "timeout" => @timeout,
187
- "mime_map" => @mime_map,
188
- "docroot" => @docroot,
189
- "debug" => @debug,
190
- "config_script" => @config_script,
191
- "num-procs" => @num_procs
173
+ "pid_file" => @pid_file
192
174
  }
175
+
176
+ @options["log_file"] = @log_file if @log_file
177
+ @options["debug"] = @debug if @debug
178
+ @options["num_procs"] = @num_procs if @num_procs
179
+ @options["docroot"] = @docroot if @docroots
180
+ @options["address"] = @address if @address
181
+ @options["timeout"] = @timeout if @timeout
182
+ @options["environment"] = @environment if @environment
183
+ @options["mime_map"] = @mime_map if @mime_map
184
+ @options["config_script"] = @config_script if @config_script
185
+ @options["cwd"] = @cwd if @cwd
186
+
193
187
  puts "Writing configuration file to #{@config_file}."
194
188
  File.open(@config_file,"w") {|f| f.write(@options.to_yaml)}
195
189
  end
196
190
  end
197
- end
191
+ end
192
+
@@ -0,0 +1,55 @@
1
+ Capistrano.configuration(:must_exist).load do
2
+ set :mongrel_servers, "2"
3
+ set :mongrel_port, "8000"
4
+ set :mongrel_address, "127.0.0.1"
5
+ set :mongrel_environment, "production"
6
+ set(:mongrel_config) { "#{deploy_to}/config/mongrel_cluster.yml" }
7
+
8
+ desc <<-DESC
9
+ Configure Mongrel processes on the app server. This uses the :use_sudo
10
+ variable to determine whether to use sudo or not.
11
+ DESC
12
+ task :configure_mongrel_cluster, :roles => :app do
13
+ send(run_method, "if [ ! -d #{File.dirname(mongrel_config)} ]; then mkdir -p #{File.dirname(mongrel_config)}; fi")
14
+ send(run_method, "mongrel_rails cluster::configure -N #{mongrel_servers} -p #{mongrel_port} -e #{mongrel_environment} -a #{mongrel_address} -c #{current_path} -C #{mongrel_config}")
15
+ end
16
+
17
+ desc <<-DESC
18
+ Start Mongrel processes on the app server. This uses the :use_sudo
19
+ variable to determine whether to use sudo or not.
20
+ DESC
21
+ task :start_mongrel_cluster , :roles => :app do
22
+ send(run_method, "mongrel_rails cluster::start -C #{mongrel_config}")
23
+ end
24
+
25
+ desc <<-DESC
26
+ Restart the Mongrel processes on the app server. This uses the :use_sudo
27
+ variable to determine whether to use sudo or not.
28
+ DESC
29
+ task :restart_mongrel_cluster , :roles => :app do
30
+ send(run_method, "mongrel_rails cluster::restart -C #{mongrel_config}")
31
+ end
32
+
33
+ desc <<-DESC
34
+ Stop the Mongrel processes on the app server. This uses the :use_sudo
35
+ variable to determine whether to use sudo or not.
36
+ DESC
37
+ task :stop_mongrel_cluster , :roles => :app do
38
+ send(run_method, "mongrel_rails cluster::stop -C #{mongrel_config}")
39
+ end
40
+
41
+ desc <<-DESC
42
+ Restart the Mongrel processes on the app server by calling restart_mongrel_cluster.
43
+ DESC
44
+ task :restart, :roles => :app do
45
+ restart_mongrel_cluster
46
+ end
47
+
48
+ desc <<-DESC
49
+ Start the Mongrel processes on the app server by calling start_mongrel_cluster.
50
+ DESC
51
+ task :spinner, :roles => :app do
52
+ start_mongrel_cluster
53
+ end
54
+
55
+ end
metadata CHANGED
@@ -3,19 +3,19 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: mongrel_cluster
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.1"
7
- date: 2006-04-24 00:00:00 -04:00
8
- summary: The mongrel_cluster GemPlugin
6
+ version: 0.1.1
7
+ date: 2006-05-01 00:00:00 -04:00
8
+ summary: Mongrel plugin that provides commands and Capistrano tasks for managing multiple Mongrel processes.
9
9
  require_paths:
10
10
  - lib
11
11
  email:
12
12
  homepage:
13
13
  rubyforge_project:
14
- description: The mongrel_cluster GemPlugin
14
+ description: Mongrel plugin that provides commands and Capistrano tasks for managing multiple Mongrel processes.
15
15
  autorequire:
16
16
  default_executable:
17
17
  bindir: bin
18
- has_rdoc: true
18
+ has_rdoc: false
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
21
  - - ">"
@@ -34,6 +34,7 @@ files:
34
34
  - Rakefile
35
35
  - lib/mongrel_cluster
36
36
  - lib/mongrel_cluster/init.rb
37
+ - lib/mongrel_cluster/recipes.rb
37
38
  - tools/rakehelp.rb
38
39
  - resources/defaults.yaml
39
40
  test_files: []
@@ -65,5 +66,5 @@ dependencies:
65
66
  requirements:
66
67
  - - ">="
67
68
  - !ruby/object:Gem::Version
68
- version: 0.3.12.2
69
+ version: 0.3.12.4
69
70
  version: