meow
meow

Reputation: 28164

Debugging on the production server in Rails

how do you effectively debug on live server in rails, whether on a beta/production server?

I tried modifying the file directly on the server, and restarting the app, but the changes does not seem to take effect, or takes a long time to (caching?)

I also tried to do "script/server production" locally, but that is very slow

The other option is to code and deploy, but that is very inefficient.

Anyone has any insights as to how they do this efficiently?

Upvotes: 5

Views: 7832

Answers (2)

Vlad Zloteanu
Vlad Zloteanu

Reputation: 8512

I will answer your question, even if I don't agree with this way of hotpatching the server code :)

First, are you really sure that you have restarted the server? You ca check it by tailing the log files.

The view that is displayed by your changed code may be cached. The cached pages are located under tmp/cache folder. You can attempt to manually delete the file or you can rake tmp:cache:clear and they will all be deleted. Anyway, you can see exactly what's happening by tailing your log/production.log file (It will tell you something like 'rendering cached ...').

Another point: some data is also stored in session. You may also try to delete your session (or, delete all sessions; EG if you keep your sessions in DB, you can run rake db:sessions:clear)

Upvotes: 7

Roadmaster
Roadmaster

Reputation: 5357

To run the local server in production mode, try:

RAILS_ENV=production script/server

or

script/server --environment=production

The problem is that, unless you're also using the webrick/mongrel server in actual production, doing this will not exactly duplicate your actual production configuration (presumably using Apache or Passenger?). Also there might be subtle differences in environments that could be causing your problems.

How are you restarting your production environment when you change things there? this depends on how you deployed, and it might be as simple as dropping a restart.txt in your app's /tmp, or as difficult (not really) as restarting Apache or the Mongrel processes serving your app. It seems odd that your changes take a long time to appear when you do this.

When a problem arises in production mode, I just check the production.log which usually points me in the direction of a fix. I implement this in development, and then redeploy. That usually takes care of things. Using Capistrano it just takes 3 commands (a commit, a push and a deploy), unless your setup is significantly more complex than mine.

Upvotes: 2

Related Questions