FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo User

 
 
LinkBack Thread Tools
 
Old 08-11-2010, 06:17 PM
Michael Orlitzky
 
Default Postgres gem not found by cron job

I feel like I should be able to solve this one, but it started after my
last world update so maybe someone else has had a similar problem.


We have a ruby script called 'mailshears' on our mail server that cleans
up orphaned users and domains every night. The main script,


/root/src/mailshears/bin/mailshears

includes a class,

require 'src/postfixadmin_db'

which in turn requires the postgres library from ruby-postgres:

require 'postgres'

I don't think there's anything fancy going on here. All of the required
packages are installed, and the script runs fine when I execute it
manually. For example, both of the following work:


cd /root/src/mailshears/bin/
./mailshears

cd /
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
export HOME=/
/root/src/mailshears/bin/mailshears

(That last one mimics my crontab.) The problem is, whenever the nightly
cron job runs, the 'postgres' library can't be found. I get mailed this
every night:


/root/src/mailshears/bin/../src/postfixadmin_db.rb:1:in `require': no
such file to load -- postgres (LoadError)
from /root/src/mailshears/bin/../src/postfixadmin_db.rb:1
from /etc/cron.daily/01mailshears:35:in `require'
from /etc/cron.daily/01mailshears:35

The path /etc/cron.daily/01mailshears is simply a symlink to
/root/src/mailshears/bin/mailshears, and of course, if I execute that
symlink manually, it runs fine.


What's different between my root environment and the one in which cron
runs (with respect to ruby and its gems)? Where should I start looking?
 
Old 08-11-2010, 07:16 PM
Bill Longman
 
Default Postgres gem not found by cron job

<snip>
> What's different between my root environment and the one in which cron
> runs (with respect to ruby and its gems)? Where should I start looking?

No direct answer, sorry, Michael.

You might want to use:

/bin/bash -l -x -c /root/src/mailshears/bin/mailshears

to at least help debug it.
 
Old 08-11-2010, 07:32 PM
Michael Orlitzky
 
Default Postgres gem not found by cron job

On 08/11/2010 03:16 PM, Bill Longman wrote:

<snip>

What's different between my root environment and the one in which cron
runs (with respect to ruby and its gems)? Where should I start looking?


No direct answer, sorry, Michael.

You might want to use:

/bin/bash -l -x -c /root/src/mailshears/bin/mailshears

to at least help debug it.



Thanks for the tip. The cron environment was missing
"RUBYOPT=-rauto_gem" -- adding it fixed the problem.


Dark magic, whatever it does.
 
Old 08-13-2010, 06:36 PM
Hans de Graaff
 
Default Postgres gem not found by cron job

On Wed, 11 Aug 2010 15:32:53 -0400, Michael Orlitzky wrote:

> Thanks for the tip. The cron environment was missing
> "RUBYOPT=-rauto_gem" -- adding it fixed the problem.
>
> Dark magic, whatever it does.

It ensures that installed gems are found automatically without
specifying this explicitly in your script. The other solution
is to "require 'rubygems'" first in your script.

Kind regards,

Hans
 

Thread Tools




All times are GMT. The time now is 03:26 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org