about summary refs log tree commit homepage
path: root/projects
diff options
context:
space:
mode:
authorevanweaver <evanweaver@19e92222-5c0b-0410-8929-a290d50e31e9>2007-10-11 07:30:46 +0000
committerevanweaver <evanweaver@19e92222-5c0b-0410-8929-a290d50e31e9>2007-10-11 07:30:46 +0000
commit514135c040197faf83627b90d74dcfabe415b3cb (patch)
tree35aa90088d2b85c3a41eb8d12666b5ff2b789cef /projects
parent370a88b2e428a41008d2f9e4e2c2a4ed215ab873 (diff)
downloadunicorn-514135c040197faf83627b90d74dcfabe415b3cb.tar.gz
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@641 19e92222-5c0b-0410-8929-a290d50e31e9
Diffstat (limited to 'projects')
-rw-r--r--projects/mongrel_cluster/README64
-rw-r--r--projects/mongrel_cluster/lib/mongrel_cluster/recipes_2.rb117
2 files changed, 155 insertions, 26 deletions
diff --git a/projects/mongrel_cluster/README b/projects/mongrel_cluster/README
index ace0e31..d82c290 100644
--- a/projects/mongrel_cluster/README
+++ b/projects/mongrel_cluster/README
@@ -3,45 +3,57 @@
 Tool to help start/stop/restart multiple mongrel servers to use behind a load balancer like Apache 2.2 (mod_proxy_balancer), Lighttpd, 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.
 
 Configure cluster and write configuration file:
-mongrel_rails cluster::configure  
+  mongrel_rails cluster::configure  
 
 Start cluster:
-mongrel_rails cluster::start
+  mongrel_rails cluster::start
 
 Restart cluster:
-mongrel_rails cluster::restart
+  mongrel_rails cluster::restart
 
 Stop cluster:
-mongrel_rails cluster::stop
+  mongrel_rails cluster::stop
 
-Capistrano Recipe
+== Capistrano 1.0 Recipes
 
 Add to config/deploy.rb:
-require 'mongrel_cluster/recipes'
+  require 'mongrel_cluster/recipes'
 
-Example usage:
-cap -a configure_mongrel_cluster
-
-Variables
-mongrel_servers: Number of Mongrel servers to start.
-mongrel_port: Starting port to bind to.
-mongrel_address: Address to bind to.
-mongrel_environment: Rails environment to run as.
-mongrel_conf: Path to conf file. Defaults to /etc/mongrel_cluster/app_name.conf
-mongrel_user: User to run mongrels in cluster as. Unset by default
-mongrel_group: Group to run mongrels in cluster as. Unset by default.
+Variables:
+  mongrel_servers: Number of Mongrel servers to start.
+  mongrel_port: Starting port to bind to.
+  mongrel_address: Address to bind to.
+  mongrel_environment: Rails environment to run as.
+  mongrel_conf: Path to conf file. Defaults to /etc/mongrel_cluster/app_name.conf
+  mongrel_user: User to run mongrels in cluster as. Unset by default
+  mongrel_group: Group to run mongrels in cluster as. Unset by default.
 
 Tasks (performed on :app role)
-configure_mongrel_cluster: Configure the cluster with variables.
-start_mongrel_cluster: Start Mongrel processes on the app server.
-stop_mongrel_cluster: Stop the Mongrel processes on the app server.
-restart_mongrel_cluster: Restart the Mongrel processes on the app server by starting and stopping mongrel_cluster.
-restart: Calls restart_mongrel_cluster to allow Mongrel to be used with the standard Capistrano deploy task.
-spinner: Calls start_mongrel_cluster to allow Mongrel to be used with the standard Capistrano cold_deploy task.
-
-Supporting starting clusters on boot.
+  configure_mongrel_cluster: Configure the cluster with variables.
+  start_mongrel_cluster: Start Mongrel processes on the app server.
+  stop_mongrel_cluster: Stop the Mongrel processes on the app server.
+  restart_mongrel_cluster: Restart the Mongrel processes on the app server by starting and stopping mongrel_cluster.
+  restart: Calls restart_mongrel_cluster to allow Mongrel to be used with the standard Capistrano deploy task.
+  spinner: Calls start_mongrel_cluster to allow Mongrel to be used with the standard Capistrano cold_deploy task.
+
+== Capistrano 2.0 Recipes
+
+Add to config/deploy.rb:
+  require 'mongrel_cluster/recipes_2'
+
+Capistrano 2.0 uses namespaced tasks. The new task names are:
+  mongrel:cluster:configure Configure the cluster with variables.
+  mongrel:cluster:start: Start Mongrel processes on the app server.
+  mongrel:cluster:stop: Stop the Mongrel processes on the app server.
+  mongrel:cluster:restart: Restart the Mongrel processes on the app server by starting and stopping mongrel_cluster.
+  deploy:restart: Calls mongrel:cluster:restart to allow Mongrel to be used with the standard Capistrano deploy task.
+  deploy:start: Calls mongrel:cluster:start to allow Mongrel to be used with the standard Capistrano deploy task.
+  deploy:stop: Calls mongrel:cluster:stop to allow Mongrel to be used with the standard Capistrano deploy task.
+
+== Starting clusters at boot
+
 1. Create mongrel_cluster conf directory (/etc/mongrel_cluster).
