Thinking Sphinx delta indexing fails in production - ruby-on-rails

Here's what I've determined:
Delta indexing works fine in development
Delta indexing does not work when I push to the production server, and no action is logged in searchd.log
I'm running Phusion Passenger, and, as recommended in the basic troubleshooting guide, have confirmed that:
www-data has permission to run indexing rake tasks (ran them from command line manually)
the path to indexer and searchd are correct (/usr/local/bin)
there are no errors in production.log
What on earth could I possibly be missing? I'm running Ruby Enterprise 1.8.6, Rails 2.3.4, Sphinx 0.9.8.1, and Thinking Sphinx 1.2.11.
Thanks!

Last night as I slept it hit me. Unsurprisingly, it was a stupid issue involving bad configuration, though I am rather surprised that it produced the results it did. I guess I don't know much about Thinking Sphinx internals.
Recently I migrated servers. sphinx.yml looked like this:
production:
bin_path: '/usr/local/bin'
host: mysql.mysite.com
On the new server, MySQL was just a local service, but I had forgotten to remove that line. Interestingly, manual rake reindexing still worked just fine. I'm intrigued that Thinking Sphinx didn't throw an error when trying to reload the deltas, since mysql.mysite.com no longer exists, even though that was clearly the source of the issue.
Thanks for all your help, and sorry to have brought up such a silly problem.

Are there any clues in Apache/Nginx's error log?

Here's the next troubleshooting step I would take. Open up the file for the delta indexing strategy you are using (presumably lib/thinking_sphinx/deltas/default_delta.rb). Find the line where it actually generates the indexing command. In mine (v1.1.6) it's line 20:
output = `#{config.bin_path}indexer --config #{config.config_file} #{rotate} #{delta_index_name model}`
Change that so you can log the command itself, and maybe log the output as well:
command = `#{config.bin_path}indexer --config #{config.config_file} #{rotate} #{delta_index_name model}`
RAILS_DEFAULT_LOGGER.info(command)
output = `#{command}`
RAILS_DEFAULT_LOGGER.info(output)
Deploy that to production and tail the log while modifying a delta-indexed model. Hopefully that will actually show you the problem. Of course maybe the problem is elsewhere in the code and you won't even get to this point, but this is where I would start.

I was having this problem and found the "bin_path" solution mentioned above. When it didn't seem to work, it took me a while to realize that I'd pasted in the example code for "production" when I was testing on "stagiing" environment. Problem solved!
This was after making sure that the rake tasks that config, index, and start sphinx are all running as the same user as your passenger instance. If you log into the server as root to run these tasks, they will work in the console but not via passenger.

I had the same problem. Works on the command line, not inthe app.
Turns out that we still had a slave database that we were using for the indexing, but the slave wasn't getting updated.

As above, same issues were faced our side on two machine. The first one we had an issue with mysql which showed in apache2 log. Only seemed to affect local OSX machine..
Second time when we deployed to Ubuntu server, we had same issue. Rails c production was fine, no errors, bla bla bla.
Ended up being a permissions problem. Couldn't figure this out as there were no problems starting, although I guess I was doing so as root.
Using capistrano and passenger, we did this:
Create a passenger user and added to www-data group
Changed user in deploy.rb to be passenger
Manually changed all the /current files to be owned by above
Logged in as passenger user.
Ran rake ts:rebuild RAILS_ENV="production"
Worked a treat for us...
Good luck

Related

Rails 4.0 receiving emails - no such file (runner)

Up until now I've been using script/runner to forward bouncebacks to eblast-bounceback#mydomain.com and eblast-bounceback#dev.mydomain.com. However it is no longer working in Rails 4.0. I also can't seem to find a good resource online to illustrate how to do it. I usually get directed to the 'whenever' gem - but that's for cron jobs, not for 'piping to programs'.
So this is essentially what I'm currently doing, but is failing:
|/home/user/rails/dev.www/script/rails runner 'EBlast.receive(STDIN.read)' -e development
How do I get this to work? I'm not on Rails 4.1, I'm on 4.0. FWIW I do not have bin/rails. The above command yields "no such file or directory".
There were actually a few things I needed to do.
The email eblast-bounce#dev.mydomain.com was considered 'unroutable'. At first I figured it was because there wasn't any MX records for the subdomain, so I added one. But then I still got the error. I had manually updated the aliases file in /etc/valiases to pipe to the program using a symlinked directory (because I was deploying with Capistrano, and the directory ends up changing after every deploy). Turns out symlinks don't work for some reason when it comes to exim routing (/home/me/rails_deployments/dev.www/current/bin/rails fails). Maybe I'm wrong about the symlinks thing but the problem went away when I used the solution below.
This problem however was solved when I eventually came to another problem (/usr/bin/env: ruby: No such file or directory). I'm using RVM to manage rubies/gems, and apparently the email forwarder didn't know what ruby was. This leads to the final solution:
(when in cPanel, "pipe to program" assumes the user home directory (/home/me/))
.rvm/wrappers/ruby-2.1.0#website/ruby /home/me/rails_deployments/dev.www/current/bin/rails runner 'EBlast.receive(STDIN.read)' -e development
Where ruby-2.1.0 is my current ruby version, and #website is the gemset used by the EBlast.receive code base.
EDIT: Spoke too soon, the command has its own set of problems...(gemfile not present). This is ludicrous.

