Permalink
Browse files

fixing website gen, upload plugin, mongrel cluster fix

  • Loading branch information...
1 parent d39472d commit 2dee1a07d0bdfa7017b744f7ac0168af7de45703 @gabriel committed Feb 22, 2008
View
@@ -1,3 +1,8 @@
+== 0.1.9 2008-02-23
+
+* Adding config_script to mongrel_cluster recipe
+* Creating upload plugin that streams data
+
== 0.1.8 2008-02-22
* Fixing up documentation
View
@@ -17,6 +17,7 @@ lib/capitate/plugins/package.rb
lib/capitate/plugins/profiles.rb
lib/capitate/plugins/script.rb
lib/capitate/plugins/templates.rb
+lib/capitate/plugins/upload.rb
lib/capitate/plugins/wget.rb
lib/capitate/plugins/yum.rb
lib/capitate/recipes.rb
@@ -77,6 +78,7 @@ tasks/deployment.rake
tasks/environment.rake
tasks/website.rake
test/test_helper.rb
+test/test_plugin_upload.rb
test/test_recipes.rb
test/test_templates.rb
website/index.html
View
@@ -0,0 +1,12 @@
+=== Nginx + mongrel
+http://brainspl.at/articles/2006/08/23/nginx-my-new-favorite-front-end-for-mongrel-cluster
+http://brainspl.at/articles/2007/01/03/new-nginx-conf-with-optimizations
+http://topfunky.net/svn/shovel/nginx
+
+=== Nginx + memcached:
+http://www.igvita.com/2008/02/11/nginx-and-memcached-a-400-boost/
+http://blog.kovyrin.net/2007/08/05/using-nginx-ssi-and-memcache-to-make-your-web-applications-faster/
+
+=== Nginx
+http://robsanheim.com/2008/02/07/beware-the-default-nginx-config-old-ie6-hates-gzip/
+http://brainspl.at/articles/2007/11/09/a-fair-proxy-balancer-for-nginx-and-mongrel
View
@@ -22,6 +22,8 @@ module Plugins # :nodoc:
require 'capitate/plugins/wget'
require 'capitate/plugins/yum'
+require 'capitate/plugins/upload'
+
require "capitate/cap_ext/connections"
require "capitate/cap_ext/extension_proxy"
require "capitate/cap_ext/variables"
@@ -1,3 +1,10 @@
+#--
+# =============================================================================
+# Copyright (c) 2007, Gabriel Handford (gabrielh@gmail.com)
+# All rights reserved.
+# =============================================================================
+#++
+
require 'erb'
require 'yaml'
@@ -0,0 +1,58 @@
+module Capitate::Plugins::Upload
+
+ # Upload file with source path.
+ # Data is streamed.
+ #
+ # ==== Options
+ # +src_path+:: Source path
+ # +dest_path:: Remote destination path
+ # +options+:: Options (see capistrano 'put')
+ #
+ def file(src_path, dest_path, options = {})
+ data = FileData.new(src_path)
+ put(data, dest_path, options)
+ end
+
+ # Stream data with Net::SFTP by looking like an Array
+ class FileData
+
+ def initialize(path)
+ @path = path
+ @next_start = 0
+ end
+
+ def [](start, length)
+
+ if start != @next_start
+ raise <<-EOS
+
+ Can only access data sequentially; so we can stream it (The next start position should have been: #{@next_start})
+
+ EOS
+ end
+
+ data = file.read(length)
+
+ @next_start = start + length
+ close if @next_start >= self.length
+
+ data
+ end
+
+ def length
+ @file_size ||= File.size(@path)
+ end
+
+ def file
+ @file ||= File.open(@path, "r")
+ end
+
+ def close
+ @file.close if @file
+ end
+
+ end
+
+end
+
+Capistrano.plugin :upload, Capitate::Plugins::Upload
View
@@ -1,44 +1,82 @@
-# TODO: Document this class
+# Task node in the capistrano namespace, task hierarchy.
+#
class Capitate::TaskNode
include Capitate::Plugins::Base
attr_reader :name, :nodes, :tasks, :parent
-
+
+ # Create task node with name and parent
+ # For root not use name = "top"
+ #
+ # ==== Options
+ # +name+:: Node name (namespace name)
+ # +parent+:: Parent node
+ #
def initialize(name, parent = nil)
@name = name
@parent = parent
@nodes = []
@tasks = []
end
+ # Add "child" node.
+ #
+ # ==== Options
+ # +task_node+:: Node
+ #
def add_node(task_node)
@nodes << task_node
end
+ # Find node with name (namespace).
+ #
+ # ==== Options
+ # +name+:: Name to look for
+ #
def find(name)
@nodes.each do |node|
return node if node.name == name
end
nil
end
+ # Add task to this node.
+ #
+ # ==== Options
+ # +task+:: Add task associated with this node (namespace).
+ #
def add_task(task)
@tasks << task
end
+ # Get "child" nodes (sorted).
+ #
def sorted_nodes
nodes.sort_by(&:name)
end
- # Depth first iteration
+ # Iterate over ALL "child" nodes, depth first.
+ # Yields |node, level|.
+ #
+ # ==== Options
+ # +level+:: Current level
+ #
def each_node(level = 0, &block)
sorted_nodes.each do |node|
yield(node, level)
node.each_node(level + 1, &block)
end
end
+ # Get the full name, using delimeter
+ #
+ # ==== Options
+ # +delimeter+:: Delimeter
+ #
+ # ==== Examples
+ # node.full_name(":") => "mysql:centos" # On node mysql centos node (top -> mysql -> centos)
+ #
def full_name(delimeter = "-")
if parent
parent_name = parent.full_name
@@ -50,6 +88,13 @@ def full_name(delimeter = "-")
end
# Write doc for node (recursively)
+ #
+ # ==== Options
+ # +dir+:: Dir to write to
+ # +file_name+:: File name to write to, defaults to full name
+ # +title+:: Title and h1 for page, defaults to name
+ # +options+:: Options
+ #
def write_doc(dir, file_name = nil, title = nil, options = {}, &block)
file_name ||= full_name
@@ -115,6 +160,8 @@ def write_doc(dir, file_name = nil, title = nil, options = {}, &block)
end
end
+ # Node to string.
+ #
def to_s(level = 0)
spaces = " "
indent = (0...level).collect { spaces }.join("")
@@ -133,9 +180,20 @@ def to_s(level = 0)
end
s
end
-
+
+ # Class methods
class << self
+ # Create nodes and and task to node.
+ #
+ # If task is "mysql:centos:install", the nodes will look like:
+ #
+ # (top node) -> (mysql node) -> (centos node; w/ tasks: install)
+ #
+ # ==== Options
+ # +top_node+:: Node to start at
+ # +task+:: Task to add
+ #
def populate_with_task(top_node, task)
node_names = task.namespace.fully_qualified_name.split(":")
View
@@ -2,7 +2,7 @@ module Capitate #:nodoc:
module VERSION #:nodoc:
MAJOR = 0
MINOR = 1
- TINY = 8
+ TINY = 9
STRING = [MAJOR, MINOR, TINY].join('.')
end
View
@@ -4,8 +4,6 @@
task :recipes do
top_node = capitate.task_tree
- puts "Tree:\n#{}"
-
dir = "docs/recipes"
FileUtils.rm_rf(dir)
FileUtils.mkdir_p(dir)
@@ -13,6 +13,10 @@
set :mongrel_port, 9000
+ mongrel_config_script: Config script to load with mongrel.
+
+ set :mongrel_config_script, "config/mongrel_handler.rb"
+
DESC
task :setup_monit do
@@ -24,13 +28,30 @@
# Settings
fetch(:mongrel_size)
fetch(:mongrel_port)
+ fetch_or_default(:mongrel_config_script, nil)
processes = []
ports = (0...mongrel_size).collect { |i| mongrel_port + i }
ports.each do |port|
pid_path = "#{shared_path}/pids/mongrel.#{port}.pid"
- start_options = "-d -e production -a 127.0.0.1 -c #{current_path} --user #{user} --group #{user} -p #{port} -P #{pid_path} -l log/mongrel.#{port}.log"
+
+ default_options = [
+ [ "-d" ],
+ [ "-e", "production" ],
+ [ "-a", "127.0.0.1" ],
+ [ "-c", current_path ],
+ [ "--user", user ],
+ [ "--group", user ],
+ [ "-p", port ],
+ [ "-P", pid_path ],
+ [ "-l", "log/mongrel.#{port}.log" ]
+ ]
+
+ default_options << [ "-S", mongrel_config_script ] if mongrel_config_script
+
+ start_options = default_options.collect { |a| a.join(" ") }.join(" ")
+ #start_options = "-d -e production -a 127.0.0.1 -c #{current_path} --user #{user} --group #{user} -p #{port} -P #{pid_path} -l log/mongrel.#{port}.log"
stop_options = "-p #{port} -P #{pid_path}"
processes << { :port => port, :start_options => start_options, :stop_options => stop_options, :name => "/usr/bin/mongrel_rails", :pid_path => pid_path }
@@ -8,3 +8,4 @@ pid_file: <%= pid_path %>/mongrel.pid
servers: <%= mongrel_size %>
user: <%= user %>
group: <%= user %>
+config_script: <%= mongrel_config_script %>
@@ -4,10 +4,18 @@
# See vhost conf for site specific stuff.
#
# ==== References:
+# http://brainspl.at/articles/2006/08/23/nginx-my-new-favorite-front-end-for-mongrel-cluster
# http://brainspl.at/articles/2007/01/03/new-nginx-conf-with-optimizations
# http://topfunky.net/svn/shovel/nginx
# http://robsanheim.com/2008/02/07/beware-the-default-nginx-config-old-ie6-hates-gzip/
#
+# Nginx + memcached:
+# http://www.igvita.com/2008/02/11/nginx-and-memcached-a-400-boost/
+# http://blog.kovyrin.net/2007/08/05/using-nginx-ssi-and-memcache-to-make-your-web-applications-faster/
+#
+# Fair balancing:
+# http://brainspl.at/articles/2007/11/09/a-fair-proxy-balancer-for-nginx-and-mongrel
+
# user and group to run as
user nginx nginx;
Oops, something went wrong.

0 comments on commit 2dee1a0

Please sign in to comment.