如何在 Rails 应用程序加载时自动启动 sphinx 守护进程?

发布于 2024-07-16 16:58:17 字数 112 浏览 6 评论 0原文

我知道手动启动 sphinx 守护进程的命令。 我使用 rake 任务:“rakethought_sphinx:start” 是否可以在我的 Rails 应用程序加载时启动它,这样我就不必每次都手动输入命令?

I am aware of the command to start the sphinx daemon manually. I use a rake task: "rake thinking_sphinx:start" Is it possible to have it start whenever my rails application loads so I don't have to manually type in the command every time?

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

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

发布评论

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

评论(7

秉烛思 2024-07-23 16:58:17

如果您通过 capistrano 进行部署(您应该这样做),只需将其添加为 after_deploy:

desc“在每次成功部署后运行此”

  task :after_deploy, :roles => :app do
        run "#{current_path}/rake thinking_sphinx:start"
  end

If you are deploying via capistrano (and you should be), simply add it as an after_deploy:

desc "Run this after every successful deployment"

  task :after_deploy, :roles => :app do
        run "#{current_path}/rake thinking_sphinx:start"
  end
独自唱情﹋歌 2024-07-23 16:58:17

您应该能够测试它是否正在运行并从 Rails 内启动它(使用 back -ticks%x{...} 表示

法(正如您在评论中所说),这是一个 rake 任务,您可能希望这样做,而不是使用 back 。 - 刻度:

Rake::Task['thinking_sphinx:start'].invoke

You should be able to test if it's running and launch it from within rails (using back-ticks or the %x{...} notation.

Given that (as you said in the comments) it's a rake task you may want to do it like so instead of with back-ticks:

Rake::Task['thinking_sphinx:start'].invoke
好久不见√ 2024-07-23 16:58:17

将启动它的命令放在 config/initializers/custom.rb 中

Put the command to launch it in your config/initializers/custom.rb

迷乱花海 2024-07-23 16:58:17

我必须在我的应用程序中做同样的事情,但是是在 Windows 上。 如果您陷入同样的​​困境,您会发现如果您执行以下操作,您的生活会容易得多:

if app_not_already_running
  IO.popen("start app") do |fd|
  end
end

我正在查看旧代码,但我不记得是否执行了 |fd| 确实有必要。 试一试。

“开始”之所以重要,是为了让窗口成为​​被诅咒的东西的背景。 啊啊!

I've had to do the same thing in my app, but with windows. In case you're in the same sticky mess, you'll find that your life will be much easier if you do something like:

if app_not_already_running
  IO.popen("start app") do |fd|
  end
end

I'm looking at old code and I don't remember if the do |fd| was really necessary. Give it a shot.

The reason the 'start' is important is to con windows into backgrounding the cursed thing. Yargh!

围归者 2024-07-23 16:58:17

如上所述,在 config/initializers.xml 中创建一个文件。 例如,我创建了一个名为initializers/start_thinking_sphinx.rb 的文件。 在我放入的文件中,

require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
require "#{RAILS_ROOT}/vendor/plugins/thinking-sphinx/tasks/thinking_sphinx_tasks"
Rake::Task['thinking_sphinx:start'].invoke

如果我随后使用 script/server 启动服务器,则此方法有效。 但是,如果我从乘客开始,则不起作用:(

As mentioned above, create a file in config/initializers. For example, I created a file called initializers/start_thinking_sphinx.rb. And in the file I put

require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
require "#{RAILS_ROOT}/vendor/plugins/thinking-sphinx/tasks/thinking_sphinx_tasks"
Rake::Task['thinking_sphinx:start'].invoke

This works if I then start the server with script/server. However does not work if I start with passenger :(

許願樹丅啲祈禱 2024-07-23 16:58:17

虽然这篇文章已经很老了,但我添加我的解决方案只是为了完整性......

我通过将以下代码放入 config/initializers/launch_sphinx.rb 来启动 sphinx 守护进程而不使用 rake。

Kernel.system("/usr/local/sphinx/bin/searchd --pidfile --config [full-path-to-your-app]/config/#{RAILS_ENV}.sphinx.config")

重要

根据您的需要更改 searchd 和 Rails 应用程序的路径。

Although this post is quite old, I add my solution just for the sake of completeness ...

I start the sphinx daemon without using rake, by putting the following code to config/initializers/launch_sphinx.rb.

Kernel.system("/usr/local/sphinx/bin/searchd --pidfile --config [full-path-to-your-app]/config/#{RAILS_ENV}.sphinx.config")

Important:

Change the paths to searchd and your rails application to your needs.

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