[LRUG] Shebang

Andrew Stewart boss at airbladesoftware.com
Fri Jun 27 08:00:18 PDT 2008


On 27 Jun 2008, at 12:47, Matthew Rudy Jacobs wrote:

> if that doesnt work it may also be down to the way your script is  
> being run.
>
> eg. I belive that capistrano commands are issued seperately, rather  
> than through a sustained Bash session, so ~/.profile doesn't get  
> loaded.
>
> get a script runner to do "puts system("echo $PATH")"
> or something (when you've temporarily set the shebang to the full  
> path)
> then you'll know the PATH in the exact instance!
>
> 2008/6/27 Roland Swingler <roland.swingler at gmail.com>:
> Hi,
>
> Presumably Bj is a background job runner?
>
> It might be possible that the PATH variable isn't set for the user
> that is running, or at least doesn't include the directory with ruby
> in it.
>
> So it will work for you on the command line, because your user has
> ruby in its path. You could try "su your-bj-user" and then "echo
> $PATH" to check this.
>
> Cheers,
> Roland


Thanks for the suggestions.

I submitted various jobs via the console to test out your ideas.  For  
example:

 >> Bj.submit 'whoami'
=> #<Bj::Table::Job bj_job_id: 69, command: "whoami", state:  
"finished", priority: 0, tag: "", submitter: "bigserver", runner:  
"bigserver", pid: 8865, submitted_at: "2008-06-27 14:15:52",  
started_at: "2008-06-27 14:16:07", finished_at: "2008-06-27 14:16:08",  
env: nil, stdin: nil, stdout: "deploy\n", stderr: "", exit_status: 0>

This told me that the background job runner was running as the deploy  
user, which is what it should be doing.  However when I run the jobs  
myself as the deploy user, they work fine.

So next I checked the path:

 >> Bj.submit 'echo $PATH'
=> #<Bj::Table::Job bj_job_id: 68, command: "echo $PATH", state:  
"finished", priority: 0, tag: "", submitter: "bigserver", runner:  
"bigserver", pid: 8860, submitted_at: "2008-06-27 14:14:27",  
started_at: "2008-06-27 14:14:43", finished_at: "2008-06-27 14:14:43",  
env: nil, stdin: nil, stdout: "/usr/bin:/bin\n", stderr: "",  
exit_status: 0>

Weirdly, the runner's path (running as deploy) is /usr/bin:/bin,  
whereas the deploy user's path is:

usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/ 
X11:/usr/games

I have no idea why the runner's path differs from the deploy user's,  
given they are both running as deploy.

Anyway, now I know the problem, how to set the correct path?

First I tried passing a PATH environment variable to Bj:

 >> Bj.submit 'echo $PATH', :env => {'PATH' => '/usr/local/bin:$PATH'}
=> #<Bj::Table::Job bj_job_id: 74, command: "echo $PATH", state:  
"finished", priority: 0, tag: "", submitter: "bigserver", runner:  
"bigserver", pid: 9093, submitted_at: "2008-06-27 14:51:05",  
started_at: "2008-06-27 14:51:06", finished_at: "2008-06-27 14:51:08",  
env: "--- \nPATH: /usr/local/bin:$PATH\n", stdin: nil, stdout: "/usr/ 
bin:/bin\n", stderr: "", exit_status: 0>

So it seems that Bj doesn't use a PATH handed to it via its env hash.

Next I tried setting the PATH as part of the command I run:

 >> Bj.submit "PATH=/usr/local/bin:$PATH ./script/runner 'puts  
system(\"echo $PATH\")'"
=> #<Bj::Table::Job bj_job_id: 71, command: "PATH=/usr/local/bin: 
$PATH ./script/runner 'puts sys...", state: "finished", priority: 0,  
tag: "", submitter: "bigserver", runner: "bigserver", pid: 9004,  
submitted_at: "2008-06-27 14:37:27", started_at: "2008-06-27  
14:38:05", finished_at: "2008-06-27 14:38:08", env: nil, stdin: nil,  
stdout: "/usr/local/bin:/usr/bin:/bin\ntrue\n", stderr: "",  
exit_status: 0>

And this found ruby, executing successfully.  Finally ;-)

So I'm changing my Rails app's action to prepend a hard-coded PATH to  
the command it runs.  It's unsatisfactory, but does have the rather  
compelling advantage of working.

Cheers,
Andy

-------
AirBlade Software Ltd
http://airbladesoftware.com








More information about the Chat mailing list