认为 Sphinx 索引在命令行上成功,但在 Cron 作业中失败

发布于 2024-09-12 05:14:20 字数 2235 浏览 3 评论 0原文

我承认我已经从官方文档(看起来过时了并且做了很多假设)和不同过时的各种博客文章中拼凑了一个在 Ubuntu 上与 Capistrano 一起工作的生产设置。无论如何,最后一个烦人的问题是,当我手动执行索引时(并且在部署时我很确定),索引可以工作,但在 Cron 中却不起作用。

这是我的 crontab:

$ crontab -l
# m h  dom mon dow   command
* * * * * cd /var/www/app/current && /usr/local/bin/rake RAILS_ENV=production thinking_sphinx:index >> /var/www/app/current/log/cron.log 2>&1

这是日志输出(实际上每次调用会出现 3 次):

Sphinx cannot be found on your system. You may need to configure the following
settings in your config/sphinx.yml file:
  * bin_path
  * searchd_binary_name
  * indexer_binary_name

For more information, read the documentation:
http://freelancing-god.github.com/ts/en/advanced_config.html

这是我手动运行相同命令时的情况(在记录日志时也有效):

$ cd /var/www/app/current && /usr/local/bin/rake RAILS_ENV=production thinking_sphinx:index
(in /var/www/app/releases/20100729042739)
Generating Configuration to /var/www/app/releases/20100729042739/config/production.sphinx.conf
Sphinx 0.9.9-release (r2117)
Copyright (c) 2001-2009, Andrew Aksyonoff

using config file '/var/www/app/releases/20100729042739/config/production.sphinx.conf'...
indexing index 'app_core'...
collected 5218 docs, 3.9 MB
collected 5218 attr values
sorted 0.0 Mvalues, 100.0% done
sorted 0.7 Mhits, 100.0% done
total 5218 docs, 3898744 bytes
total 0.616 sec, 6328760 bytes/sec, 8470.28 docs/sec
distributed index 'app' can not be directly indexed; skipping.
total 3 reads, 0.008 sec, 1110.2 kb/call avg, 2.6 msec/call avg
total 15 writes, 0.016 sec, 540.4 kb/call avg, 1.0 msec/call avg
rotating indices: succesfully sent SIGHUP to searchd (pid=20101).

也相关:

$ which rake        
/usr/local/bin/rake

$ which indexer
/usr/local/bin/indexer
The error is somewhat common, but it smells funny that it works fine from the command line, I suspect something else is weird. I have 2 other mission-critical cron jobs that run rake tasks that look identical and run fine, not sure what's different about this one. Any help would be greatly appreciated!

PS-当前 Capistrano 和 TS 版本是否有权威的部署配置?似乎每个人都推出了自己的,官方文档似乎和那里的博客文章一样独特。

I admit I've cobbled together a mostly working production setup on Ubuntu with Capistrano from the official docs (which seem dated and make a lot of assumptions) and various blog posts of varying outdatedness. Anyway, the last annoying hang up is that indexing works when I do it by hand (and on deploy I'm pretty sure), but doesn't work from Cron.

Here's my crontab:

$ crontab -l
# m h  dom mon dow   command
* * * * * cd /var/www/app/current && /usr/local/bin/rake RAILS_ENV=production thinking_sphinx:index >> /var/www/app/current/log/cron.log 2>&1

Here is the log output (this actually appears 3 times per call):

Sphinx cannot be found on your system. You may need to configure the following
settings in your config/sphinx.yml file:
  * bin_path
  * searchd_binary_name
  * indexer_binary_name

For more information, read the documentation:
http://freelancing-god.github.com/ts/en/advanced_config.html

This is when I run the same command by hand (also works when logging):

$ cd /var/www/app/current && /usr/local/bin/rake RAILS_ENV=production thinking_sphinx:index
(in /var/www/app/releases/20100729042739)
Generating Configuration to /var/www/app/releases/20100729042739/config/production.sphinx.conf
Sphinx 0.9.9-release (r2117)
Copyright (c) 2001-2009, Andrew Aksyonoff

using config file '/var/www/app/releases/20100729042739/config/production.sphinx.conf'...
indexing index 'app_core'...
collected 5218 docs, 3.9 MB
collected 5218 attr values
sorted 0.0 Mvalues, 100.0% done
sorted 0.7 Mhits, 100.0% done
total 5218 docs, 3898744 bytes
total 0.616 sec, 6328760 bytes/sec, 8470.28 docs/sec
distributed index 'app' can not be directly indexed; skipping.
total 3 reads, 0.008 sec, 1110.2 kb/call avg, 2.6 msec/call avg
total 15 writes, 0.016 sec, 540.4 kb/call avg, 1.0 msec/call avg
rotating indices: succesfully sent SIGHUP to searchd (pid=20101).

Also relevant:

$ which rake        
/usr/local/bin/rake

$ which indexer
/usr/local/bin/indexer


The error is somewhat common, but it smells funny that it works fine from the command line, I suspect something else is weird. I have 2 other mission-critical cron jobs that run rake tasks that look identical and run fine, not sure what's different about this one. Any help would be greatly appreciated!

PS-is there an authoritative deploy config for this with current Capistrano and TS versions? It seems everyone rolls their own, and the official docs seem to be as idiosyncratic as the blog posts out there.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

慕烟庭风 2024-09-19 05:14:20

crontab 是否与您手动运行时登录的用户属于同一用户?

由于这似乎是一个明显的 PATH 问题,并且 cron 使用受限的 PATH 运行(即不是 .profile 中的内容),因此请尝试将其添加到 crontab 文件的顶部。

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin

或者,如果您不想修改 cron 的 PATH,您可以将所需的文件符号链接到 /usr/sbin 中,默认情况下这可能位于 PATH 中。

Is the crontab owned by the same user as the one you are logged in as when you run things manually?

Since it seems like a clear PATH issue, and cron runs with a restricted PATH (i.e. not what's in your .profile), try adding this to the top of your crontab file.

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin

Or if you don't want to modify cron's PATH, you could symlink the files you need into /usr/sbin, which is likely in the PATH by default.

阳光下慵懒的猫 2024-09-19 05:14:20

我可以确认我遇到了类似的错误,例如@kbighorse,其中命令在命令行上手动运行良好,但没有从 cron 作业运行。我没有收到任何错误,但日志文件只会输出运行 sphinx 命令的目录。一旦我将以下路径变量从 @jdl 添加到 crontab 文件的顶部,cron 作业就会正常运行:

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin

I can confirm I had a similar error like @kbighorse where the commands ran fine manually on the command line, but did not run from the cron job. I did not receive any errors, but the log file would only output the directory the sphinx command was being run from. Once I added the following path variable from @jdl to the top of the crontab file the cron job would run properly:

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文