Author Topic: Using Capistrano to tweak a dcerouter after (re)install  (Read 3025 times)


  • Guru
  • ****
  • Posts: 261
    • View Profile
Using Capistrano to tweak a dcerouter after (re)install
« on: May 26, 2008, 09:58:18 am »

One of the pains of testing different releases or just recovering from a botched experiment, is having to reapply all the little tweaks to your system after a (re)install.  Particularly if you don't have a separate test system.

While setting up the deploy for a rails app, it hit me that I can just use Capistrano ( for remote scripting all of these little tweaks.

To use, you need to install ruby and rubygems on your workstation, then use gem to install Capistrano.  You do not have to install anything on your dcerouter.  Your workstation does need to be able to ssh to your dcerouter.

I'm going to present this example as from a kubuntu workstation.  As I normally use gentoo, there might be a few mistakes (I did run each command on my dad's kubuntu, but it's kind of in between 0710 & 0804 (let's just say the upgrade is not going smoothly)).

kubuntu workstation installation example:
Code: [Select]
$ sudo apt-get install ruby
$ sudo apt-get install rubygems
$ sudo gem install capistrano

The easiest way to run capistrano is out of a rails application.  This can be just a bare bones rails app.

Code: [Select]
$ sudo gem install rails
$ cd ~
$ rails lmce_manager
$ cd lmce_manager
$ /var/lib/gems/1.8/bin/capify . 
$ vi config/deploy.rb

Here's an example deploy.rb that I'm using for tweaking my dcerouter:
Code: [Select]
set :application, "lmce_manager"
set :repository,  "http://royw-gentoo/svn/linuxmce/trunk/lmce_manager"
set :user, "linuxmce"
set :runner, "linuxmce"

# If you aren't deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
# set :deploy_to, "/var/www/#{application}"

set :deploy_to, "/var/www/rails/#{application}"

# If you aren't using Subversion to manage your source code, specify
# your SCM below:
# set :scm, :subversion

set :scm_username, 'linuxmce'
set :scm_password, proc{Capistrano::CLI.password_prompt('SVN pass:')}

role :app, ""
role :web, ""
role :db,  "", :primary => true

namespace(:dcerouter) do
desc "setup core/hybrid"
task :setup do
# setup ssh certificates using ssh-installkeys
# (
# installed locally on workstation (not on lmce system)
`ssh-installkeys linuxmce@`

# copy hack_xorg_conf from workstation to dcerouter, then run it
# hack_xorg_conf edits /etc/X11/xorg.conf to add "DisplaySize 406 229" to "Monitor" section
put('/var/dcerouter/hack_xorg_conf'), '/home/linuxmce/hack_xorg_conf')
sudo "chmod 775 /home/linuxmce/hack_xorg_conf"
sudo "/home/linuxmce/hack_xorg_conf"

# increase firefox's font sizes to 16pt
sudo "mkdir /root/.mozilla/firefox/pluto.default/chrome"
sudo "chown root.root /root/.mozilla/firefox/pluto.default/chrome/userChrome.css"

# create rails directory that user linuxmce has write permission to
sudo "mkdir /var/www/rails"
sudo "chown linuxmce.linuxmce /var/www/rails"
sudo "chmod 775 /var/www/rails"

desc "install rails"
task :install_rails do
# we first install the ancient versions furnished via kubuntu,
sudo "apt-get install -y libyaml-ruby"
sudo "apt-get install -y libzlib-ruby"
sudo "apt-get install -y rubygems"
sudo "apt-get install -y ruby1.8-dev"
sudo "apt-get install -y build-essential"

# then we upgrade gem to the the lastest
sudo "gem update -y"
sudo "gem update -y --system"
sudo "rm /usr/bin/gem"
sudo "ln -s /usr/bin/gem1.8 /usr/bin/gem"

# now we install rails and our required modules
sudo "gem install rails"
sudo "gem install composite_primary_keys"
sudo "gem install railroad"
sudo "gem install will_paginate"
sudo "gem install --platform ruby fastthread"
sudo "gem install --platform ruby mongrel"

sudo "apt-get install -y libmysql-ruby1.8"
sudo "apt-get install -y libmysql-ruby"
sudo "apt-get install -y irb"

Now after an LMCE install I just run:
Code: [Select]
$ cd ~/lmce_manager
$ /var/lib/gems/1.8/bin/cap dcerouter:setup

Presto, my dcerouter is tweaked.

To install rails on my dcerouter:
Code: [Select]
$ cd ~/lmce_manager
$ /var/lib/gems/1.8/bin/cap dcerouter:install_rails

The only downside to Capistrano is the online documentation for version 2.x is sub-par.  The team seems to be working on it at  The documentation for 1.3 is available at  The book, "Deploying Rails Applications", has a chapter on Capistrano.  IMO, it's an ok intro, but it is not a full reference manual.

Have fun,