如何在 Rails 应用程序加载时自动启动 sphinx 守护进程?
我知道手动启动 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以配置 daemon_controller 来执行此操作: http://blog.phusion.nl/2008/08/25/daemon_controller-a-library-for-robust-daemon-management/
You can configure daemon_controller to do this: http://blog.phusion.nl/2008/08/25/daemon_controller-a-library-for-robust-daemon-management/
如果您通过 capistrano 进行部署(您应该这样做),只需将其添加为 after_deploy:
desc“在每次成功部署后运行此”
If you are deploying via capistrano (and you should be), simply add it as an after_deploy:
desc "Run this after every successful deployment"
您应该能够测试它是否正在运行并从 Rails 内启动它(使用 back -ticks 或
%x{...}
表示法(正如您在评论中所说),这是一个 rake 任务,您可能希望这样做,而不是使用 back 。 - 刻度:
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:
将启动它的命令放在 config/initializers/custom.rb 中
Put the command to launch it in your config/initializers/custom.rb
我必须在我的应用程序中做同样的事情,但是是在 Windows 上。 如果您陷入同样的困境,您会发现如果您执行以下操作,您的生活会容易得多:
我正在查看旧代码,但我不记得是否执行了 |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:
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!
如上所述,在 config/initializers.xml 中创建一个文件。 例如,我创建了一个名为initializers/start_thinking_sphinx.rb 的文件。 在我放入的文件中,
如果我随后使用 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
This works if I then start the server with script/server. However does not work if I start with passenger :(
虽然这篇文章已经很老了,但我添加我的解决方案只是为了完整性......
我通过将以下代码放入 config/initializers/launch_sphinx.rb 来启动 sphinx 守护进程而不使用 rake。
重要:
根据您的需要更改 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.
Important:
Change the paths to searchd and your rails application to your needs.