Capistrano and Environment Variables

From Apis Networks Wiki

Jump to: navigation, search

The Problem:

Capistrano's deployment tasks fail on built in commands that shouldn't fail. In my case, 'rake db:migrate' failed on line 9, complaining it couldn't require('rubygems') as it could find no such file. As rubygems is one of the core files of ruby, this turned into a large problem.

After banging my head against this for another day or two, I narrowed it down specifically to the RUBYLIB environment variable not being taken into account correctly. I did some more testing and found out that the SSH instance used by Capistrano doesn't take most environment variables into account at all.

Solution:

Update to Capistrano 2.1.0, which no longer requires a new PTY for each request.

As you can read on [1]:

---[snip]--- No default PTY. Prior to 2.1, Capistrano would request a pseudo-tty for each command that it executed. This had the side-effect of causing the profile scripts for the user to not be loaded. Well, no more! As of 2.1, Capistrano no longer requests a pty on each command, which means your .profile (or .bashrc, or whatever) will be properly loaded on each command! ---[snip]---

This solved the problem, as now all normal environment variables as described in /etc/bashrc (or ~/.bashrc, take your pick) show up in the script's environment.

Personal tools