<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Zownir Enterprises &#187; Mongrel</title>
	<atom:link href="http://zownir.net/tag/mongrel/feed" rel="self" type="application/rss+xml" />
	<link>http://zownir.net</link>
	<description></description>
	<lastBuildDate>Mon, 10 May 2010 09:02:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Rails and Git</title>
		<link>http://zownir.net/2008/03/16/rails-and-git</link>
		<comments>http://zownir.net/2008/03/16/rails-and-git#comments</comments>
		<pubDate>Mon, 17 Mar 2008 02:00:00 +0000</pubDate>
		<dc:creator>Ronnie Zownir</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Mongrel]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[My notes from Scott Chacon&#8217;s screencast. You should check it out for yourself. It is definitely well worth your time. Instantiate a git repository with a newly minted rails app. rails railsapp &#38;&#38; cd railsapp git init-db touch .gitignore Add the following lines to .gitignore: config/database.yml tmp/* log/* Add all the files to the repository [...]]]></description>
			<content:encoded><![CDATA[<p>My notes from <a href="http://jointheconversation.org/railsgit">Scott Chacon&#8217;s screencast</a>. You should check it out for yourself. It is definitely well worth your time.</p>
<h3>Instantiate a git repository with a newly minted rails app.</h3>
<pre><code>rails railsapp &amp;&amp; cd railsapp
git init-db
touch .gitignore
</code></pre>
<p>Add the following lines to <code>.gitignore</code>:</p>
<pre><code>config/database.yml
tmp/*
log/*
</code></pre>
<p>Add all the files to the repository and commit all.</p>
<pre><code>git add .
git status # To check the status of the working copy.
git commit -a -m "Initial commit"
git log # To see the log for the repository.
</code></pre>
<h3>Create a remote git repository from the one just created.</h3>
<pre><code>cd ..
git clone --bare railsapp/.git railsapp.git
scp -r railsapp.git username@remote-machine:/home/username/git-repos
cd railsapp
git remote add gitserver username@remote-machine:/home/username/git-repos/railsapp.git
</code></pre>
<p>Replace <code>gitserver</code> with a name you want to reference the remote machine by. Make sure that the path to the <code>git</code> binaries is defined in <code>~/.bashrc</code> and not <code>~/.bash_profile</code> because remote commands load the former and not the latter. Information about the remote is added in the <code>git</code> config.</p>
<pre><code>git push gitserver # Push the code in local repository to gitserver
</code></pre>
<p>On the remote machine, in railsapp.git:</p>
<pre><code>export GIT_DIR=.
git log
</code></pre>
<h3>Branching and merging in git.</h3>
<pre><code>git branch -a # Show all git branches (including the remote machine).
git branch # Show all local git branches.
git checkout -b experimental # Create and switch to new branch "experimental".
git checkout master # Switch back to master branch.
git checkout experimental # Switch back to experimental branch.
</code></pre>
<p>To merge experimental into master:</p>
<pre><code>git checkout master # Switch to the master branch as the working copy.
git pull . experimental # Does a fetch and then a merge; you could just merge.
git add filenameinconflict # Fix files in conflict and then do a git add.
git commit -a # After merging do a commit.
</code></pre>
<p>After merging the experimental branch into master, we&#8217;re finished with it so we can delete its identifier. The branch&#8217;s change history will still be there but the branch name is gone. To do so:</p>
<pre><code>git branch -d experimental
git branch # See that the branch name is deleted.
gitk --all&amp; # Visualize the change history using a TK GUI.
</code></pre>
<h3>Database</h3>
<h4>database.yml</h4>
<pre><code>development:
  adapter: sqlite3
  database: db/development.sqlite3

test:
  adapter: sqlite3
  database: db/test.sqlite3

production:
  adapter: mysql
  encoding: utf8
  host: localhost
  database: production_db_name
  username: mysql_username
  password: mysql_password
</code></pre>
<h3>Mongrel Cluster</h3>
<h4>mongrel_cluster.yml</h4>
<pre><code>---
user: user
group: user
environment: production
address: 127.0.0.1
port: 3000
servers: 2
cwd: /home/user/webapps/railsapp/current
log_file: log/mongrel.log
pid_file: tmp/pids/mongrel.pid
</code></pre>
<h3>Capistrano</h3>
<p>In railsapp, execute:</p>
<pre><code>capify .
</code></pre>
<h4>Capfile</h4>
<pre><code>load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy'
load 'config/mongrel' # mongrel overrides
</code></pre>
<h4>deploy.rb</h4>
<pre><code>set :application, "railsapp"
set :repository,  "user@webxx.webfaction.com:/home/user/git-repos/railsapp.git"
set :domain, "webxx.webfaction.com"
set :deploy_to, "/home/user/webapps/#{application}"
set :mongrel_conf, "#{current_path}/config/mongrel_cluster.yml"
set :scm, :git
set :deploy_via, :remote_cache
ssh_options[:paranoid] = false
set :user, "user"
set :runner, "user"
set :use_sudo, false
role :app, domain
role :web, domain
role :db,  domain, :primary =&gt; true

# If the production web server doesn't have access to your git server,
# add the following two lines.
set :deploy_via, :copy # instead of :remote_cache
set :git_shallow_clone, 1 # optional, but makes things faster

# moves over server config files after deploying the code
task :update_config, :roles =&gt; [:app] do
  run "cp -Rf #{shared_path}/config/* #{release_path}/config/"
end
after 'deploy:update_code', :update_config
</code></pre>
<h4>mongrel.rb</h4>
<pre><code># mongrel-based overrides of the default tasks

namespace :deploy do
  namespace :mongrel do
    [ :stop, :start, :restart ].each do |t|
      desc "#{t.to_s.capitalize} the mongrel appserver"
      task t, :roles =&gt; :app do
        #invoke_command checks the use_sudo variable to determine how to run the mongrel_rails command
        invoke_command "mongrel_rails cluster::#{t.to_s} -C #{mongrel_conf}", :via =&gt; run_method
      end
    end
  end

  desc "Custom restart task for mongrel cluster"
  task :restart, :roles =&gt; :app, :except =&gt; { :no_release =&gt; true } do
    deploy.mongrel.restart
  end

  desc "Custom start task for mongrel cluster"
  task :start, :roles =&gt; :app do
    deploy.mongrel.start
  end

  desc "Custom stop task for mongrel cluster"
  task :stop, :roles =&gt; :app do
    deploy.mongrel.stop
  end

end
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://zownir.net/2008/03/16/rails-and-git/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mongrel_cluster with Nonconsecutive Ports</title>
		<link>http://zownir.net/2008/03/15/mongrel_cluster-with-nonconsecutive-ports</link>
		<comments>http://zownir.net/2008/03/15/mongrel_cluster-with-nonconsecutive-ports#comments</comments>
		<pubDate>Sun, 16 Mar 2008 02:30:00 +0000</pubDate>
		<dc:creator>Ronnie Zownir</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Mongrel]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[WebFaction]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Need to operate mongrel_cluster with nonconsecutive ports? No problem. WebFaction assigns ports to its users through the control panel. By design, the panel assigns ports in such a way that users hoping to officially stake claim to a consecutive block of ports are out of luck. Ports that the panel intentionally does not assign can [...]]]></description>
			<content:encoded><![CDATA[<p>Need to operate <code>mongrel_cluster</code> with nonconsecutive ports? No problem.</p>
<p><a href="http://www.webfaction.com?affiliate=rzownir">WebFaction</a> assigns ports to its users through the control panel. By design, the panel assigns ports in such a way that users hoping to officially stake claim to a consecutive block of ports are out of luck. Ports that the panel intentionally does not assign can be put to use, but let us suppose that this practice is frowned upon. If you are interested in running <code>mongrel_cluster</code>, walking the line requires a little bit of effort. Out of the box, <code>mongrel_cluster</code> spawns <code>mongrel_rails</code> listeners on consecutive ports. Configuration is limited to specifying the first port and the number of instances. The situation outlined requires a more precise port configuration and that in turn requires modification the the <code>mongrel_cluster</code> code. Luckily, this modification comes down to a one line addition.</p>
<p>The file requiring modification is <code>lib/mongrel_cluster/init.rb</code> inside the <code>mongrel_cluster</code> gem directory. The easiest way to find and open this file for editing is to execute the following command:</p>
<pre><code>nano `locate lib/mongrel_cluster/init.rb`
</code></pre>
<p>Locate the <code>read_options</code> method. In version 1.0.5, it should read:</p>
<pre><code>def read_options
    @options = {
        "environment" =&gt; ENV['RAILS_ENV'] || "development",
        "port" =&gt; 3000,
        "pid_file" =&gt; "tmp/pids/mongrel.pid",
        "log_file" =&gt; "log/mongrel.log",
        "servers" =&gt; 2
    }
    conf = YAML.load_file(@config_file)
    @options.merge! conf if conf

    process_pid_file @options["pid_file"]
    process_log_file @options["log_file"]

    start_port = end_port = @only
    start_port ||=  @options["port"].to_i
    end_port ||=  start_port + @options["servers"] - 1
    @ports = (start_port..end_port).to_a
end
</code></pre>
<p>Add the following line to the end of the method:</p>
<pre><code>@ports = @options["ports"] if @options["ports"] &amp;&amp; !@only
</code></pre>
<p>What this addition does is acknowledge a parameter named &#8216;ports&#8217; in <code>config/mongrel_cluster.yml</code>. Unless a single port is specified on the command line using the <code>--only</code> option, &#8216;ports&#8217; will be respected over the &#8216;port&#8217; and &#8216;servers&#8217; parameters used to specify a continuous range. The &#8216;ports&#8217; parameter should be accompanied by an array of integers in YAML format. An example <code>mongrel_cluster.yml</code> file that defines nonconsecutive ports follows:</p>
<pre><code>---
cwd: /home/user/webapps/railsapp
environment: production
user: user
group: user
address: 127.0.0.1
log_file: log/mongrel.log
pid_file: tmp/pids/mongrel.pid
ports:
- 3333
- 3335
- 3359
- 3401
</code></pre>
<p>The one line addition does not allow you to define discontinuous ports on the command line. You must edit <code>mongrel_cluster.yml</code> to do so. This is merely a matter of convenience and has no operational impact whatsoever.</p>
]]></content:encoded>
			<wfw:commentRss>http://zownir.net/2008/03/15/mongrel_cluster-with-nonconsecutive-ports/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
