Using Apache with Mongrel or Thin and Rails 3

When using mod_proxy to load balance between members of a mongrel or thin cluster it’s important not to pass requests through for static content.  A basic virtual site can be configured like this:

<VirtualHost *:80>

    ServerName myapp.mydomain.com
    DocumentRoot /opt/myapp/public

    <Proxy balancer://thinservers>
        BalancerMember http://127.0.0.1:3000
        BalancerMember http://127.0.0.1:3001
        BalancerMember http://127.0.0.1:3002
    </Proxy>

    ProxyPreserveHost On
    ProxyPass /images !
    ProxyPass /stylesheets !
    ProxyPass /javascripts !
    ProxyPass / balancer://thinservers/
    ProxyPassReverse / balancer://thinservers/

    <Proxy *>
     Order deny,allow
     Allow from all
    </Proxy>

    ErrorLog /var/log/apache2/error.log
    LogLevel warn
    CustomLog /var/log/apache2/access.log combined

</VirtualHost>

Thin with Apache

Having run into compatibility issues between Passenger and RJB and between Mongrel and Rails 2.3.8 I’ve been looking at Thin.

Slicehost has a couple of good articles on setting up a Thin cluster with Apache on Ubuntu.

In summary:

gem install thin
thin install
/usr/sbin/update-rc.d -f thin defaults
thin –h # help
thin -C /etc/thin/${appenv}.yml -c ${apphome} -s 3 -e production config
su – ${appenv}bat ; thin -C /etc/thin/${appenv}.yml start

Installing Nokogiri on Ubuntu

Worked for me with Nokogiri 1.4.4 on Ubuntu 10.04 LTS:

# ruby developer packages
sudo apt-get install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8
sudo apt-get install libreadline-ruby1.8 libruby1.8 libopenssl-ruby 

# nokogiri requirements
sudo apt-get install libxslt-dev libxml2-dev
sudo gem install nokogiri

Getting started with Ruby on Windows

To get started my preference is to use RubyInstaller for Windows.  Both 1.8.x and 1.9.x variants are available. I group together my Ruby variants under \Programs\rubies.

Having installed multiple variants you can register and manage them using Pik.  I recommend not changing the installation path from the default C:\pik.  It is in fact possible to install Ruby using Pik (by default Pik installs rubies in %HOMEPATH%\.pik\rubies), but I prefer not to do so.

pik add d:\programs\rubies\ruby-1.8.7-p334\bin
pik add d:\programs\rubies\ruby-1.9.2-p180\bin

To access code repositories you will need to download and install msysGit for Windows.  I also strongly recommend TortoiseGit instead of Git GUI.

To build native extension gems like Nokogiri you will need DevKit.  I tried

pik package devkit install

but this did not work for me (got HTTP 404) so I had to manually download and extract the DevKit.  DevKit also includes MSYS/MinGW.

For an IDE I use Aptana Studio 3.  Studio looks for an existing Git installation or installs its own private copy of portable Git.  Studio then leverages the msysGit bash shell.

RubyInstaller includes gem, which can then be used to install bundler to complete the setup of the environment.

RJB on Ubuntu LTS 10.04

Ruby-Java Bridge (RJB) allows use of Java libraries from within a c-ruby environment, see this slideshow.   RJB provides an alternative when a full port to JRuby is impractical.

First install Java and build-essential

apt-get update
apt-get install openjdk-6-jdk
apt-get install build-essential

Now install rjb gem

export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
gem install rjb

The bad news is that RJB currently crashes when used with Passenger so the best alternative is to revert to Mongrel.

Building Your Own Website

There are several levels of sophistication:

  • Using wizards
  • Leveraging open source packages
  • Mastering HTML, CSS and Javascript in the browser
  • Writing server programs to use a database

Really simple websites can be built using

These are all good for static, slowly changing content.  If you want to publish content regularly consider blogging with

If you want to go beyond blogging consider an open source package like Joomla or Drupal. Sign-up for hosting with a company like Dreamhost or GoDaddy and they will give you simple installation scripts to get started with these packages for a few dollars a month. If you want to customize these or do something more your own you will need to master HTML/CSS/Javascript (DHTML aka. DOM scripting).  Get an HTML editor and study the tutorials at W3 Schools After you’ve learned DHTML you can go on to build database driven sites using Microsoft’s technologies, PHP or Ruby On Rails

Rails Datepickers

