Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 450
meow Avatar asked May 21 '10 14:05

meow


People also ask

How do I run rails server in debug mode?

Inside any Rails application you can invoke the debugger by calling the debugger method. In development mode, you can dynamically require \'ruby-debug\' instead of restarting the server, if it was started without --debugger. In order to use Rails debugging you'll need to be running either WEBrick or Mongrel.

What is rails logger debugging?

logger. debug , or in short logger. debug writes the parameter text to a log file. This log file is by default environment specific. If you are currently running rails in development environment then the log file in use is log/development.

How do I enable debugging in Ruby?

In order to start the Ruby debugger, load the debug library using the command-line option -r debug. The debugger stops before the first line of executable code and asks for the input of user commands.


2 Answers

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)

like image 66
Vlad Zloteanu Avatar answered Sep 20 '22 14:09

Vlad Zloteanu


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.

like image 34
Roadmaster Avatar answered Sep 21 '22 14:09

Roadmaster