Installing Passenger with Puppet

Alongside our slow but steady move towards using Puppet for configuration management, our rails team has made the transition to Passenger (‘bye-bye mongrels’). Passenger has a fine installation mechanism for installation, but we wanted to be able to push out production-level machines and VMs with the most minimal level of manual intervention.

I found a decent bash script here that we modified to play well with puppet.


#!/bin/bash
#
# passenger_config.sh
export PASSENGER="2.2.5"
export MODDIR=/usr/lib/ruby/gems/1.8/gems/passenger-$PASSENGER/ext/apache2
export LOADER=/etc/httpd/mods-available/passenger.load

yes '' | /usr/bin/passenger-install-apache2-module

if [ -f $MODDIR/mod_passenger.so ] ; then
echo "LoadModule passenger_module $MODDIR/mod_passenger.so" > $LOADER
echo "PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-$PASSENGER" >> $LOADER
echo "PassengerRuby /usr/bin/ruby" >> $LOADER
ln -s $LOADER /etc/httpd/mods-enabled

else
echo I didn\'t create /etc/httpd/mods-available/passenger.load because there is no $MODDIR/mod_passenger.so.
fi

/etc/init.d/httpd configtest && /etc/init.d/httpd graceful

So our passenger_install class runs the above bash script and subscribes to a file named reconfig_passenger. This allows us to upgrade our passenger install by only touching the reconfig_passenger file on the puppetmaster. The puppet client detects there has been a modification to the file and re-runs the passenger_config script.

# class for installing passenger
class passenger_install {
file { "/usr/bin/passenger_config.sh":
source => "puppet://puppetmaster/files/passenger_config.sh",
owner => "root",
group => "root",
mode => "775"
}

package { "passenger":
ensure => "2.2.5",
provider => "gem"
}
file { "/etc/reconfig_passenger":
source => "puppet://puppetmaster/files/reconfig_passenger",
owner => "root",
group => "root",
mode => "664"
}
# only run config script if this file changes
exec { "/usr/bin/passenger_config.sh":
subscribe => file[ "/etc/reconfig_passenger" ],
refreshonly => true
}
}

We can now roll out production-level VMs in about 22 minutes with a combination of kickstart and puppet. There are a few manual issues existing that are due to our home-rolled python packages, but I’m rather happy with what we’ve been able to do. Even better, we start to get a layer of control over packages, permissions and all innumerable tasks that were done to bring a machine up to match our production stack.

Comments

3 Responses to “Installing Passenger with Puppet”

  1. James Hillyerd on October 10th, 2009 8:18 pm

    Thanks for this. One change I suggest (is working for me), subscribe to the passenger_config.sh script instead of using a touch file. You have to edit the script to change the passenger version anyhow.

    Also, you don’t need to “export” the variables in your script since you are only using them locally.

    -james

  2. mjladd on October 11th, 2009 3:19 am

    Ah, good points. We were working to be able to manage different versions of passenger on different servers, but I think having versioned passenger_conf scripts would probably be a better way to go.

  3. Stefan on November 29th, 2010 1:25 pm

    At least for Debian users I wrote a nice tutorial on my blog. Its gotten much easier to install it on Squeeze.

    http://sts.ono.at/blog/2010/08/31/debian-puppet-passenger/