views:

259

answers:

2

I'm trying to get CruiseControl.rb to run rcov during a build. It's currently failing with the following error:

sh: rcov: not found 

Since I can run rcov from the shell when I log in, I figure that this is a PATH problem. (Additionally, I can run both rake test:rcov and rake cruise from the shell without errors). I added a p 'echo $PATH' statement (with the correct backticks to execute the command; thanks Markdown) to my cruise.rake and discovered that the path was indeed incorrect:

"/usr/local/bin:/usr/bin:/bin\n"

The rcov executable is at /var/lib/gems/1.8/bin/rcov, so it's no wonder that CC.rb can't find it.

However, I can't figure out how to set the path properly. I have this set at the bottom of my .profile:

PATH="$PATH:/var/lib/gems/1.8/bin/"

This is what makes it work interactively, but it's not being picked up by CC.

I'm running CruiseControl.rb under Passenger Phusion (and thus under apache). I've checked as many files as I can think of, but nothing looks like a PATH to me.

Where can I set the path and/or determine where the path is being set?

+1  A: 

First of all, your .profile is wrong. You need to export the environment variable before it's visible to other processes. Like this:

export PATH=....

or

PATH=...
export PATH

Non-exported environment variable values can only be accessed from within the same shell process.

But that's not your problem since you're running Phusion Passenger. .profile is only read by the shell, and since Apache is not started from the shell, but from the system init process, whatever you put in .profile is ignored. For Phusion Passenger you have to set your PATH with mod_env and the SetEnv directive, like this:

<VirtualHost *:80>
    ServerName something.test
    DocumentRoot /somewhere/to/cruisecontrol/public
    SetEnv PATH /usr/bin:/usr/local/bin:/bin:/var/lib/gems/1.8/bin    # <---- add this
</VirtualHost>
Hongli
By all rights this looks like it should work... but for some reason, it doesn't.
Craig Walker
Clarification: the path is correctly being set for CC/Passenger. However, this path is *not* being used when invoking the builder.
Craig Walker
A: 

I finally got everything working.

Firstly, @Hongli's advice about setting the PATH within Apache was correct; SetEnv was able to set the PATH for the Passenger-based site.

After digging around through the CruiseControl.rb code I discovered the secondary problem (to which I alluded in my comments to Hongli's answer). During startup, CC.rb forks a builder process for each project. Each process gets the PATH of its parent at the time it was created. My problem was that I was restarting Apache, but this wasn't restarting the builder processes for whatever reason. The builders thus didn't get my PATH updates, and so appeared to not get the PATH from Apache. That led me to believe that their PATHs were set somewhere else -- but this is not the case.

Rebooting the system did the trick; the new builders got the new PATH from Apache and now everything works as expected. There's probably some other way to restart the builders, but I haven't investigated that.

Craig Walker