Reputation: 9184
I have a chain of nginx + passenger for my rails app.
Now after each server restart i need to write in terminal in project folder
rake ts:start
but how can i automatize it?
So that after each server restart thinking sphinx is automatically started without my command in terminal?
I use rails 3.2.8 and ubuntu 12.04.
I can not imagine what can i try ever, please help me.
How can i do this, give some advices?
Upvotes: 1
Views: 1317
Reputation: 709
If you are using the excellent whenever gem to manage your crontab, you can just put
every :reboot do
rake "ts:start"
end
in your schedule.rb
and it seems to work great. I just tested on an EC2 instance running Ubuntu 14.04.
Upvotes: 2
Reputation: 5635
I followed @pat's suggestion and wrote a script to start ThinkingSphinx whenever the server boots up. You can see it as a gist - https://gist.github.com/declan/4b7cc4fb4926df16f54c
We're using Capistrano for deployment to Ubuntu 14.04, and you may need to modify the path and user name to match your server setup. Otherwise, all you need to do is
/etc/init.d/thinking_sphinx
/etc/init.d/thinking_sphinx start
on the command line should start ThinkingSphinx for your app, and /etc/init.d/thinking_sphinx stop
should stop itupdate-rc.d thinking_sphinx defaults
There's a good post on debian-administration.org called making scripts run at boot time that has more details.
Upvotes: 1
Reputation: 117567
What I did to solve the same problem:
In config/application.rb
, add:
module Rails
def self.rake?
!!@rake
end
def self.rake=(value)
@rake = !!value
end
end
In Rakefile
, add this line:
Rails.rake = true
Finally, in config/initializers/start_thinking_sphinx.rb
put:
unless Rails.rake?
begin
# Prope ts connection
ThinkingSphinx.search "test", :populate => true
rescue Mysql2::Error => err
puts ">>> ThinkingSphinx is unavailable. Trying to start .."
MyApp::Application.load_tasks
Rake::Task['ts:start'].invoke
end
end
(Replace MyApp
above with your app's name)
Seems to work so far, but if I encounter any issues I'll post back here.
Obviously, the above doesn't take care of monitoring that the server stays up. You might want to do that separately. Or an alternative could be to manage the service with Upstart.
Upvotes: 3
Reputation: 16226
There's two options I can think of.
/etc/init
?).The catch with Monit and other such tools is that when you deliberately stop Sphinx (say, to update configuration structure and corresponding index changes), it might start it up again before it's appropriate. So I think you should start with the first of these two options - I just don't know a great deal about the finer points of that approach.
Upvotes: 1