There are multiple ways to add date-pickers to a Rails application. Searching for a date picker online I came across one Prototype based gem called calendar_date_select that was featured by Ruby Inside, and another one called Calendar-DatePicker-for-Rails.  On closer inspection, however, calendar_date_select was last updated in 2008 and is looking for a new maintainer: the demo still uses Rails 2.2.2: it does not work with some later versions.

Apart from using a date-picker specifically packaged for Rails it is not that difficult to use a free-standing Javascript solution: I found a nice looking solution called unobtrusive-date-picker but it appears to have limited support. There are also Javascript widget libraries like AUI and jQuery UI.  Finally I came across a Railscast that mentions calendar_date_select but goes on to recommends jQuery UI.  jQuery can be integrated with Rails 2.x using jRails or Rails 3 with jquery-rails and/or jquery-ujs or you can simply forgo the integration and just use jQuery directly. In my case I linked to the libraries hosted by Google like this:

 <%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js" %>
 <%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/humanity/jquery-ui.css" %>

The remaining details of using a jQuery UI datepicker with Rails are covered in the Railscast.

Using Ruby with Postgres on Ubuntu 10.04 LTS

Installation of PostgreSQL on Ubuntu is straightforward, see http://library.linode.com/databases/postgresql/ubuntu-10.04-lucid

To create a simple database with its own user use the command line:

appenv=myapptst
psql <<EOF
  create user ${appenv} createdb password '*****';
EOF
createdb --username=postgres --owner ${appenv} ${appenv}

To access the database from Rails use pg

gem install pg

Entries in database.yml should look like

development:
  adapter: postgresql
  username: myappstst
  password: mypwd
  database: myapptst

Domain Registration

The most popular domain registrars are ranked by Webhosting.info The most popular registrar by far is GoDaddy.com, which rents dot-com domains for less than $12/yr. and includes free DNS management, email and a simple website wizard that can build a basic landing page. Other large online registrars include Enom and Network Solutions. Tucows is a wholesaler and does not sell registrations online. Lifehacker readers recently recommended namecheap.

Building a Windows 7 Image for Dell ImageDirect

ImageDirect is a Dell service that allows you to customize the software on a Dell PC before it ships from Dell’s manufacturing facility. In a distributed organization ImageDirect saves PC support staff from unboxing new PCs, ‘staging’ the PC with preferred configuration settings and software, and boxing and reshipping the PC to its final destination.

With Windows XP the ImageDirect process was as simple as uploading a disk image created with Symantec Norton Ghost, but with Vista and Windows 7 the process has become more sophisticated – and complex. The main benefit of the newer approach is that the customizations are merged with the latest Dell drivers for a given machine model, so one customization image can be applied to multiple models, and it will stay current as newer hardware revisions are shipped by Dell. The drawback is that the customization image has to be more carefully prepared in accordance with Dell’s guidelines (eg. only Professional edition or higher is supported), and can only be used on hardware specifically supported by Dell’s ImageDirect service.

The steps can be summarized as follows:

  • Use only supported hardware to build the customization image. Turn off various BIOS settings as instructed in Dell’s documentation.
  • Discard any software already on the machine. Reinstall Windows 7 from Dell’s OEM media. Delete any factory installed recovery partition.
  • Download and install only the NIC driver from Dell’s support site. Don’t install any other Dell device driver software.
  • After installation enable the Local Administrator account (net user administrator /enable:yes).
  • Log into the local administrator account and delete the account created during the installation process.
  • Customize the local administrator account and install software as required. Check for and install any updates then turn off further automatic updates.
  • Unconfigure any network interfaces (ipconfig /release)
  • Make a system backup.
  • Install and run the Dell Windows 7 Capture tool from DVD.

Once a customization image has been uploaded it has to be retrieved and audited by applying it to a sample machine, possibly the same machine that was used to prepare the image in the first place. Make sure any NIC has an Ethernet cable attached as otherwise the restore may fail.

My first experience with ImageDirect was not as positive as I had hoped for. Dell direct sales has limited familiarity with how ImageDirect works. The upload/download process for 4+GB files is time consuming. The high speed file transfer utility provides better transfer rates using UDP, but there was no way to recover if a transfer was interrupted. The ImageDirect build process can take several hours to prepare an installation image based on an uploaded customization image. The imaging installation process has bugs: troubleshooting issues can wipe out the savings promised by the factory automation. In summary this offering has great potential for larger deployments but be prepared for an upfront investment in time and effort that may not be worthwhile for smaller deployments.

Posts navigation

1 2 3 4 5 6 7 8 9 11 12 13
Scroll to top