<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Tnux.net</title>
	
	<link>http://tnux.net</link>
	<description>Blog of Tom Pesman</description>
	<lastBuildDate>Sun, 17 Jan 2010 19:56:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/tnuxnet" /><feedburner:info uri="tnuxnet" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Ruby on Rails MiniWiki plugin released</title>
		<link>http://feedproxy.google.com/~r/tnuxnet/~3/LcshWEWFqxA/</link>
		<comments>http://tnux.net/2010/01/17/ruby-on-rails-miniwiki-plugin-released/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 19:56:12 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://tnux.net/?p=63</guid>
		<description><![CDATA[To create a wiki in a Ruby on Rails app, I&#8217;ve created a plugin called: MiniWiki. With 3 simple steps it is possible to add a very basic wiki to your application. The only dependency is RedCloth and the generator creates a migration for only two tables in your database. For more detailed information see [...]]]></description>
			<content:encoded><![CDATA[<p>To create a wiki in a Ruby on Rails app, I&#8217;ve created a plugin called: MiniWiki. With 3 simple steps it is possible to add a very basic wiki to your application. The only dependency is RedCloth and the generator creates a migration for only two tables in your database. For more detailed information see the <a href="http://github.com/tompesman/mini_wiki">Github</a> page.</p>
<p>Try here: <a href="http://tnux.net/miniwiki/">http://tnux.net/miniwiki/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tnux.net/2010/01/17/ruby-on-rails-miniwiki-plugin-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://tnux.net/2010/01/17/ruby-on-rails-miniwiki-plugin-released/</feedburner:origLink></item>
		<item>
		<title>SWFUpload direct to Amazon S3 in Ruby on Rails</title>
		<link>http://feedproxy.google.com/~r/tnuxnet/~3/Xs9C6zpkpL0/</link>
		<comments>http://tnux.net/2010/01/17/swfupload-direct-to-amazon-s3-in-ruby-on-rails/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 19:38:17 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Amazon S3]]></category>
		<category><![CDATA[SWFUpload]]></category>

		<guid isPermaLink="false">http://tnux.net/?p=34</guid>
		<description><![CDATA[I&#8217;m working on various projects and for one certain project this company wanted a file sharing website, like yousendit.com for example, but the site should be in-house. I proposed Amazon S3 for the storage of the files, otherwise the VPS will become very expensive. This file sharing website should also handle large files, so a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on various projects and for one certain project this company wanted a file sharing website, like yousendit.com for example, but the site should be in-house. I proposed Amazon S3 for the storage of the files, otherwise the VPS will become very expensive. This file sharing website should also handle large files, so a reliable upload method is desired. SWFUpload is a well known Flash upload application. So the requirements are now complete: Ruby on Rails, Amazon S3 and SWFUpload.</p>
<p>First I created a config file to enter my Amazon S3 credentials. The credentials are dependent on the Ruby on Rails environment. </p>
<p>config/amazon_s3.yml</p>
<pre class="brush: ruby">
development:
  bucket_name: BUCKET_NAME
  access_key_id: ACCESS_KEY_ID
  secret_access_key: SECRET_ACCESS_KEY

test:
  bucket_name: BUCKET_NAME
  access_key_id: ACCESS_KEY_ID
  secret_access_key: SECRET_ACCESS_KEY

production:
  bucket_name: BUCKET_NAME
  access_key_id: ACCESS_KEY_ID
  secret_access_key: SECRET_ACCESS_KEY
</pre>
<p>Created a controller and added the index method. The method reads the S3 settings from the config file and generates the fields required for SWFUpload and S3.</p>
<pre class="brush: ruby">
  def index
    filename = &quot;#{RAILS_ROOT}/config/amazon_s3.yml&quot;
    config = YAML.load_file(filename)

    bucket            = config[ENV[&#039;RAILS_ENV&#039;]][&#039;bucket_name&#039;]
    access_key_id     = config[ENV[&#039;RAILS_ENV&#039;]][&#039;access_key_id&#039;]
    secret_access_key = config[ENV[&#039;RAILS_ENV&#039;]][&#039;secret_access_key&#039;]

    key             = ENV[&#039;RAILS_ENV&#039;]
    acl             = &#039;public-read&#039;
    expiration_date = 10.hours.from_now.utc.strftime(&#039;%Y-%m-%dT%H:%M:%S.000Z&#039;)
    max_filesize    = 2.gigabyte

    policy = Base64.encode64(
      &quot;{&#039;expiration&#039;: &#039;#{expiration_date}&#039;,
        &#039;conditions&#039;: [
          {&#039;bucket&#039;: &#039;#{bucket}&#039;},
          [&#039;starts-with&#039;, &#039;$key&#039;, &#039;#{key}&#039;],
          {&#039;acl&#039;: &#039;#{acl}&#039;},
          {&#039;success_action_status&#039;: &#039;201&#039;},
          [&#039;starts-with&#039;, &#039;$Filename&#039;, &#039;&#039;],
          [&#039;content-length-range&#039;, 0, #{max_filesize}]
        ]
      }&quot;).gsub(/\n|\r/, &#039;&#039;)

    signature = Base64.encode64(
                  OpenSSL::HMAC.digest(
                    OpenSSL::Digest::Digest.new(&#039;sha1&#039;),
                    secret_access_key, policy)).gsub(&quot;\n&quot;,&quot;&quot;)

    @post = {
      &quot;key&quot; =&gt; &quot;#{key}/${filename}&quot;,
      &quot;AWSAccessKeyId&quot; =&gt; &quot;#{access_key_id}&quot;,
      &quot;acl&quot; =&gt; &quot;#{acl}&quot;,
      &quot;policy&quot; =&gt; &quot;#{policy}&quot;,
      &quot;signature&quot; =&gt; &quot;#{signature}&quot;,
      &quot;success_action_status&quot; =&gt; &quot;201&quot;
    }

    @upload_url = &quot;http://#{bucket}.s3.amazonaws.com/&quot;
  end
</pre>
<p>And the index.html.erb view.</p>
<pre class="brush: ruby">
&lt;% content_for :head do %&gt;
&lt;link href=&quot;/stylesheets/swfupload.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
&lt;% end%&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/swfupload/swfupload.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/swfupload/swfupload.queue.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/swfupload/fileprogress.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/swfupload/handlers.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
	var swfu;

	window.onload = function() {
		var settings = {
			flash_url : &quot;/assets/swfupload.swf&quot;,
			upload_url: &quot;&lt;%= @upload_url %&gt;&quot;,
			http_success : [ 200, 201, 204 ], 		// FOR AWS

			file_size_limit : &quot;2 GB&quot;,
			file_types : &quot;*.*&quot;,
			file_types_description : &quot;All Files&quot;,
			file_upload_limit : 100,
			file_queue_limit : 0,
			file_post_name : &quot;file&quot;, 				// FOR AWS

			custom_settings : {
				progressTarget : &quot;fsUploadProgress&quot;,
				cancelButtonId : &quot;btnCancel&quot;
			},
			debug: &lt;%= ENV[&#039;RAILS_ENV&#039;]==&#039;development&#039; ? &#039;true&#039; : &#039;false&#039; %&gt;,

			// Button settings
			button_image_url : &quot;/images/buttonUploadText.png&quot;,
			button_placeholder_id : &quot;spanButtonPlaceHolder&quot;,
			button_width: 61,
			button_height: 22,

			// The event handler functions are defined in handlers.js
			file_queued_handler : fileQueued,
			file_queue_error_handler : fileQueueError,
			file_dialog_complete_handler : fileDialogComplete,
			upload_start_handler : uploadStart,
			upload_progress_handler : uploadProgress,
			upload_error_handler : uploadError,
			upload_success_handler : uploadSuccess,
			upload_complete_handler : uploadComplete,
			queue_complete_handler : queueComplete,	// Queue plugin event

			post_params: &lt;%= @post.to_json %&gt;		// FOR AWS
		};

		swfu = new SWFUpload(settings);
     };
&lt;/script&gt;

&lt;div id=&quot;content&quot;&gt;
	&lt;form id=&quot;form&quot; action=&quot;/upload/upload&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
			&lt;div class=&quot;fieldset flash&quot; id=&quot;fsUploadProgress&quot;&gt;
			&lt;span class=&quot;legend&quot;&gt;Upload Queue&lt;/span&gt;
			&lt;/div&gt;
		&lt;div id=&quot;divStatus&quot;&gt;0 Files Uploaded&lt;/div&gt;
			&lt;div&gt;
				&lt;span id=&quot;spanButtonPlaceHolder&quot;&gt;&lt;/span&gt;
				&lt;input id=&quot;btnCancel&quot; type=&quot;button&quot; value=&quot;Cancel All Uploads&quot; onclick=&quot;swfu.cancelQueue();&quot; disabled=&quot;disabled&quot; style=&quot;margin-left: 2px; font-size: 8pt; height: 29px;&quot; /&gt;
			&lt;/div&gt;

	&lt;/form&gt;
&lt;/div&gt;
</pre>
<p>Upload the file crossdomain.xml to the root of your bucket. This is for Flash to upload to a different domain.</p>
<pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!DOCTYPE cross-domain-policy SYSTEM &quot;http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd&quot;&gt;
&lt;cross-domain-policy&gt;
  &lt;allow-access-from domain=&quot;*&quot; secure=&quot;false&quot; /&gt;
&lt;/cross-domain-policy&gt;
</pre>
<p>Finally took the files from the SWFUpload simpledemo and placed them in the following directories:</p>
<ul>
<li>swfupload.swf in public/assets/</li>
<li>fileprogress.js, handles.js, swfupload.js and swfupload.queue.js in public/javascripts/swfupload/</li>
<li>buttonUploadText.png in public/images/</li>
</ul>
<p>Now SWFUpload should be working in your Ruby on Rails application.</p>
<p><strong>Callback</strong><br />
For my application I needed a callback to let my application know there was a file successfully uploaded to the S3 bucket. To get this functionality I added a function to the controller and modified the handlers.js file.</p>
<pre class="brush: ruby">
  def upload_done
    file = ShareFile.new

    file.name = params[:name]
    file.filestatus = params[:filestatus]
    file.filetype = params[:type]
    file.size = params[:size]
    file.s3_available = true

    file.save
  end
</pre>
<pre class="brush: javascript">
function uploadSuccess(file, serverData) {
	// HERE: Send a notification upload has succeeded
	new Ajax.Request(&#039;/share/upload_done?&#039;+Object.toQueryString(file), {
		method:&#039;get&#039;,
		asynchronous: false,
		onSuccess: function(){
			var progress = new FileProgress(file, this.customSettings.progressTarget);
			progress.setStatus(&quot;Sending meta data.&quot;);
		}
	});
	// HERE: end

	try {
		var progress = new FileProgress(file, this.customSettings.progressTarget);
		progress.setComplete();
		progress.setStatus(&quot;Complete.&quot;);
		progress.toggleCancel(false);

	} catch (ex) {
		this.debug(ex);
	}
}
</pre>
<p>When SWFUpload is done uploading it uses the javascript callback to update the status of the form and to send a notification to the Ruby on Rails application.</p>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://tnux.net/2010/01/17/swfupload-direct-to-amazon-s3-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://tnux.net/2010/01/17/swfupload-direct-to-amazon-s3-in-ruby-on-rails/</feedburner:origLink></item>
		<item>
		<title>XEN, Ruby Enterprise Edition and 4gb seg fixup</title>
		<link>http://feedproxy.google.com/~r/tnuxnet/~3/2xCol20A8Oo/</link>
		<comments>http://tnux.net/2010/01/17/xen-ree-4gbsegfixup/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 17:35:39 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[VPS]]></category>
		<category><![CDATA[RubyEnterpriseEdition]]></category>
		<category><![CDATA[XEN]]></category>

		<guid isPermaLink="false">http://tnux.net/?p=32</guid>
		<description><![CDATA[My new CentOS XEN server has a virtual machine which serves as a dedicated web server. The on the console and in /var/log/messages the following message appeared:

4gb seg fixup, process ruby (pid 20252), cs:ip 73:00e0a636
printk: 151939 messages suppressed.

The console is unusable, because every second a new message appears. The logfile is unusable as well, because [...]]]></description>
			<content:encoded><![CDATA[<p>My new CentOS XEN server has a virtual machine which serves as a dedicated web server. The on the console and in /var/log/messages the following message appeared:</p>
<pre class="brush: bash">
4gb seg fixup, process ruby (pid 20252), cs:ip 73:00e0a636
printk: 151939 messages suppressed.
</pre>
<p>The console is unusable, because every second a new message appears. The logfile is unusable as well, because it is very large and takes long to open in a text editor and interesting messages are difficult to find. After some google&#8217;ing I&#8217;ve found the following <a href="http://groups.google.com/group/emm-ruby/browse_thread/thread/1b9beffe8fa694a7/82fd6839307d9298">page</a> with some instructions to fix it. I&#8217;ve mixed up various methods, but this is the most robust one to use. It creates a wrapper around the gcc and g++ binaries with the correct parameters.</p>
<pre class="brush: bash">
mv /usr/bin/gcc /usr/bin/gcc.orig
mv /usr/bin/g++ /usr/bin/g++.orig
echo &#039;#!/bin/sh&#039; &gt; /usr/bin/gcc
echo &#039;#!/bin/sh&#039; &gt; /usr/bin/g++
echo &#039;exec gcc.orig -mno-tls-direct-seg-refs $@&#039; &gt;&gt; /usr/bin/gcc
echo &#039;exec g++.orig -mno-tls-direct-seg-refs $@&#039; &gt;&gt; /usr/bin/g++
chmod a+x /usr/bin/gcc
chmod a+x /usr/bin/g++
</pre>
<p>Extract the Ruby Enterprise Edition. Be careful to use a fresh extracted version to compile, because the files will not be recompiled. Compile and install Ruby Enterprise Edition as stated in the manual.</p>
<pre class="brush: bash">
tar zxvf ruby-enterprise-1.8.7-2009.10.tar.gz
./ruby-enterprise-1.8.7-2009.10/installer
</pre>
<p>Don&#8217;t forget to reinstall passenger, and off course reinstall all the gems from the old installation.</p>
<p>Now you can restore gcc and g++ as this will probably break yum updates of gcc and g++.</p>
<pre class="brush: bash">
rm -rf /usr/bin/gcc &amp;&amp; mv /usr/bin/gcc.orig /usr/bin/gcc
rm -rf /usr/bin/g++ &amp;&amp; mv /usr/bin/g++.orig /usr/bin/g++
</pre>
<p>Hopefully I&#8217;ve saved you guys some time <img src='http://tnux.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://tnux.net/2010/01/17/xen-ree-4gbsegfixup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://tnux.net/2010/01/17/xen-ree-4gbsegfixup/</feedburner:origLink></item>
		<item>
		<title>Capistrano and Passenger part 2</title>
		<link>http://feedproxy.google.com/~r/tnuxnet/~3/KDEpkC0LUEw/</link>
		<comments>http://tnux.net/2009/12/12/capistrano-and-passenger-part-2/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 13:52:21 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://tnux.net/?p=26</guid>
		<description><![CDATA[As Karl Varga pointed out in his comment on my previous post on Capistrano and Passenger (here) my apache rewrite rules did not send back the proper HTTP status codes. Now with the improved and tested rules the 503 status code is returned.

ErrorDocument 503 /system/maintenance.html

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
# RewriteCond %{REQUEST_URI} !^/images/
# RewriteCond %{REQUEST_URI} [...]]]></description>
			<content:encoded><![CDATA[<p>As Karl Varga pointed out in his comment on my previous post on Capistrano and Passenger (<a href="http://tnux.net/2008/06/23/capistrano-and-passenger/">here</a>) my apache rewrite rules did not send back the proper HTTP status codes. Now with the improved and tested rules the 503 status code is returned.</p>
<pre class="brush: bash">
ErrorDocument 503 /system/maintenance.html

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
# RewriteCond %{REQUEST_URI} !^/images/
# RewriteCond %{REQUEST_URI} !^/robots.txt
# RewriteCond %{REQUEST_URI} !^/sitemap
RewriteRule ^.*$ – [redirect=503,last]
</pre>
<p>If your maintenance page has images on it than you can enable line 6 by removing the &#8216;#&#8217;. </p>
<p>See also <a href="http://www.shiftcommathree.com/articles/make-your-rails-maintenance-page-respond-with-a-503">Chris K&#8217;s</a> article.</p>
]]></content:encoded>
			<wfw:commentRss>http://tnux.net/2009/12/12/capistrano-and-passenger-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://tnux.net/2009/12/12/capistrano-and-passenger-part-2/</feedburner:origLink></item>
		<item>
		<title>Namespace route and form_for method</title>
		<link>http://feedproxy.google.com/~r/tnuxnet/~3/0AQ5qcJ4gog/</link>
		<comments>http://tnux.net/2008/06/29/namespace-route-and-form_for-method/#comments</comments>
		<pubDate>Sun, 29 Jun 2008 08:16:43 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[form_for]]></category>
		<category><![CDATA[namespace]]></category>
		<category><![CDATA[routes]]></category>

		<guid isPermaLink="false">http://tnux.net/?p=14</guid>
		<description><![CDATA[When you have a namespace in your routes.rb like this:

  map.namespace :admin do &#124;admin&#124;
    admin.resources :users
  end

And you like to have a form like this: 

&#60;% form_for(@user) do &#124;f&#124; %&#62;
  &#60;%= f.error_messages %&#62;

Change the form_for in this and you&#8217;re good to go!

&#60;% form_for([:admin, @user]) do &#124;f&#124; %&#62;
  &#60;%= [...]]]></description>
			<content:encoded><![CDATA[<p>When you have a namespace in your routes.rb like this:</p>
<pre class="brush: ruby">
  map.namespace :admin do |admin|
    admin.resources :users
  end
</pre>
<p>And you like to have a form like this: </p>
<pre class="brush: ruby">
&lt;% form_for(@user) do |f| %&gt;
  &lt;%= f.error_messages %&gt;
</pre>
<p>Change the form_for in this and you&#8217;re good to go!</p>
<pre class="brush: ruby">
&lt;% form_for([:admin, @user]) do |f| %&gt;
  &lt;%= f.error_messages %&gt;
</pre>
<p>This might save you some time. <img src='http://tnux.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://tnux.net/2008/06/29/namespace-route-and-form_for-method/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://tnux.net/2008/06/29/namespace-route-and-form_for-method/</feedburner:origLink></item>
		<item>
		<title>Gem 1.2.0 released</title>
		<link>http://feedproxy.google.com/~r/tnuxnet/~3/9XzymnOAuBA/</link>
		<comments>http://tnux.net/2008/06/24/gem-120-released/#comments</comments>
		<pubDate>Tue, 24 Jun 2008 10:20:49 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[VPS]]></category>
		<category><![CDATA[Gem]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://tnux.net/?p=10</guid>
		<description><![CDATA[Yesterday gem 1.2.0 was released. This is a release we&#8217;ve all been waiting for! This version doesn&#8217;t have the &#8216;bulkupdate&#8217; and doesn&#8217;t consume that much memory as before. So update your gem for the last time with the -B parameter. Like this:

gem update --system -B 1000000

Before version 1.2.0 I had to do on my VPS:

gem [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday gem 1.2.0 was released. This is a release we&#8217;ve all been waiting for! This version doesn&#8217;t have the &#8216;bulkupdate&#8217; and doesn&#8217;t consume that much memory as before. So update your gem for the last time with the -B parameter. Like this:</p>
<pre class="brush: bash">
gem update --system -B 1000000
</pre>
<p>Before version 1.2.0 I had to do on my VPS:</p>
<pre class="brush: bash">
gem install -B 1000000 --no-rdoc --no-ri rails
</pre>
<p>But now I can do:</p>
<pre class="brush: bash">
gem install --no-rdoc --no-ri rails
</pre>
<p>And it&#8217;s finished in a sec!</p>
]]></content:encoded>
			<wfw:commentRss>http://tnux.net/2008/06/24/gem-120-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://tnux.net/2008/06/24/gem-120-released/</feedburner:origLink></item>
		<item>
		<title>Capistrano and Passenger</title>
		<link>http://feedproxy.google.com/~r/tnuxnet/~3/l0APr7fzOjA/</link>
		<comments>http://tnux.net/2008/06/23/capistrano-and-passenger/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 19:17:19 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Passenger]]></category>

		<guid isPermaLink="false">http://tnux.net/?p=4</guid>
		<description><![CDATA[To use Capistrano on a Passenger enabled host, you need to add the following lines to your config/deploy.rb file.

namespace :deploy do
  desc &#34;Restarting mod_rails with restart.txt&#34;
  task :restart, :roles =&#62; :app, :except =&#62; { :no_release =&#62; true } do
    run &#34;touch #{current_path}/tmp/restart.txt&#34;
  end

  desc &#34;Stop task is a [...]]]></description>
			<content:encoded><![CDATA[<p>To use Capistrano on a Passenger enabled host, you need to add the following lines to your <code>config/deploy.rb</code> file.</p>
<pre class="brush: ruby">
namespace :deploy do
  desc &quot;Restarting mod_rails with restart.txt&quot;
  task :restart, :roles =&gt; :app, :except =&gt; { :no_release =&gt; true } do
    run &quot;touch #{current_path}/tmp/restart.txt&quot;
  end

  desc &quot;Stop task is a deploy.web.disable with mod_rails&quot;
  task :stop, :roles =&gt; :app do
    deploy.web.disable
  end

  desc &quot;Start task is a deploy.web.enable with mod_rails&quot;
  task :start, :roles =&gt; :app do
    deploy.web.enable
  end
end
</pre>
<p>Because in passenger there is no way of stopping or starting your Rails application, I&#8217;ve changed the <code>deploy:start</code> and <code>deploy:stop</code> to <code>deploy:web:enable</code> and <code>deploy:web:disable</code>. The <code>deploy:restart</code> is used by the deploy task, so now your deployment works as expected.</p>
<p><strong>Update:</strong><br />
Don&#8217;t forget to add the rewrite rules to your apache virtual host config, otherwise the enable disable tasks won&#8217;t work.</p>
<pre class="brush: bash">
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tnux.net/2008/06/23/capistrano-and-passenger/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://tnux.net/2008/06/23/capistrano-and-passenger/</feedburner:origLink></item>
		<item>
		<title>Plesk, Passenger (mod_rails), Ruby Enterprise Edition &amp; Ruby on Rails</title>
		<link>http://feedproxy.google.com/~r/tnuxnet/~3/W_LTkHbR1Iw/</link>
		<comments>http://tnux.net/2008/06/23/plesk-passenger-mod_rails-railsenterpriseedition-ruby-on-rails/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 19:16:23 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Plesk]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[VPS]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[CentOS 5]]></category>
		<category><![CDATA[Passenger]]></category>
		<category><![CDATA[RubyEnterpriseEdition]]></category>

		<guid isPermaLink="false">http://tnux.net/?p=3</guid>
		<description><![CDATA[Currently I have a Plesk 8.4 installation running on a CentOS 5 VPS. First I had my Ruby on Rails websites running on multiple mongrel servers (cluster) but it took too much RAM of my VPS and it was very complicated to add more websites. So now I’ve installed Passenger (make sure you check the [...]]]></description>
			<content:encoded><![CDATA[<p>Currently I have a Plesk 8.4 installation running on a CentOS 5 VPS. First I had my Ruby on Rails websites running on multiple mongrel servers (cluster) but it took too much RAM of my VPS and it was very complicated to add more websites. So now I’ve installed <a href="http://www.modrails.com/">Passenger</a> (make sure you check the screencast on the Passenger website!) which makes adding websites very easy. Also I’ve installed <a href="http://www.rubyenterpriseedition.com/">RubyEnterpriseEdition</a> which reduces the memory needed for Ruby applications, including Ruby on Rails. Below I’ll describe the steps I took to complete this installation.</p>
<p><strong>Passenger</strong></p>
<p>Just follow the steps described on the Passenger website. Run as root:</p>
<pre class="brush: bash">
gem install passenger
</pre>
<p>The following command verifies if all the dependencies are installed, if not it suggests what rpm’s should be installed and exits. If all the dependencies are met, it compiles the Apache 2 module and installs the module.</p>
<pre class="brush: bash">
passenger-install-apache2-module
</pre>
<p>Personally I hate installers who do a lot of stuff you can&#8217;t control, but this one does only the stuff it should do and will not break your current setup. After the module is installed you need to add the module to Apache. So I created the file <code>/etc/httpd/conf.d/passenger.conf</code> with the following contents:</p>
<pre class="brush: bash">
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.1/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.1
PassengerRuby /usr/bin/ruby
</pre>
<p>Restart Apache.</p>
<pre class="brush: bash">
/etc/init.d/httpd restart
</pre>
<p>At this point you have installed Passenger and the only thing to make a Ruby on Rails application work, is to point the Apache <code>DocumentRoot</code> directive to the public directory of your Rails application.</p>
<p><strong>RubyEnterpriseEdition</strong></p>
<p>Download RubyEnterpriseEdition (REE), extract the file and run the installer. As described on the REE website.</p>
<pre class="brush: bash">
wget http://rubyforge.org/frs/download.php/38777/ruby-enterprise-1.8.6-20080624.tar.gz
tar xzvf ruby-enterprise-1.8.6-20080624.tar.gz
./ruby-enterprise-1.8.6-20080624/install
</pre>
<p>This installer will install it’s own Ruby environment to /opt. This is good, because it will not touch your current Ruby environment. After the installation you’ll have a separate gem installed which is version 1.2.0. The version without the gem bulkupdate, which causes a lot of memory problems on VPS’es. The following commands I’ve used to install different gems. Mysql did not install easily, but with the <code>-- --with-mysql</code> it worked. Note the <code>--no-rdoc</code> and <code>--no-ri</code> because we’re on a production environment we don&#8217;t need the documentation.</p>
<pre class="brush: bash">
/opt/ruby-enterprise-1.8.6-20080624/bin/gem install --no-rdoc --no-ri rails
/opt/ruby-enterprise-1.8.6-20080624/bin/gem install --no-rdoc --no-ri -v 1.2.6 rails
/opt/ruby-enterprise-1.8.6-20080624/bin/gem install --no-rdoc --no-ri -v 2.0.2 rails
/opt/ruby-enterprise-1.8.6-20080624/bin/gem install --no-rdoc --no-ri mysql -- --with-mysql-config
</pre>
<p>If you have all the gems installed which you need in your Rails applications, it’s time to switch the Ruby Interpreter to the REE installation, we do this by replacing the <code>PassengerRuby</code> line in the <code>/etc/httpd/conf.d/passenger.conf</code> file.</p>
<pre class="brush: bash">
PassengerRuby /opt/ruby-enterprise-1.8.6-20080624/bin/ruby
</pre>
<p><strong>Finetuning</strong></p>
<p>Depending on the available RAM on your VPS, you should add the following line to <code>passenger.conf</code>:</p>
<pre class="brush: bash">
PassengerMaxPoolSize 2
</pre>
<p>To prevent Passenger from invoking to many instances of the Rails app.</p>
<p><strong>Plesk</strong></p>
<p>The only thing you have to do in Plesk is to modify the DocumentRoot. I&#8217;ve made a app directory where I deploy my Rails application with Capistrano. Create the file vhost.conf in the config directory of your domain.</p>
<pre class="brush: bash">
DocumentRoot /var/www/vhosts/DOMAIN.COM/app/current/public
</pre>
<p>After that run the following command to let Plesk reconfigure your domain and add a include for your vhost.conf file.</p>
<pre class="brush: bash">
/usr/local/psa/admin/sbin/websrvmng -u --vhost-name=DOMAIN.COM
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tnux.net/2008/06/23/plesk-passenger-mod_rails-railsenterpriseedition-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://tnux.net/2008/06/23/plesk-passenger-mod_rails-railsenterpriseedition-ruby-on-rails/</feedburner:origLink></item>
	</channel>
</rss>
