【问题标题】:Thinking Sphinx indexing succeeding on command line, but failing in Cron job认为 Sphinx 索引在命令行上成功,但在 Cron 作业中失败
【发布时间】:2011-03-23 12:01:32
【问题描述】:

我承认我已经在 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
这个错误有点常见,但它在命令行中运行良好,这听起来很有趣,我怀疑还有一些奇怪的东西。我还有 2 个其他关键任务 cron 作业,它们运行看起来相同且运行良好的 rake 任务,不确定这个有什么不同。任何帮助将不胜感激!

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

【问题讨论】:

  • 为什么不thinking_sphinx:reindex?我相信这会更好地满足您的需求。 thinking_sphinx:index 执行了很多日常索引完全不需要的东西,比如重写 production.sphinx.conf。

标签: ruby-on-rails cron capistrano thinking-sphinx


【解决方案1】:

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

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

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

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

【讨论】:

  • 我将四处寻找如何检查 crontab 所有权,我只需键入 'crontab -l' 如上所示,作为我曾经登录过的唯一用户,这让我觉得它可能是别的东西.加上其他作业运行良好,我使用完全指定的二进制文件路径。你真的认为这是一个 PATH 问题吗?
  • 添加了 PATH 行并且它正在工作。你是对的,非常感谢!
  • 我建议不要这样做,而是在 sphinx.yml 中设置 bin 路径。例如,我的是bin_path: '/opt/sphinx-1.10-beta/bin'
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-31
    • 2015-11-17
    • 2017-08-15
    • 2015-05-27
    • 2022-01-18
    相关资源
    最近更新 更多