Cloned a RoR server and now getting "we're sorry, but something went wrong error"

I have a working RoR app that's running on Ubuntu Server, served by Nginx and Unicorn. It's using a local postgres database. I also think it's running on Sinatra instead of rails, but I'm too new to RoR to be able to say for certain.
I am attempting to create a development copy of the app to do some testing with. I'm able to do so using the source code, bundle install, and then running webbrick on my desktop. However, my developer wants to duplicate the environment that the actual production copy is running in. I cloned the server hosting the application, but when I browse to the server I get the dreaded "We're sorry, but something went wrong" error.
Here's what I've checked so for. I looked at the log files in the app/logs directory, and those haven't been updated in the last 6 days, so I suspect nothing relevant will be in them. If I run "service nginx status", it appears to be started. The database is running, and I can access it through the psql interface. Again, I'm pretty much an RoR newb... I was hoping one of you kind folks might give me some advice. Where should I look next? I'm sure it's something simple that I'm just overlooking. Thanks in advance!
In your config > environments > production.rb file change the consider_all_requests_local variable to true.
config.consider_all_requests_local = true
FYI, unicorn was not starting along with NGINX. I was able to script unicorn to start on boot, and this fixed my problem.

Rails Connecting to database specified by database.yml

I recently restarted POW. On reloading the Rails app I'm working on, it hung.
Checking Rails' logs I get the following repeating every 5-20 seconds:
Connecting to database specified by database.yml
I can interact with the Postgres db without issue through the Rails console, so there is no problem there. I haven't changed anything in my database.yml for weeks, so I don't think the problem is there.
What might be the problem and how can I debug it?
Turns out it was caused by POW
I had set '$powder always_restart` which was causing some sort of loop.
I reset this using `$ powder no_restarts'
Change your production database temporary to your development settings.
Then run in your terminal:
rails console production
Most of the times it is not about your database, but probably a syntax error. Anyways you can debug it like this.

Capistrano Rails app SQLite3 Cannot open Database

I've managed to get a Rails app deployed with Capistrano to a server running NGinx & Passenger. On deploy I was getting the "We're sorry, something went wrong" message & was rather confused as the production log was blank. I then switched the rails_env to development in my NGinx Conf & now I'm getting:
SQLite3::CantOpenException
unable to open database file
Rails.root: /www/testcap/releases/20120407015032
I logged into the server, into the current folder within testcap (which I believe symlinks to the latest release) and ran rake db:create, however the db files exist. Having looked within the app's db folder I see both development.db & test.db.
If I run rails s -e production and then head to myurl.com:3000 the app works completely fine, which is weird, and it also works fine when I run rails s -e development too.
I'm at a complete loss as to what the issue might be here. I'm sure it must be a relatively obvious issue, potentially with capistrano? I'm still new to it so I could well have missed anything but googling so far has been fruitless.
The only thing I can think of is that I've nothing explicitly relating to databases in my config/deploy.rb ? However I've not been able to find any guides on the net to help out thus far.
Thanks in advance for your help :)
Jack.
Thanks to the comments from Adam P & Ben L above, I managed to make some head way on this. This Guide also solved my issue.
I followed the steps in that guide above and in my database.yml file I changed the path to the production db from:
`db/production.sqlite3`
To
`/www/testcap/shared/db/production.sqlite3`
(eg the absolute path)
I then added this to my config/deploy.rb:
role :db, "{my vps IP}", :primary => true
On my VPS I went into the nginx conf & removed the line rails_env development (Passenger then sets it to production by default).
And then ran cap deploy followed by cap deploy:migrate, which worked, and I get the app displayed when I visit the URL.
I hope this might help someone out in the future stuck on the same issue :)
Jack.

Mongrel not detecting changes in Rails classes?

I have a Rails app installed on a Slicehost server running Apache 2 and Ubuntu LTC 10.04. Things have worked beautifully up until now: I edit a file, do a quick mongrel_rails cluster::restart, and the changes are reflected in production. However, suddenly this process has broken down.
For example, I have a class called Master located in /lib/master.rb. I added a new method to this class that simply runs puts "it works!", then restarted the mongrel cluster. Looking at the production logs, the server throws an error and thinks this method doesn't exist. When I go to the console using ruby script/console production, however, I can use this new method perfectly. I even tried deleting the file containing entire Master class. Once again, the production thought it was still there, but the production console correctly recognized it was missing.
Any ideas? How can the production environment detect a class that doesn't even exist anymore?
Funny, I spend 2 hours debugging this, then post to StackOverflow and figure it out in 20 minutes.
The problem is that I needed to also restart my background jobs as well. They were running the old version of the classes stored in /lib. It's interesting that this problem has never snagged me before.

Resources