任何想法为什么思考Sphinx Rake任务没有运行?

我发现当我尝试运行其Rake任务时,Thinking Sphinx有时会出错。 有时候任务工作正常,有时候会出现类似下面的错误。

我正在以普通用户身份运行任务,而不是root用户。 不使用sudo。

在下面的示例中,在Rake任务失败后,searchd仍在运行。

我也看到过类似的错误ts:rebuild

有没有人见过这个?

我正在使用Sphinx 0.9.9版本(r2117)

我正在使用Thinking Sphinx 1.4.4而不是最新版本,因为我使用的是Rails 2.3.11。


 $ rake ts:stop RAILS_ENV=production (in /var/www/blog_app/releases/20110425053509) rake aborted! execution expired (See full trace by running task with --trace) [ethan@apphost current]$ rake ts:stop RAILS_ENV=production --trace (in /var/www/blog_app/releases/20110425053509) ** Invoke ts:stop (first_time) ** Invoke thinking_sphinx:stop (first_time) ** Invoke thinking_sphinx:app_env (first_time) ** Execute thinking_sphinx:app_env ** Invoke environment (first_time) ** Execute environment ** Execute thinking_sphinx:stop rake aborted! execution expired /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/1.8/timeout.rb:60 /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/thinking-sphinx-1.4.4/lib/thinking_sphinx/tasks.rb:58 /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/1.8/monitor.rb:242:in `synchronize' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:607:in `invoke_prerequisites' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `each' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:596:in `invoke_with_call_chain' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/1.8/monitor.rb:242:in `synchronize' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run' /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31 /opt/ruby/bin/rake:19:in `load' /opt/ruby/bin/rake:19 

我相信当您已经运行搜索守护程序时会导致此错误。

尝试

 ps | grep searchd 

如果这给你这样的东西……

 73470 ttys002 0:00.03 searchd --pidfile --config /Users/dwickwire/Projects/production/config/development.sphinx.conf 81907 ttys002 0:00.00 grep searchd 

然后杀死searchd

 sudo kill -9 process_id 

在我的情况下,process_id将是73470

然后尝试rake ts:再次重建。

我试过命令’ps | grep searchd’获取进程ID,但我没有得到它。 然后我尝试命令’pgrep searchd’,它给了我进程ID。 我杀了那个进程并运行命令’rake ts:rebuild’。 有效。

我在这里写了关于整个体验的博客(免责声明:我是作者)。

在thinking_sphinx 1.4.4中, rake ts:stop5秒超时 rake ts:stop

如果rake ts:stop接近或超过5秒,ruby将抛出exception。

我在此期间使用的是thinking_sphinx 1.3.18。 (1.3.18没有超时)。

此外,我已经向github存储库提交了一个补丁,并且可以使用sphinx.yml配置变量stop_timeout配置超时。

注意: rake ts:rebuild == rake ts:stop; rake ts:index; rake ts:start rake ts:stop; rake ts:index; rake ts:start

我想在经过capistrano部署后你没有运行rake thinking_sphinx:configure
它会在config/production.sphinx.conf生成sphinx配置文件

尝试将pidfile添加到config/sphinx.yml

 production: ... pid_file: "/tmp/searchd.pid" 

它会确保找到searchd的pid来杀死

并将以下代码添加到config/deploy.rb

 namespace :my_tasks do task :generate_sphinx_config, :roles => [:web] do run "cd #{latest_release} && RAILS_ENV=#{rails_env} bundle exec rake thinking_sphinx:configure" end end .... after :deploy, "my_tasks:generate_sphinx_config" 

在每个版本文件夹中生成sphinx配置文件

问题

如果您的searchd崩溃或手动杀死它会发生此问题。 在Windows上,它不会覆盖您的searchd..pid ,因此仍然会保存旧的PID并且ThinkingSphinx不会检查任务管理器中的实际运行进程。 因此所有这些命令( rake ts:restart, rake ts:rebuild, ... )将不起作用,rake将始终中止,并且你得到错误rake aborted, ... searchd already running

解决方案

删除您的path-to/your-app/log/searchd..pid

可能是developmentproduction ,具体取决于您当前的阶段。

希望这个答案能够帮助googler。