-2. Assign ownership to your capistrano user.
+2. Assign ownership to your Capistrano user.
 3. Copy the init.d script from this gem's resouces directory /etc/init.d.
 4. chmod +x /etc/init.d/mongrel_cluster
 5. Add to init.d startup. On RHEL/CentOS use: /sbin/chkconfig --level 345 mongrel_cluster on
diff --git a/projects/mongrel_cluster/lib/mongrel_cluster/recipes_2.rb b/projects/mongrel_cluster/lib/mongrel_cluster/recipes_2.rb
new file mode 100644
index 0000000..a82c424
--- /dev/null
+++ b/projects/mongrel_cluster/lib/mongrel_cluster/recipes_2.rb
@@ -0,0 +1,117 @@
+Capistrano::Configuration.instance.load do
+  set :mongrel_servers, 2
+  set :mongrel_port, 8000
+  set :mongrel_address, "127.0.0.1"
+  set :mongrel_environment, "production"
+  set :mongrel_conf, nil
+  set :mongrel_user, nil
+  set :mongrel_group, nil
+  set :mongrel_prefix, nil
+  set :mongrel_rails, 'mongrel_rails'
+  set :mongrel_clean, false
+  set :mongrel_pid_file, nil
+  set :mongrel_log_file, nil
+  set :mongrel_config_script, nil
+
+  namespace :mongrel do
+    namespace :cluster do
+      desc <<-DESC
+      Configure Mongrel processes on the app server. This uses the :use_sudo
+      variable to determine whether to use sudo or not. By default, :use_sudo is
+      set to true.
+      DESC
+      task :configure, :roles => :app do
+        set_conf
+        
+        argv = []
+        argv << "#{mongrel_rails} cluster::configure"
+        argv << "-N #{mongrel_servers.to_s}"
+        argv << "-p #{mongrel_port.to_s}"
+        argv << "-e #{mongrel_environment}"
+        argv << "-a #{mongrel_address}"
+        argv << "-c #{current_path}"
+        argv << "-C #{mongrel_conf}"
+        argv << "-P #{mongrel_pid_file}" if mongrel_pid_file
+        argv << "-l #{mongrel_log_file}" if mongrel_log_file
+        argv << "--user #{mongrel_user}" if mongrel_user
+        argv << "--group #{mongrel_group}" if mongrel_group
+        argv << "--prefix #{mongrel_prefix}" if mongrel_prefix
+        argv << "-S #{mongrel_config_script}" if mongrel_config_script
+        cmd = argv.join " "
+        send(run_method, cmd)
+      end
+  
+      desc <<-DESC
+      Start Mongrel processes on the app server.  This uses the :use_sudo variable to determine whether to use sudo or not. By default, :use_sudo is
+      set to true.
+      DESC
+      task :start , :roles => :app do
+        set_conf
+        cmd = "#{mongrel_rails} cluster::start -C #{mongrel_conf}"
+        cmd += " --clean" if mongrel_clean    
+        send(run_method, cmd)
+      end
+  
+      desc <<-DESC
+      Restart the Mongrel processes on the app server by starting and stopping the cluster. This uses the :use_sudo
+      variable to determine whether to use sudo or not. By default, :use_sudo is set to true.
+      DESC
+      task :restart , :roles => :app do
+        set_conf
+        cmd = "#{mongrel_rails} cluster::restart -C #{mongrel_conf}"
+        cmd += " --clean" if mongrel_clean    
+        send(run_method, cmd)
+      end
+  
+      desc <<-DESC
+      Stop the Mongrel processes on the app server.  This uses the :use_sudo
+      variable to determine whether to use sudo or not. By default, :use_sudo is
+      set to true.
+      DESC
+      task :stop , :roles => :app do
+        set_conf
+        cmd = "#{mongrel_rails} cluster::stop -C #{mongrel_conf}"
+        cmd += " --clean" if mongrel_clean    
+        send(run_method, cmd)
+      end
+
+      desc <<-DESC
+      Check the status of the Mongrel processes on the app server.  This uses the :use_sudo
+      variable to determine whether to use sudo or not. By default, :use_sudo is
+      set to true.
+      DESC
+      task :status , :roles => :app do
+        set_conf
+        send(run_method, "#{mongrel_rails} cluster::status -C #{mongrel_conf}")
+      end
+  
+      def set_conf
+        set :mongrel_conf, "/etc/mongrel_cluster/#{application}.yml" unless mongrel_conf
+      end
+    end
+  end
+  
+  namespace :deploy do
+    desc <<-DESC
+    Restart the Mongrel processes on the app server by calling mongrel:cluster:restart.
+    DESC
+    task :restart, :roles => :app do
+      mongrel.cluster.restart
+    end
+  
+    desc <<-DESC
+    Start the Mongrel processes on the app server by calling mongrel:cluster:start.
+    DESC
+    task :start, :roles => :app do
+      mongrel.cluster.start
+    end
+    
+    desc <<-DESC
+    Stop the Mongrel processes on the app server by calling mongrel:cluster:stop.
+    DESC
+    task :stop, :roles => :app do
+      mongrel.cluster.stop
+    end
+  end
+
+end