views:

229

answers:

2

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?

+2  A: 

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.

Roadmaster
What do you mean by restart.txt?My setup is simple too, but the problem is that sometimes i need to DEBUG using the production environment, which means i need to do it often. =)
ming yeow
under Passenger (an Apache module for rails deployment) you restart the application by creating a restart.txt file in the application's /tmp directory. Check documentation here:http://www.modrails.com/documentation/Users%20guide.html#_redeploying_restarting_the_rack_application
Roadmaster
+2  A: 

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)

Vlad Zloteanu
great tips: 1) tailing log files (i can tail mongrel logs as well) 2) rake tmp:cache:clear (THANKS!)PS: I use CODA to directly edit the staging server code. =)
ming yeow