<?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>SmartLogic Solutions Blog &#187; Apache</title>
	<atom:link href="http://blog.smartlogicsolutions.com/category/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.smartlogicsolutions.com</link>
	<description>News and updates from the people at SmartLogic Solutions</description>
	<lastBuildDate>Tue, 30 Nov 2010 21:39:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Rack::Rewrite for Site Maintenance and Downtime</title>
		<link>http://blog.smartlogicsolutions.com/2009/11/16/rack-rewrite-for-site-maintenance-and-downtime/</link>
		<comments>http://blog.smartlogicsolutions.com/2009/11/16/rack-rewrite-for-site-maintenance-and-downtime/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 15:36:26 +0000</pubDate>
		<dc:creator>John Trupiano</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[John Trupiano]]></category>
		<category><![CDATA[Rack]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rack-rewrite]]></category>
		<category><![CDATA[rubygem]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=740</guid>
		<description><![CDATA[Rack::Rewrite is a Rack middleware for defining and applying rewrite rules. Though it&#8217;s not a full replacement for Apache&#8217;s mod_rewrite, a great deal of rules I&#8217;ve previously written in Apache config files can be replaced by Rack::Rewrite. Run gem install rack-rewrite to install the gem. I typically leverage rewrite rules to take my sites offline [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/jtrupiano/rack-rewrite">Rack::Rewrite</a> is a <a href="http://rack.rubyforge.org/">Rack</a> middleware for defining and applying rewrite rules.  Though it&#8217;s not a full replacement for <a href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html">Apache&#8217;s mod_rewrite</a>, a great deal of rules I&#8217;ve previously written in Apache config files can be replaced by Rack::Rewrite.  Run <code>gem install rack-rewrite</code> to install the gem.</p>
<p>I typically leverage rewrite rules to take my sites offline for maintenance.  Most <a href="http://www.capify.org/index.php/Capistrano">capistrano</a> users will be familiar with the following Apache rewrite ruleset.<br />
<span id="more-740"></span></p>
<pre>
  RewriteCond %{REQUEST_URI} !\.(css|jpg|png)$
  RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
  RewriteCond %{SCRIPT_FILENAME} !maintenance.html
  RewriteRule ^.*$ /system/maintenance.html [L]
</pre>
<p>This ruleset matches requests for non-asset URL&#8217;s and renders a maintenance page if it exists on the filesystem.  When capistrano users run <code>cap deploy:web:disable REASON="site upgrade" UNTIL="2PM"</code> a maintenance page is placed in public/system and this ruleset begins to kick in.  Running <code>cap deploy:web:enable</code> will remove this page and the ruleset ceases to match.</p>
<p>We can replace this ruleset with the following Rack::Rewrite rule:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#008000; font-style:italic;"># Ruby 1.8.x</span>
  maintenance_file = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ROOT, <span style="color:#996600;">'public'</span>, <span style="color:#996600;">'system'</span>, <span style="color:#996600;">'maintenance.html'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  send_file <span style="color:#006600; font-weight:bold;">/</span>.<span style="color:#006600; font-weight:bold;">*/</span>, maintenance_file, :<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>rack_env<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>maintenance_file<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> rack_env<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'REQUEST_URI'</span><span style="color:#006600; font-weight:bold;">&#93;</span> !~ <span style="color:#006600; font-weight:bold;">/</span>\.<span style="color:#006600; font-weight:bold;">&#40;</span>css<span style="color:#006600; font-weight:bold;">|</span>jpg<span style="color:#006600; font-weight:bold;">|</span>png<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>This rewrite rule uses the <code>send_file</code> method to return the maintenance page, uses a rule guard (the :if proc) to check for the existence of the file, and accesses the rack environment directly (rack_env arg to the Proc) to check the request URI.  Due to the shortcomings of the Ruby 1.8&#8242;s regular expression library (no negative lookahead), we have to leverage the rule guard to allow assets to continue to be served (css, jpg, png).</p>
<p>Using Ruby 1.9, this rule is simpler.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#008000; font-style:italic;"># Ruby 1.9.x</span>
  maintenance_file = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ROOT, <span style="color:#996600;">'public'</span>, <span style="color:#996600;">'system'</span>, <span style="color:#996600;">'maintenance.html'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  send_file <span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span>.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span>$<span style="color:#006600; font-weight:bold;">&#40;</span>?<span style="color:#006600; font-weight:bold;">&lt;</span>!css<span style="color:#006600; font-weight:bold;">|</span>png<span style="color:#006600; font-weight:bold;">|</span>jpg<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span>, maintenance_file, :<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>rack_env<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>maintenance_file<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>Users of 1.8.x can leverage <a href="http://oniguruma.rubyforge.org/">Oniguruma</a> to keep the rule simpler.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#008000; font-style:italic;"># Ruby 1.8.x + Oniguruma</span>
  maintenance_file = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ROOT, <span style="color:#996600;">'public'</span>, <span style="color:#996600;">'system'</span>, <span style="color:#996600;">'maintenance.html'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  send_file <span style="color:#6666ff; font-weight:bold;">Oniguruma::ORegexp</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;(.*)$(?&lt;!css|png|jpg)&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, maintenance_file, :<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>rack_env<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>maintenance_file<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2010/01/06/rack-rewrite-0-2-1-released/" rel="bookmark" class="crp_title">Rack::Rewrite 0.2.1 Released</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/05/13/rack-rewrite-1-0-0-released/" rel="bookmark" class="crp_title">Rack::Rewrite 1.0.0 Released</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/11/24/rack-rewrite-google-analytics-makes-site-transitions-seamless/" rel="bookmark" class="crp_title">Rack::Rewrite + Google Analytics Makes Site Transitions Seamless</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/05/13/directory-conventions-for-rack-middleware-rubygems/" rel="bookmark" class="crp_title">Directory Conventions for Rack Middleware RubyGems</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/06/02/better-setup-for-environments-in-rails/" rel="bookmark" class="crp_title">Better setup for environments in Rails</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2009/11/16/rack-rewrite-for-site-maintenance-and-downtime/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Integrity CI on Passenger 2.2.2 with Ruby Enterprise Edition on Ubuntu 8.04</title>
		<link>http://blog.smartlogicsolutions.com/2009/04/26/integrity-ci-on-passenger-222-with-ruby-enterprise-edition-on-ubuntu-804/</link>
		<comments>http://blog.smartlogicsolutions.com/2009/04/26/integrity-ci-on-passenger-222-with-ruby-enterprise-edition-on-ubuntu-804/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 17:38:28 +0000</pubDate>
		<dc:creator>John Trupiano</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[Integrity]]></category>
		<category><![CDATA[Passenger]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby Enterprise Edition]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[ci]]></category>
		<category><![CDATA[ree]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=592</guid>
		<description><![CDATA[I just spent a few hours trying to get this configuration sorted out, so I thought I&#8217;d share my notes. My goal was to get Integrity running on Passenger with Ruby Enterprise Edition. However, I couldn&#8217;t get the user Integrity/Apache was running as to use the proper PATH. Whenever Integrity would try to build my [...]]]></description>
			<content:encoded><![CDATA[<p>I just spent a few hours trying to get this configuration sorted out, so I thought I&#8217;d share my notes.  My goal was to get <a href="http://integrityapp.com/">Integrity</a> running on <a href="http://modrails.com/">Passenger</a> with <a href="http://rubyenterpriseedition.com/">Ruby Enterprise Edition</a>.  However, I couldn&#8217;t get the user Integrity/Apache was running as to use the proper PATH.</p>
<p>Whenever Integrity would try to build my project, I&#8217;d get an error about rake not being able to be found: <code>sh: rake: not found</code></p>
<p><span id="more-592"></span></p>
<p>This totally threw me.  I had added it to /etc/environment</p>
<pre>
PATH="/opt/ruby/bin:$PATH"
</pre>
<p>and so it was certainly on my PATH:</p>
<pre>
john@john-ci:~$ echo $PATH
/opt/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
</pre>
<p>I had also added it to /root/.bash_profile so that root would have it picked up:</p>
<pre>
john@john-ci:~$ sudo su -
root@john-ci:~# echo $PATH
/opt/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
</pre>
<p>So why wasn&#8217;t Apache/Integrity picking it up?  To seek this out, I opened up the Integrity source and edited /opt/ruby/lib/ruby/gems/1.8/gems/integrity-0.1.9.3/lib/integrity/project_builder.rb to output the values of `whoami` and $PATH to help me troubleshoot.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC00FF; font-weight:bold;">IO</span>.<span style="color:#9900CC;">popen</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;(echo `whoami` &amp;&amp; echo $PATH &amp;&amp; cd #{scm.working_directory} &amp;&amp; $
          |output| build.output = output.read }</span></pre></div></div>

<p>Doing this yielded the following output:</p>
<pre>
www-data
/usr/local/bin:/usr/bin:/bin
</pre>
<p>At this point, I wholly expected the PATH to not include /opt/ruby/bin, so this isn&#8217;t a surprise.  But why is this being set?</p>
<h3>The Real Problem</h3>
<p>The real issue here was that I was trying to set the PATH in scripts that only get run when a shell is entered.  Since apache starts up as a system process, it is not started from a shell, and does not have a PATH associated with it.  In fact, if you open up /etc/init.d/apache, you&#8217;ll see on one of the first few lines that the PATH is distinctly set:</p>
<pre>
ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"
</pre>
<p>This was precisely the PATH I was seeing when I hacked Integrity to output its PATH just prior to failing the Rake command.  Now it&#8217;s fairly obvious that I just need to add in /opt/ruby/bin to the front of that PATH, and Integrity will be able to execute all of my ruby/rubygem executables (most importantly rake).</p>
<h3>Recap of Steps to Install</h3>
<ol>
<li><a href="http://rubyenterpriseedition.com/download.html">Download</a> and install REE</li>
<li>Create a symlink for /opt/ruby so it&#8217;s dead simple to upgrade when a new REE comes out: <code>sudo ln -s /opt/ruby-enterprise-whatever-version-you-installed /opt/ruby</code></li>
<li>edit /etc/environment to add /opt/ruby/bin to your shell PATH : <code>PATH=/opt/ruby/bin:$PATH</code></li>
<li>edit ~/.bash_profile to alias sudo so that sudo can inherit your environment : <code>alias sudo='sudo env PATH=$PATH'</code></li>
<li>Reload your environment to pick up the new PATH: <code>source /etc/environment &#038;&#038; source ~/.bash_profile</code></li>
<li>Install Passenger: <code>sudo gem install passenger &#038;&#038; passenger-install-apache2-module</code></li>
<li>Install Integrity Gem: <code>sudo gem install integrity</code></li>
<li>Install Integrity Home: <code>sudo integrity install --passenger ~www-data/integrity</code></li>
<li>Install do_sqlite3 Gem: <code>sudo gem install do_sqlite3</code></li>
<li>Prepare Integrity Database: <code>cd ~www-data/integrity &#038;&#038; sudo integrity migrate_db config.yml</code></li>
<li>Grant ownership of all integrity files to www-data: <code>sudo chown -R www-data:www-data ~www-data/integrity</code></li>
<li>Create Apache config for Integrity: <code>sudo nano -w /etc/apache2/sites-available/integrity</code>:
<pre>
<VirtualHost *>
  ServerName ci.yourdomain.com
  DocumentRoot /var/www/integrity/public
</VirtualHost>
</pre>
</li>
<li>Enable the site: <code>sudo ln -s /etc/apache2/sites-available/integrity /etc/apache2/sites-enabled/002-integrity</code></li>
<li>Edit /etc/init.d/apache2 and add /opt/ruby/bin to the PATH as described above: <code>ENV="env -i LANG=C PATH=/opt/ruby/bin:/usr/local/bin:/usr/bin:/bin"</code></li>
<li>Restart Apache: <code>sudo /etc/init.d/apache2 restart</code></li>
<li>Navigate to http://ci.yourdomain.com/ and start adding projects.</li>
</ol>
<p>Boy, that was a mouthful.  Please let me know if you&#8217;ve also been successful, and if there are any other steps you take to set up Integrity with REE and Passenger.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2009/06/10/shell-script-to-upgrade-ruby-enterprise-edition-while-maintaining-directory-naming-sanity/" rel="bookmark" class="crp_title">Shell Script to Upgrade Ruby Enterprise Edition while Maintaining Directory Naming Sanity</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/02/01/setting-up-ubuntu-9-10-for-ruby-on-rails-development/" rel="bookmark" class="crp_title">Setting Up Ubuntu 9.10 for Ruby On Rails Development</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/06/02/better-setup-for-environments-in-rails/" rel="bookmark" class="crp_title">Better setup for environments in Rails</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/07/07/i-cant-upgrade-rubygems-from-111-to-120-on-ubuntu/" rel="bookmark" class="crp_title">I can&#8217;t upgrade RubyGems from 1.1.1 to 1.2.0 on Ubuntu</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/08/04/introducing-environmentalize-an-intuitive-environment-focused-config-structure-for-your-rails-applications/" rel="bookmark" class="crp_title">Introducing environmentalist: an intuitive, environment-focused config structure for your rails applications</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2009/04/26/integrity-ci-on-passenger-222-with-ruby-enterprise-edition-on-ubuntu-804/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

