Re: [ts] Rebuild index with cron + rake

181 views
Skip to first unread message
Message has been deleted

Joe Noon

unread,
Jul 26, 2008, 10:51:30 PM7/26/08
to thinkin...@googlegroups.com
I just ran into this myself.  Its most likely that your cron environment isn't the same as your app's user's environment.  To fix that, get the PATH of your app's user and set it in the crontab file.  Also, set the shell to the same as what you get when you ssh in (mine is bash).  Here's an excerpt of mine to show what I mean:

PATH=/usr/local/bin:/usr/bin:/bin
SHELL=/bin/bash

# re-index sphinx every 20 minutes
12,32,52 * * * * cd /var/www/app/current && RAILS_ENV=production rake thinking_sphinx:index >> /dev/null 2>&1

Unrelated, but you can set MAILTO the same way.

Joe

On Sat, Jul 26, 2008 at 7:43 PM, PJAY79 <pjay...@hotmail.com> wrote:

Hi

I am trying to rebuild the index using cron and am having trouble with
this. I am using an Ubuntu Gutsy server, with Rails 2.0.2.

I have created a script that would be run under cron every day. This
is the file, thinkingsphinx.sh (chmod 700):

#!/bin/bash
# script to re-index thinking_sphinx
cd /home/demo/public_html/project/current && /usr/bin/rake
thinking_sphinx:index RAILS_ENV=production

My crontab -e looks like this:

10 2 * * * /home/demo/rakecron/thinkingsphinx.sh >> /home/demo/
rakecron/cronlogentries.txt 2>&1

When i look at the cronlogentries.txt file, i see this:

(in /home/demo/public_html/project/releases/20080725130346)
indexer --config /home/demo/public_html/project/releases/
20080725130346/config/production.sphinx.conf --all --rotate

It seems to have run ok, and no errors are seen. But when i look at
the the db/sphinx/production directory and look at the file sizes,
they remain unchanged (i don't know how else to check that the rebuild
has worked???).

If if run the script manually from the command line using:

./thinkingsphinx.sh

The index appears to have rebuilt (again, i just look at the files
sizes in the db/sphinx/production directory), so the script does work.

So the problem is that this does not appear to be working when it is
run through cron!

Any help appreciated...

PJ.





Message has been deleted

wbharding

unread,
Aug 23, 2008, 4:45:12 PM8/23/08
to Thinking Sphinx
Beautiful. This was my exact problem, and exact solution.

For those that are not Linux heads through and through (anyone besides
me? :)) you can find your user's shell and path with:

echo $PATH

and

echo $SHELL

On Jul 26, 11:23 pm, PJAY79 <pjay1...@hotmail.com> wrote:
> Thank you Joe, i added the PATH to the script and it seems to be
> working.
>
> PJ.
>
> On Jul 27, 12:51 pm, "Joe Noon" <joen...@gmail.com> wrote:
>
> > I just ran into this myself. Its most likely that yourcronenvironment
> > isn't the same as your app's user's environment. To fix that, get the PATH
> > of your app's user and set it in the crontab file. Also, set the shell to
> > the same as what you get when you ssh in (mine is bash). Here's an excerpt
> > of mine to show what I mean:
>
> > PATH=/usr/local/bin:/usr/bin:/bin
> > SHELL=/bin/bash
>
> > # re-index sphinx every 20 minutes
> > 12,32,52 * * * * cd /var/www/app/current && RAILS_ENV=production rake
> > thinking_sphinx:index >> /dev/null 2>&1
>
> > Unrelated, but you can set MAILTO the same way.
>
> > Joe
>
> > On Sat, Jul 26, 2008 at 7:43 PM, PJAY79 <pjay1...@hotmail.com> wrote:
>
> > > Hi
>
> > > I am trying to rebuild the index usingcronand am having trouble with
> > > this. I am using an Ubuntu Gutsy server, with Rails 2.0.2.
>
> > > I have created a script that would be run undercronevery day. This
Reply all
Reply to author
Forward
0 new messages